Remove hass_recorder test fixture (#120295)
This commit is contained in:
parent
be6dfc7a70
commit
e32a27a8ff
3 changed files with 0 additions and 143 deletions
|
@ -125,7 +125,6 @@ _TEST_FIXTURES: dict[str, list[str] | str] = {
|
|||
"hass_owner_user": "MockUser",
|
||||
"hass_read_only_access_token": "str",
|
||||
"hass_read_only_user": "MockUser",
|
||||
"hass_recorder": "Callable[..., HomeAssistant]",
|
||||
"hass_storage": "dict[str, Any]",
|
||||
"hass_supervisor_access_token": "str",
|
||||
"hass_supervisor_user": "MockUser",
|
||||
|
|
|
@ -70,7 +70,6 @@ from homeassistant.helpers import (
|
|||
intent,
|
||||
issue_registry as ir,
|
||||
label_registry as lr,
|
||||
recorder as recorder_helper,
|
||||
restore_state as rs,
|
||||
storage,
|
||||
translation,
|
||||
|
@ -83,7 +82,6 @@ from homeassistant.helpers.entity import Entity
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.json import JSONEncoder, _orjson_default_encoder, json_dumps
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.util.async_ import run_callback_threadsafe
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.json import (
|
||||
|
@ -1162,30 +1160,6 @@ def assert_setup_component(count, domain=None):
|
|||
), f"setup_component failed, expected {count} got {res_len}: {res}"
|
||||
|
||||
|
||||
def init_recorder_component(hass, add_config=None, db_url="sqlite://"):
|
||||
"""Initialize the recorder."""
|
||||
# Local import to avoid processing recorder and SQLite modules when running a
|
||||
# testcase which does not use the recorder.
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from homeassistant.components import recorder
|
||||
|
||||
config = dict(add_config) if add_config else {}
|
||||
if recorder.CONF_DB_URL not in config:
|
||||
config[recorder.CONF_DB_URL] = db_url
|
||||
if recorder.CONF_COMMIT_INTERVAL not in config:
|
||||
config[recorder.CONF_COMMIT_INTERVAL] = 0
|
||||
|
||||
with patch("homeassistant.components.recorder.ALLOW_IN_MEMORY_DB", True):
|
||||
if recorder.DOMAIN not in hass.data:
|
||||
recorder_helper.async_initialize_recorder(hass)
|
||||
assert setup_component(hass, recorder.DOMAIN, {recorder.DOMAIN: config})
|
||||
assert recorder.DOMAIN in hass.config.components
|
||||
_LOGGER.info(
|
||||
"Test recorder successfully started, database location: %s",
|
||||
config[recorder.CONF_DB_URL],
|
||||
)
|
||||
|
||||
|
||||
def mock_restore_cache(hass: HomeAssistant, states: Sequence[State]) -> None:
|
||||
"""Mock the DATA_RESTORE_CACHE."""
|
||||
key = rs.DATA_RESTORE_STATE
|
||||
|
|
|
@ -106,8 +106,6 @@ from .common import ( # noqa: E402, isort:skip
|
|||
MockUser,
|
||||
async_fire_mqtt_message,
|
||||
async_test_home_assistant,
|
||||
get_test_home_assistant,
|
||||
init_recorder_component,
|
||||
mock_storage,
|
||||
patch_yaml_files,
|
||||
extract_stack_to_frame,
|
||||
|
@ -1350,120 +1348,6 @@ def recorder_db_url(
|
|||
sqlalchemy_utils.drop_database(db_url)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def hass_recorder(
|
||||
recorder_db_url: str,
|
||||
enable_nightly_purge: bool,
|
||||
enable_statistics: bool,
|
||||
enable_schema_validation: bool,
|
||||
enable_migrate_context_ids: bool,
|
||||
enable_migrate_event_type_ids: bool,
|
||||
enable_migrate_entity_ids: bool,
|
||||
hass_storage: dict[str, Any],
|
||||
) -> Generator[Callable[..., HomeAssistant]]:
|
||||
"""Home Assistant fixture with in-memory recorder."""
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from homeassistant.components import recorder
|
||||
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from homeassistant.components.recorder import migration
|
||||
|
||||
with get_test_home_assistant() as hass:
|
||||
nightly = (
|
||||
recorder.Recorder.async_nightly_tasks if enable_nightly_purge else None
|
||||
)
|
||||
stats = (
|
||||
recorder.Recorder.async_periodic_statistics if enable_statistics else None
|
||||
)
|
||||
compile_missing = (
|
||||
recorder.Recorder._schedule_compile_missing_statistics
|
||||
if enable_statistics
|
||||
else None
|
||||
)
|
||||
schema_validate = (
|
||||
migration._find_schema_errors
|
||||
if enable_schema_validation
|
||||
else itertools.repeat(set())
|
||||
)
|
||||
migrate_states_context_ids = (
|
||||
recorder.Recorder._migrate_states_context_ids
|
||||
if enable_migrate_context_ids
|
||||
else None
|
||||
)
|
||||
migrate_events_context_ids = (
|
||||
recorder.Recorder._migrate_events_context_ids
|
||||
if enable_migrate_context_ids
|
||||
else None
|
||||
)
|
||||
migrate_event_type_ids = (
|
||||
recorder.Recorder._migrate_event_type_ids
|
||||
if enable_migrate_event_type_ids
|
||||
else None
|
||||
)
|
||||
migrate_entity_ids = (
|
||||
recorder.Recorder._migrate_entity_ids if enable_migrate_entity_ids else None
|
||||
)
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.recorder.Recorder.async_nightly_tasks",
|
||||
side_effect=nightly,
|
||||
autospec=True,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.recorder.Recorder.async_periodic_statistics",
|
||||
side_effect=stats,
|
||||
autospec=True,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.recorder.migration._find_schema_errors",
|
||||
side_effect=schema_validate,
|
||||
autospec=True,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.recorder.Recorder._migrate_events_context_ids",
|
||||
side_effect=migrate_events_context_ids,
|
||||
autospec=True,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.recorder.Recorder._migrate_states_context_ids",
|
||||
side_effect=migrate_states_context_ids,
|
||||
autospec=True,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.recorder.Recorder._migrate_event_type_ids",
|
||||
side_effect=migrate_event_type_ids,
|
||||
autospec=True,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.recorder.Recorder._migrate_entity_ids",
|
||||
side_effect=migrate_entity_ids,
|
||||
autospec=True,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.recorder.Recorder._schedule_compile_missing_statistics",
|
||||
side_effect=compile_missing,
|
||||
autospec=True,
|
||||
),
|
||||
):
|
||||
|
||||
def setup_recorder(
|
||||
*, config: dict[str, Any] | None = None, timezone: str | None = None
|
||||
) -> HomeAssistant:
|
||||
"""Set up with params."""
|
||||
if timezone is not None:
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
hass.config.async_set_time_zone(timezone), hass.loop
|
||||
).result()
|
||||
init_recorder_component(hass, config, recorder_db_url)
|
||||
hass.start()
|
||||
hass.block_till_done()
|
||||
hass.data[recorder.DATA_INSTANCE].block_till_done()
|
||||
return hass
|
||||
|
||||
yield setup_recorder
|
||||
hass.stop()
|
||||
|
||||
|
||||
async def _async_init_recorder_component(
|
||||
hass: HomeAssistant,
|
||||
add_config: dict[str, Any] | None = None,
|
||||
|
|
Loading…
Add table
Reference in a new issue