26 lines
773 B
Python
26 lines
773 B
Python
"""Fixtures for the recorder component tests."""
|
|
|
|
from collections.abc import Generator
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components import recorder
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
|
@pytest.fixture
|
|
def recorder_dialect_name(
|
|
hass: HomeAssistant, db_engine: str
|
|
) -> Generator[None, None, None]:
|
|
"""Patch the recorder dialect."""
|
|
if instance := hass.data.get(recorder.DATA_INSTANCE):
|
|
instance.__dict__.pop("dialect_name", None)
|
|
with patch.object(instance, "_dialect_name", db_engine):
|
|
yield
|
|
instance.__dict__.pop("dialect_name", None)
|
|
else:
|
|
with patch(
|
|
"homeassistant.components.recorder.Recorder.dialect_name", db_engine
|
|
):
|
|
yield
|