Convert test helpers to get hass instance to contextmanagers (#109990)

* Convert get_test_home_assistant helper to contextmanager

* Convert async_test_home_assistant helper to contextmanager

* Move timezone reset to async_test_home_assistant helper
This commit is contained in:
Marc Mueller
2024-02-11 21:23:51 +01:00
committed by GitHub
parent 3342e6ddbd
commit 2ef2172b01
17 changed files with 750 additions and 784 deletions

View File

@@ -75,32 +75,26 @@ class MockFFmpegDev(ffmpeg.FFmpegBase):
self.called_entities = entity_ids
class TestFFmpegSetup:
"""Test class for ffmpeg."""
def setup_method(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def teardown_method(self):
"""Stop everything that was started."""
self.hass.stop()
def test_setup_component(self):
"""Set up ffmpeg component."""
def test_setup_component():
"""Set up ffmpeg component."""
with get_test_home_assistant() as hass:
with assert_setup_component(1):
setup_component(self.hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
assert self.hass.data[ffmpeg.DATA_FFMPEG].binary == "ffmpeg"
assert hass.data[ffmpeg.DATA_FFMPEG].binary == "ffmpeg"
hass.stop()
def test_setup_component_test_service(self):
"""Set up ffmpeg component test services."""
def test_setup_component_test_service():
"""Set up ffmpeg component test services."""
with get_test_home_assistant() as hass:
with assert_setup_component(1):
setup_component(self.hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
assert self.hass.services.has_service(ffmpeg.DOMAIN, "start")
assert self.hass.services.has_service(ffmpeg.DOMAIN, "stop")
assert self.hass.services.has_service(ffmpeg.DOMAIN, "restart")
assert hass.services.has_service(ffmpeg.DOMAIN, "start")
assert hass.services.has_service(ffmpeg.DOMAIN, "stop")
assert hass.services.has_service(ffmpeg.DOMAIN, "restart")
hass.stop()
async def test_setup_component_test_register(hass: HomeAssistant) -> None: