Deprecated stuff (#16019)
* Use async with for locks * Fix regex in template test * Close session correctly * Use correct current_task method * push camera cleanup * Lint * Revert current_task * Update websocket_api.py * Mock executor_job betteR * Fix async_create_task mock
This commit is contained in:
1 parent
975befd136
commit
d1e1b9b38a
7 files changed
+50
-22
No files matched your search
+17
-1
@@ -123,14 +123,30 @@ def async_test_home_assistant(loop):
|
||||
INSTANCES.append(hass)
|
||||
|
||||
orig_async_add_job = hass.async_add_job
|
||||
orig_async_add_executor_job = hass.async_add_executor_job
|
||||
orig_async_create_task = hass.async_create_task
|
||||
|
||||
def async_add_job(target, *args):
|
||||
"""Add a magic mock."""
|
||||
"""Add job."""
|
||||
if isinstance(target, Mock):
|
||||
return mock_coro(target(*args))
|
||||
return orig_async_add_job(target, *args)
|
||||
|
||||
def async_add_executor_job(target, *args):
|
||||
"""Add executor job."""
|
||||
if isinstance(target, Mock):
|
||||
return mock_coro(target(*args))
|
||||
return orig_async_add_executor_job(target, *args)
|
||||
|
||||
def async_create_task(coroutine):
|
||||
"""Create task."""
|
||||
if isinstance(coroutine, Mock):
|
||||
return mock_coro()
|
||||
return orig_async_create_task(coroutine)
|
||||
|
||||
hass.async_add_job = async_add_job
|
||||
hass.async_add_executor_job = async_add_executor_job
|
||||
hass.async_create_task = async_create_task
|
||||
|
||||
hass.config.location_name = 'test home'
|
||||
hass.config.config_dir = get_test_config_dir()
|
||||
|
||||
@@ -30,7 +30,7 @@ async def test_bad_posting(aioclient_mock, hass, aiohttp_client):
|
||||
assert resp.status == 400
|
||||
|
||||
|
||||
async def test_posting_url(aioclient_mock, hass, aiohttp_client):
|
||||
async def test_posting_url(hass, aiohttp_client):
|
||||
"""Test that posting to api endpoint works."""
|
||||
await async_setup_component(hass, 'camera', {
|
||||
'camera': {
|
||||
@@ -38,7 +38,7 @@ async def test_posting_url(aioclient_mock, hass, aiohttp_client):
|
||||
'name': 'config_test',
|
||||
}})
|
||||
|
||||
client = await async_setup_auth(hass, aiohttp_client)
|
||||
client = await aiohttp_client(hass.http.app)
|
||||
files = {'image': io.BytesIO(b'fake')}
|
||||
|
||||
# initial state
|
||||
|
||||
@@ -511,8 +511,8 @@ class TestHelpersTemplate(unittest.TestCase):
|
||||
|
||||
def test_regex_match(self):
|
||||
"""Test regex_match method."""
|
||||
tpl = template.Template("""
|
||||
{{ '123-456-7890' | regex_match('(\d{3})-(\d{3})-(\d{4})') }}
|
||||
tpl = template.Template(r"""
|
||||
{{ '123-456-7890' | regex_match('(\\d{3})-(\\d{3})-(\\d{4})') }}
|
||||
""", self.hass)
|
||||
self.assertEqual('True', tpl.render())
|
||||
|
||||
@@ -528,8 +528,8 @@ class TestHelpersTemplate(unittest.TestCase):
|
||||
|
||||
def test_regex_search(self):
|
||||
"""Test regex_search method."""
|
||||
tpl = template.Template("""
|
||||
{{ '123-456-7890' | regex_search('(\d{3})-(\d{3})-(\d{4})') }}
|
||||
tpl = template.Template(r"""
|
||||
{{ '123-456-7890' | regex_search('(\\d{3})-(\\d{3})-(\\d{4})') }}
|
||||
""", self.hass)
|
||||
self.assertEqual('True', tpl.render())
|
||||
|
||||
@@ -545,8 +545,8 @@ class TestHelpersTemplate(unittest.TestCase):
|
||||
|
||||
def test_regex_replace(self):
|
||||
"""Test regex_replace method."""
|
||||
tpl = template.Template("""
|
||||
{{ 'Hello World' | regex_replace('(Hello\s)',) }}
|
||||
tpl = template.Template(r"""
|
||||
{{ 'Hello World' | regex_replace('(Hello\\s)',) }}
|
||||
""", self.hass)
|
||||
self.assertEqual('World', tpl.render())
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ from yarl import URL
|
||||
|
||||
from aiohttp.client_exceptions import ClientResponseError
|
||||
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_CLOSE
|
||||
|
||||
retype = type(re.compile(''))
|
||||
|
||||
|
||||
@@ -216,7 +218,18 @@ def mock_aiohttp_client():
|
||||
"""Context manager to mock aiohttp client."""
|
||||
mocker = AiohttpClientMocker()
|
||||
|
||||
def create_session(hass, *args):
|
||||
session = mocker.create_session(hass.loop)
|
||||
|
||||
async def close_session(event):
|
||||
"""Close session."""
|
||||
await session.close()
|
||||
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_CLOSE, close_session)
|
||||
|
||||
return session
|
||||
|
||||
with mock.patch(
|
||||
'homeassistant.helpers.aiohttp_client.async_create_clientsession',
|
||||
side_effect=lambda hass, *args: mocker.create_session(hass.loop)):
|
||||
side_effect=create_session):
|
||||
yield mocker
|
||||
Reference in new issue
Block a user