From b43b50b6d23e59541088e5dace5ac95481aa385d Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 2 Jan 2020 00:22:08 +0100 Subject: [PATCH] Migrate ffmpeg tests from coroutine to async/await (#30375) --- tests/components/ffmpeg/test_init.py | 57 ++++++++++++---------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/tests/components/ffmpeg/test_init.py b/tests/components/ffmpeg/test_init.py index 1b21f07cd36..3c6a2fbb92d 100644 --- a/tests/components/ffmpeg/test_init.py +++ b/tests/components/ffmpeg/test_init.py @@ -1,5 +1,4 @@ """The tests for Home Assistant ffmpeg.""" -import asyncio from unittest.mock import MagicMock import homeassistant.components.ffmpeg as ffmpeg @@ -61,14 +60,12 @@ class MockFFmpegDev(ffmpeg.FFmpegBase): self.called_restart = False self.called_entities = None - @asyncio.coroutine - def _async_start_ffmpeg(self, entity_ids): + async def _async_start_ffmpeg(self, entity_ids): """Mock start.""" self.called_start = True self.called_entities = entity_ids - @asyncio.coroutine - def _async_stop_ffmpeg(self, entity_ids): + async def _async_stop_ffmpeg(self, entity_ids): """Mock stop.""" self.called_stop = True self.called_entities = entity_ids @@ -102,91 +99,85 @@ class TestFFmpegSetup: assert self.hass.services.has_service(ffmpeg.DOMAIN, "restart") -@asyncio.coroutine -def test_setup_component_test_register(hass): +async def test_setup_component_test_register(hass): """Set up ffmpeg component test register.""" with assert_setup_component(1): - yield from async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) + await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) hass.bus.async_listen_once = MagicMock() ffmpeg_dev = MockFFmpegDev(hass) - yield from ffmpeg_dev.async_added_to_hass() + await ffmpeg_dev.async_added_to_hass() assert hass.bus.async_listen_once.called assert hass.bus.async_listen_once.call_count == 2 -@asyncio.coroutine -def test_setup_component_test_register_no_startup(hass): +async def test_setup_component_test_register_no_startup(hass): """Set up ffmpeg component test register without startup.""" with assert_setup_component(1): - yield from async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) + await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) hass.bus.async_listen_once = MagicMock() ffmpeg_dev = MockFFmpegDev(hass, False) - yield from ffmpeg_dev.async_added_to_hass() + await ffmpeg_dev.async_added_to_hass() assert hass.bus.async_listen_once.called assert hass.bus.async_listen_once.call_count == 1 -@asyncio.coroutine -def test_setup_component_test_service_start(hass): +async def test_setup_component_test_service_start(hass): """Set up ffmpeg component test service start.""" with assert_setup_component(1): - yield from async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) + await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) ffmpeg_dev = MockFFmpegDev(hass, False) - yield from ffmpeg_dev.async_added_to_hass() + await ffmpeg_dev.async_added_to_hass() async_start(hass) - yield from hass.async_block_till_done() + await hass.async_block_till_done() assert ffmpeg_dev.called_start -@asyncio.coroutine -def test_setup_component_test_service_stop(hass): +async def test_setup_component_test_service_stop(hass): """Set up ffmpeg component test service stop.""" with assert_setup_component(1): - yield from async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) + await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) ffmpeg_dev = MockFFmpegDev(hass, False) - yield from ffmpeg_dev.async_added_to_hass() + await ffmpeg_dev.async_added_to_hass() async_stop(hass) - yield from hass.async_block_till_done() + await hass.async_block_till_done() assert ffmpeg_dev.called_stop -@asyncio.coroutine -def test_setup_component_test_service_restart(hass): +async def test_setup_component_test_service_restart(hass): """Set up ffmpeg component test service restart.""" with assert_setup_component(1): - yield from async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) + await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) ffmpeg_dev = MockFFmpegDev(hass, False) - yield from ffmpeg_dev.async_added_to_hass() + await ffmpeg_dev.async_added_to_hass() async_restart(hass) - yield from hass.async_block_till_done() + await hass.async_block_till_done() assert ffmpeg_dev.called_stop assert ffmpeg_dev.called_start -@asyncio.coroutine -def test_setup_component_test_service_start_with_entity(hass): +async def test_setup_component_test_service_start_with_entity(hass): """Set up ffmpeg component test service start.""" with assert_setup_component(1): - yield from async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) + await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) ffmpeg_dev = MockFFmpegDev(hass, False) - yield from ffmpeg_dev.async_added_to_hass() + await ffmpeg_dev.async_added_to_hass() async_start(hass, "test.ffmpeg_device") - yield from hass.async_block_till_done() + await hass.async_block_till_done() assert ffmpeg_dev.called_start assert ffmpeg_dev.called_entities == ["test.ffmpeg_device"]