Remove some more usage of run_in_executor (#8352)
* Remove usage of run_in_executor * Lintpull/8360/merge
parent
d655c0e358
commit
143044f8f1
|
@ -83,15 +83,13 @@ def test_trigger_sensor_value_changed(hass, mock_openzwave):
|
||||||
assert not device.is_on
|
assert not device.is_on
|
||||||
|
|
||||||
value.data = True
|
value.data = True
|
||||||
yield from hass.loop.run_in_executor(None, value_changed, value)
|
yield from hass.async_add_job(value_changed, value)
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
assert device.invalidate_after is None
|
assert device.invalidate_after is None
|
||||||
|
|
||||||
device.hass = hass
|
device.hass = hass
|
||||||
|
|
||||||
value.data = True
|
value.data = True
|
||||||
yield from hass.loop.run_in_executor(None, value_changed, value)
|
yield from hass.async_add_job(value_changed, value)
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
assert device.is_on
|
assert device.is_on
|
||||||
|
|
||||||
test_time = device.invalidate_after - datetime.timedelta(seconds=1)
|
test_time = device.invalidate_after - datetime.timedelta(seconds=1)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from homeassistant.setup import setup_component, async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -10,9 +10,7 @@ def test_fetching_url(aioclient_mock, hass, test_client):
|
||||||
"""Test that it fetches the given url."""
|
"""Test that it fetches the given url."""
|
||||||
aioclient_mock.get('http://example.com', text='hello world')
|
aioclient_mock.get('http://example.com', text='hello world')
|
||||||
|
|
||||||
def setup_platform():
|
yield from async_setup_component(hass, 'camera', {
|
||||||
"""Setup the platform."""
|
|
||||||
assert setup_component(hass, 'camera', {
|
|
||||||
'camera': {
|
'camera': {
|
||||||
'name': 'config_test',
|
'name': 'config_test',
|
||||||
'platform': 'generic',
|
'platform': 'generic',
|
||||||
|
@ -21,8 +19,6 @@ def test_fetching_url(aioclient_mock, hass, test_client):
|
||||||
'password': 'pass'
|
'password': 'pass'
|
||||||
}})
|
}})
|
||||||
|
|
||||||
yield from hass.loop.run_in_executor(None, setup_platform)
|
|
||||||
|
|
||||||
client = yield from test_client(hass.http.app)
|
client = yield from test_client(hass.http.app)
|
||||||
|
|
||||||
resp = yield from client.get('/api/camera_proxy/camera.config_test')
|
resp = yield from client.get('/api/camera_proxy/camera.config_test')
|
||||||
|
@ -44,9 +40,7 @@ def test_limit_refetch(aioclient_mock, hass, test_client):
|
||||||
aioclient_mock.get('http://example.com/15a', text='hello planet')
|
aioclient_mock.get('http://example.com/15a', text='hello planet')
|
||||||
aioclient_mock.get('http://example.com/20a', status=404)
|
aioclient_mock.get('http://example.com/20a', status=404)
|
||||||
|
|
||||||
def setup_platform():
|
yield from async_setup_component(hass, 'camera', {
|
||||||
"""Setup the platform."""
|
|
||||||
assert setup_component(hass, 'camera', {
|
|
||||||
'camera': {
|
'camera': {
|
||||||
'name': 'config_test',
|
'name': 'config_test',
|
||||||
'platform': 'generic',
|
'platform': 'generic',
|
||||||
|
@ -55,8 +49,6 @@ def test_limit_refetch(aioclient_mock, hass, test_client):
|
||||||
'limit_refetch_to_url_change': True,
|
'limit_refetch_to_url_change': True,
|
||||||
}})
|
}})
|
||||||
|
|
||||||
yield from hass.loop.run_in_executor(None, setup_platform)
|
|
||||||
|
|
||||||
client = yield from test_client(hass.http.app)
|
client = yield from test_client(hass.http.app)
|
||||||
|
|
||||||
resp = yield from client.get('/api/camera_proxy/camera.config_test')
|
resp = yield from client.get('/api/camera_proxy/camera.config_test')
|
||||||
|
|
|
@ -6,28 +6,21 @@ from unittest import mock
|
||||||
# https://bugs.python.org/issue23004
|
# https://bugs.python.org/issue23004
|
||||||
from mock_open import MockOpen
|
from mock_open import MockOpen
|
||||||
|
|
||||||
from homeassistant.setup import setup_component, async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import mock_http_component
|
|
||||||
import logging
|
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_loading_file(hass, test_client):
|
def test_loading_file(hass, test_client):
|
||||||
"""Test that it loads image from disk."""
|
"""Test that it loads image from disk."""
|
||||||
@mock.patch('os.path.isfile', mock.Mock(return_value=True))
|
with mock.patch('os.path.isfile', mock.Mock(return_value=True)), \
|
||||||
@mock.patch('os.access', mock.Mock(return_value=True))
|
mock.patch('os.access', mock.Mock(return_value=True)):
|
||||||
def setup_platform():
|
yield from async_setup_component(hass, 'camera', {
|
||||||
"""Setup platform inside callback."""
|
|
||||||
assert setup_component(hass, 'camera', {
|
|
||||||
'camera': {
|
'camera': {
|
||||||
'name': 'config_test',
|
'name': 'config_test',
|
||||||
'platform': 'local_file',
|
'platform': 'local_file',
|
||||||
'file_path': 'mock.file',
|
'file_path': 'mock.file',
|
||||||
}})
|
}})
|
||||||
|
|
||||||
yield from hass.loop.run_in_executor(None, setup_platform)
|
|
||||||
|
|
||||||
client = yield from test_client(hass.http.app)
|
client = yield from test_client(hass.http.app)
|
||||||
|
|
||||||
m_open = MockOpen(read_data=b'hello')
|
m_open = MockOpen(read_data=b'hello')
|
||||||
|
@ -45,27 +38,19 @@ def test_loading_file(hass, test_client):
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_file_not_readable(hass, caplog):
|
def test_file_not_readable(hass, caplog):
|
||||||
"""Test a warning is shown setup when file is not readable."""
|
"""Test a warning is shown setup when file is not readable."""
|
||||||
mock_http_component(hass)
|
with mock.patch('os.path.isfile', mock.Mock(return_value=True)), \
|
||||||
|
mock.patch('os.access', mock.Mock(return_value=False)):
|
||||||
@mock.patch('os.path.isfile', mock.Mock(return_value=True))
|
yield from async_setup_component(hass, 'camera', {
|
||||||
@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', {
|
|
||||||
'camera': {
|
'camera': {
|
||||||
'name': 'config_test',
|
'name': 'config_test',
|
||||||
'platform': 'local_file',
|
'platform': 'local_file',
|
||||||
'file_path': 'mock.file',
|
'file_path': 'mock.file',
|
||||||
}})
|
}})
|
||||||
|
|
||||||
assert 'Could not read' in caplog.text
|
assert 'Could not read' in caplog.text
|
||||||
assert 'config_test' in caplog.text
|
assert 'config_test' in caplog.text
|
||||||
assert 'mock.file' in caplog.text
|
assert 'mock.file' in caplog.text
|
||||||
|
|
||||||
yield from hass.loop.run_in_executor(None, run_test)
|
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_camera_content_type(hass, test_client):
|
def test_camera_content_type(hass, test_client):
|
||||||
|
|
Loading…
Reference in New Issue