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,16 +918,8 @@ 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:
"""Setup and return recorder instance.""" # noqa: D401
nightly = (
recorder.Recorder.async_nightly_tasks if enable_nightly_purge else None
)
stats = (
recorder.Recorder.async_periodic_statistics if enable_statistics else None
)
with patch( with patch(
"homeassistant.components.recorder.Recorder.async_nightly_tasks", "homeassistant.components.recorder.Recorder.async_nightly_tasks",
side_effect=nightly, side_effect=nightly,
@ -937,6 +929,11 @@ async def async_setup_recorder_instance(
side_effect=stats, side_effect=stats,
autospec=True, autospec=True,
): ):
async def async_setup_recorder(
hass: HomeAssistant, config: ConfigType | None = None
) -> recorder.Recorder:
"""Setup and return recorder instance.""" # noqa: D401
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