mirror of
https://github.com/home-assistant/core.git
synced 2025-12-27 22:34:47 +00:00
Remove some more usage of run_in_executor (#8352)
* Remove usage of run_in_executor * Lint
This commit is contained in:
committed by
Pascal Vizeli
parent
d655c0e358
commit
143044f8f1
@@ -6,28 +6,21 @@ from unittest import mock
|
||||
# https://bugs.python.org/issue23004
|
||||
from mock_open import MockOpen
|
||||
|
||||
from homeassistant.setup import setup_component, async_setup_component
|
||||
|
||||
from tests.common import mock_http_component
|
||||
import logging
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_loading_file(hass, test_client):
|
||||
"""Test that it loads image from disk."""
|
||||
@mock.patch('os.path.isfile', mock.Mock(return_value=True))
|
||||
@mock.patch('os.access', mock.Mock(return_value=True))
|
||||
def setup_platform():
|
||||
"""Setup platform inside callback."""
|
||||
assert setup_component(hass, 'camera', {
|
||||
with mock.patch('os.path.isfile', mock.Mock(return_value=True)), \
|
||||
mock.patch('os.access', mock.Mock(return_value=True)):
|
||||
yield from async_setup_component(hass, 'camera', {
|
||||
'camera': {
|
||||
'name': 'config_test',
|
||||
'platform': 'local_file',
|
||||
'file_path': 'mock.file',
|
||||
}})
|
||||
|
||||
yield from hass.loop.run_in_executor(None, setup_platform)
|
||||
|
||||
client = yield from test_client(hass.http.app)
|
||||
|
||||
m_open = MockOpen(read_data=b'hello')
|
||||
@@ -45,26 +38,18 @@ def test_loading_file(hass, test_client):
|
||||
@asyncio.coroutine
|
||||
def test_file_not_readable(hass, caplog):
|
||||
"""Test a warning is shown setup when file is not readable."""
|
||||
mock_http_component(hass)
|
||||
|
||||
@mock.patch('os.path.isfile', mock.Mock(return_value=True))
|
||||
@mock.patch('os.access', mock.Mock(return_value=False))
|
||||
def run_test():
|
||||
|
||||
caplog.set_level(
|
||||
logging.WARNING, logger='requests.packages.urllib3.connectionpool')
|
||||
|
||||
assert setup_component(hass, 'camera', {
|
||||
with mock.patch('os.path.isfile', mock.Mock(return_value=True)), \
|
||||
mock.patch('os.access', mock.Mock(return_value=False)):
|
||||
yield from async_setup_component(hass, 'camera', {
|
||||
'camera': {
|
||||
'name': 'config_test',
|
||||
'platform': 'local_file',
|
||||
'file_path': 'mock.file',
|
||||
}})
|
||||
assert 'Could not read' in caplog.text
|
||||
assert 'config_test' in caplog.text
|
||||
assert 'mock.file' in caplog.text
|
||||
|
||||
yield from hass.loop.run_in_executor(None, run_test)
|
||||
assert 'Could not read' in caplog.text
|
||||
assert 'config_test' in caplog.text
|
||||
assert 'mock.file' in caplog.text
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
||||
Reference in New Issue
Block a user