Minor improvements to automation test suite (#24424)

* Minor improvements to automation test suite

* Removes unused asyncio imports

* Removes some vars that are not needed
This commit is contained in:
Franck Nijhof 2019-06-09 02:10:23 +02:00 committed by Andrew Sayre
parent 848a2a95a8
commit d648eb1e4f
2 changed files with 31 additions and 55 deletions

View file

@ -1,5 +1,4 @@
"""The tests for the Event automation."""
import asyncio
from unittest.mock import patch, Mock
from homeassistant.core import CoreState
@ -9,8 +8,7 @@ import homeassistant.components.automation as automation
from tests.common import async_mock_service, mock_coro
@asyncio.coroutine
def test_if_fires_on_hass_start(hass):
async def test_if_fires_on_hass_start(hass):
"""Test the firing when HASS starts."""
calls = async_mock_service(hass, 'test', 'automation')
hass.state = CoreState.not_running
@ -27,31 +25,29 @@ def test_if_fires_on_hass_start(hass):
}
}
res = yield from async_setup_component(hass, automation.DOMAIN, config)
assert res
assert await async_setup_component(hass, automation.DOMAIN, config)
assert automation.is_on(hass, 'automation.hello')
assert len(calls) == 0
yield from hass.async_start()
await hass.async_start()
assert automation.is_on(hass, 'automation.hello')
assert len(calls) == 1
with patch('homeassistant.config.async_hass_config_yaml',
Mock(return_value=mock_coro(config))):
yield from hass.services.async_call(
await hass.services.async_call(
automation.DOMAIN, automation.SERVICE_RELOAD, blocking=True)
assert automation.is_on(hass, 'automation.hello')
assert len(calls) == 1
@asyncio.coroutine
def test_if_fires_on_hass_shutdown(hass):
async def test_if_fires_on_hass_shutdown(hass):
"""Test the firing when HASS starts."""
calls = async_mock_service(hass, 'test', 'automation')
hass.state = CoreState.not_running
res = yield from async_setup_component(hass, automation.DOMAIN, {
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'alias': 'hello',
'trigger': {
@ -63,22 +59,13 @@ def test_if_fires_on_hass_shutdown(hass):
}
}
})
assert res
assert automation.is_on(hass, 'automation.hello')
assert len(calls) == 0
yield from hass.async_start()
await hass.async_start()
assert automation.is_on(hass, 'automation.hello')
assert len(calls) == 0
with patch.object(hass.loop, 'stop'):
yield from hass.async_stop()
await hass.async_stop()
assert len(calls) == 1
# with patch('homeassistant.config.async_hass_config_yaml',
# Mock(return_value=mock_coro(config))):
# yield from hass.services.async_call(
# automation.DOMAIN, automation.SERVICE_RELOAD, blocking=True)
# assert automation.is_on(hass, 'automation.hello')
# assert len(calls) == 1