Fix recorder fixtures (#79147)

This commit is contained in:
Erik Montnemery 2022-09-27 17:00:06 +02:00 committed by GitHub
parent 53263ea9bc
commit 4fcd0f3e23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -918,25 +918,22 @@ async def async_setup_recorder_instance(
) -> AsyncGenerator[SetupRecorderInstanceT, None]: ) -> AsyncGenerator[SetupRecorderInstanceT, None]:
"""Yield callable to setup recorder instance.""" """Yield callable to setup recorder instance."""
async def async_setup_recorder( nightly = recorder.Recorder.async_nightly_tasks if enable_nightly_purge else None
hass: HomeAssistant, config: ConfigType | None = None stats = recorder.Recorder.async_periodic_statistics if enable_statistics else None
) -> recorder.Recorder: with patch(
"""Setup and return recorder instance.""" # noqa: D401 "homeassistant.components.recorder.Recorder.async_nightly_tasks",
nightly = ( side_effect=nightly,
recorder.Recorder.async_nightly_tasks if enable_nightly_purge else None autospec=True,
) ), patch(
stats = ( "homeassistant.components.recorder.Recorder.async_periodic_statistics",
recorder.Recorder.async_periodic_statistics if enable_statistics else None side_effect=stats,
) autospec=True,
with patch( ):
"homeassistant.components.recorder.Recorder.async_nightly_tasks",
side_effect=nightly, async def async_setup_recorder(
autospec=True, hass: HomeAssistant, config: ConfigType | None = None
), patch( ) -> recorder.Recorder:
"homeassistant.components.recorder.Recorder.async_periodic_statistics", """Setup and return recorder instance.""" # noqa: D401
side_effect=stats,
autospec=True,
):
await _async_init_recorder_component(hass, config) await _async_init_recorder_component(hass, config)
await hass.async_block_till_done() await hass.async_block_till_done()
instance = hass.data[recorder.DATA_INSTANCE] instance = hass.data[recorder.DATA_INSTANCE]
@ -945,13 +942,13 @@ async def async_setup_recorder_instance(
await async_recorder_block_till_done(hass) await async_recorder_block_till_done(hass)
return instance return instance
return async_setup_recorder yield async_setup_recorder
@pytest.fixture @pytest.fixture
async def recorder_mock(recorder_config, async_setup_recorder_instance, hass): async def recorder_mock(recorder_config, async_setup_recorder_instance, hass):
"""Fixture with in-memory recorder.""" """Fixture with in-memory recorder."""
await async_setup_recorder_instance(hass, recorder_config) yield await async_setup_recorder_instance(hass, recorder_config)
@pytest.fixture @pytest.fixture