Fix recorder fixture typing (#136174)

This commit is contained in:
Marc Mueller 2025-01-22 05:18:05 +01:00 committed by GitHub
parent ffcb4d676b
commit f822fd82bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 100 additions and 87 deletions

View File

@ -106,7 +106,8 @@ _TEST_FIXTURES: dict[str, list[str] | str] = {
"aiohttp_client": "ClientSessionGenerator",
"aiohttp_server": "Callable[[], TestServer]",
"area_registry": "AreaRegistry",
"async_test_recorder": "RecorderInstanceGenerator",
"async_test_recorder": "RecorderInstanceContextManager",
"async_setup_recorder_instance": "RecorderInstanceGenerator",
"caplog": "pytest.LogCaptureFixture",
"capsys": "pytest.CaptureFixture[str]",
"current_request_with_host": "None",

View File

@ -11,12 +11,12 @@ from homeassistant.core import HomeAssistant
from homeassistant.util import dt as dt_util
from tests.common import MockConfigEntry
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""

View File

@ -8,12 +8,12 @@ from homeassistant.const import CONF_DOMAINS, CONF_ENTITIES, CONF_EXCLUDE, CONF_
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""

View File

@ -8,12 +8,12 @@ from homeassistant.core import HomeAssistant
from ...common import async_wait_recording_done
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""
@ -22,7 +22,7 @@ async def mock_recorder_before_hass(
@pytest.mark.parametrize("db_engine", ["mysql", "postgresql"])
async def test_validate_db_schema_fix_float_issue(
hass: HomeAssistant,
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
db_engine: str,
recorder_dialect_name: None,
@ -58,7 +58,7 @@ async def test_validate_db_schema_fix_float_issue(
@pytest.mark.parametrize("db_engine", ["mysql"])
async def test_validate_db_schema_fix_utf8_issue_event_data(
hass: HomeAssistant,
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
db_engine: str,
recorder_dialect_name: None,
@ -91,7 +91,7 @@ async def test_validate_db_schema_fix_utf8_issue_event_data(
@pytest.mark.parametrize("db_engine", ["mysql"])
async def test_validate_db_schema_fix_collation_issue(
hass: HomeAssistant,
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
db_engine: str,
recorder_dialect_name: None,

View File

@ -8,12 +8,12 @@ from homeassistant.core import HomeAssistant
from ...common import async_wait_recording_done
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""
@ -22,7 +22,7 @@ async def mock_recorder_before_hass(
@pytest.mark.parametrize("db_engine", ["mysql", "postgresql"])
async def test_validate_db_schema_fix_float_issue(
hass: HomeAssistant,
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
db_engine: str,
recorder_dialect_name: None,
@ -60,7 +60,7 @@ async def test_validate_db_schema_fix_float_issue(
@pytest.mark.parametrize("db_engine", ["mysql"])
async def test_validate_db_schema_fix_utf8_issue_states(
hass: HomeAssistant,
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
db_engine: str,
recorder_dialect_name: None,
@ -92,7 +92,7 @@ async def test_validate_db_schema_fix_utf8_issue_states(
@pytest.mark.parametrize("db_engine", ["mysql"])
async def test_validate_db_schema_fix_utf8_issue_state_attributes(
hass: HomeAssistant,
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
db_engine: str,
recorder_dialect_name: None,
@ -125,7 +125,7 @@ async def test_validate_db_schema_fix_utf8_issue_state_attributes(
@pytest.mark.parametrize("db_engine", ["mysql"])
async def test_validate_db_schema_fix_collation_issue(
hass: HomeAssistant,
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
db_engine: str,
recorder_dialect_name: None,

View File

@ -22,12 +22,12 @@ import homeassistant.util.dt as dt_util
from ...common import async_wait_recording_done
from tests.common import async_test_home_assistant
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""
@ -134,7 +134,7 @@ def _create_engine_28(*args, **kwargs):
@pytest.mark.parametrize("persistent_database", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_delete_metadata_duplicates(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test removal of duplicated statistics."""
@ -242,7 +242,7 @@ async def test_delete_metadata_duplicates(
@pytest.mark.parametrize("persistent_database", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_delete_metadata_duplicates_many(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test removal of duplicated statistics."""

View File

@ -8,12 +8,12 @@ from homeassistant.core import HomeAssistant
from ...common import async_wait_recording_done
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""
@ -22,7 +22,7 @@ async def mock_recorder_before_hass(
@pytest.mark.parametrize("enable_schema_validation", [True])
async def test_validate_db_schema_fix_utf8_issue(
hass: HomeAssistant,
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
db_engine: str,
recorder_dialect_name: None,
@ -56,7 +56,7 @@ async def test_validate_db_schema_fix_utf8_issue(
@pytest.mark.parametrize("db_engine", ["mysql", "postgresql"])
async def test_validate_db_schema_fix_float_issue(
hass: HomeAssistant,
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
table: str,
db_engine: str,
@ -100,7 +100,7 @@ async def test_validate_db_schema_fix_float_issue(
@pytest.mark.parametrize("db_engine", ["mysql"])
async def test_validate_db_schema_fix_collation_issue(
hass: HomeAssistant,
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
recorder_dialect_name: None,
db_engine: str,

View File

@ -18,12 +18,12 @@ from homeassistant.core import HomeAssistant
from ..common import async_wait_recording_done
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""

View File

@ -23,7 +23,7 @@ from .common import (
)
from tests.common import MockEntity, MockEntityPlatform
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
def _count_entity_id_in_states_meta(
@ -40,7 +40,7 @@ def _count_entity_id_in_states_meta(
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""

View File

@ -33,12 +33,12 @@ from .common import (
async_wait_recording_done,
)
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""

View File

@ -28,12 +28,12 @@ from .common import (
old_db_schema,
)
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""

View File

@ -31,12 +31,12 @@ from .common import (
)
from .db_schema_42 import StateAttributes, States, StatesMeta
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""

View File

@ -98,12 +98,12 @@ from tests.common import (
async_test_home_assistant,
mock_platform,
)
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager, RecorderInstanceGenerator
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""
@ -1373,7 +1373,7 @@ async def test_statistics_runs_initiated(
@pytest.mark.parametrize("enable_missing_statistics", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_compile_missing_statistics(
async_test_recorder: RecorderInstanceGenerator, freezer: FrozenDateTimeFactory
async_test_recorder: RecorderInstanceContextManager, freezer: FrozenDateTimeFactory
) -> None:
"""Test missing statistics are compiled on startup."""
now = dt_util.utcnow().replace(minute=0, second=0, microsecond=0)
@ -1632,7 +1632,7 @@ async def test_service_disable_states_not_recording(
@pytest.mark.parametrize("persistent_database", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_service_disable_run_information_recorded(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Test that runs are still recorded when recorder is disabled."""

View File

@ -37,12 +37,12 @@ from .common import async_wait_recording_done, create_engine_test
from .conftest import InstrumentedMigration
from tests.common import async_fire_time_changed
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager, RecorderInstanceGenerator
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""

View File

@ -52,7 +52,7 @@ from .common import (
from .conftest import instrument_migration
from tests.common import async_test_home_assistant
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
CREATE_ENGINE_TARGET = "homeassistant.components.recorder.core.create_engine"
SCHEMA_MODULE_32 = "tests.components.recorder.db_schema_32"
@ -60,7 +60,7 @@ SCHEMA_MODULE_32 = "tests.components.recorder.db_schema_32"
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""
@ -124,7 +124,7 @@ def db_schema_32():
@pytest.mark.parametrize("indices_to_drop", [[], [("events", "ix_events_context_id")]])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_migrate_events_context_ids(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
indices_to_drop: list[tuple[str, str]],
) -> None:
"""Test we can migrate old uuid context ids and ulid context ids to binary format."""
@ -396,7 +396,7 @@ async def test_migrate_events_context_ids(
@pytest.mark.parametrize("enable_migrate_event_context_ids", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_finish_migrate_events_context_ids(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Test we re migrate old uuid context ids and ulid context ids to binary format.
@ -505,7 +505,7 @@ async def test_finish_migrate_events_context_ids(
@pytest.mark.parametrize("indices_to_drop", [[], [("states", "ix_states_context_id")]])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_migrate_states_context_ids(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
indices_to_drop: list[tuple[str, str]],
) -> None:
"""Test we can migrate old uuid context ids and ulid context ids to binary format."""
@ -758,7 +758,7 @@ async def test_migrate_states_context_ids(
@pytest.mark.parametrize("enable_migrate_state_context_ids", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_finish_migrate_states_context_ids(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Test we re migrate old uuid context ids and ulid context ids to binary format.
@ -866,7 +866,7 @@ async def test_finish_migrate_states_context_ids(
@pytest.mark.parametrize("enable_migrate_event_type_ids", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_migrate_event_type_ids(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Test we can migrate event_types to the EventTypes table."""
importlib.import_module(SCHEMA_MODULE_32)
@ -984,7 +984,7 @@ async def test_migrate_event_type_ids(
@pytest.mark.parametrize("enable_migrate_entity_ids", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_migrate_entity_ids(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Test we can migrate entity_ids to the StatesMeta table."""
importlib.import_module(SCHEMA_MODULE_32)
@ -1092,7 +1092,7 @@ async def test_migrate_entity_ids(
)
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_post_migrate_entity_ids(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
indices_to_drop: list[tuple[str, str]],
) -> None:
"""Test we can migrate entity_ids to the StatesMeta table."""
@ -1200,7 +1200,7 @@ async def test_post_migrate_entity_ids(
@pytest.mark.parametrize("enable_migrate_entity_ids", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_migrate_null_entity_ids(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Test we can migrate entity_ids to the StatesMeta table."""
importlib.import_module(SCHEMA_MODULE_32)
@ -1310,7 +1310,7 @@ async def test_migrate_null_entity_ids(
@pytest.mark.parametrize("enable_migrate_event_type_ids", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_migrate_null_event_type_ids(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Test we can migrate event_types to the EventTypes table when the event_type is NULL."""
importlib.import_module(SCHEMA_MODULE_32)
@ -1991,7 +1991,7 @@ async def test_stats_timestamp_with_one_by_one_removes_duplicates(
@pytest.mark.parametrize("persistent_database", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_stats_migrate_times(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test we can migrate times in the statistics tables."""
@ -2147,7 +2147,7 @@ async def test_stats_migrate_times(
@pytest.mark.parametrize("persistent_database", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_cleanup_unmigrated_state_timestamps(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Ensure schema 48 migration cleans up any unmigrated state timestamps."""
importlib.import_module(SCHEMA_MODULE_32)

View File

@ -25,7 +25,7 @@ from homeassistant.core import HomeAssistant
from .common import async_recorder_block_till_done, async_wait_recording_done
from tests.common import async_test_home_assistant
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
CREATE_ENGINE_TARGET = "homeassistant.components.recorder.core.create_engine"
SCHEMA_MODULE_32 = "tests.components.recorder.db_schema_32"
@ -34,7 +34,7 @@ SCHEMA_MODULE_CURRENT = "homeassistant.components.recorder.db_schema"
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""
@ -175,7 +175,7 @@ def _create_engine_test(
],
)
async def test_data_migrator_logic(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
initial_version: int,
expected_migrator_calls: dict[str, tuple[int, int]],
expected_created_indices: list[str],
@ -274,7 +274,7 @@ async def test_data_migrator_logic(
@pytest.mark.parametrize("persistent_database", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_migration_changes_prevent_trying_to_migrate_again(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Test that we do not try to migrate when migration_changes indicate its already migrated.

View File

@ -45,7 +45,7 @@ from .common import (
convert_pending_states_to_meta,
)
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
TEST_EVENT_TYPES = (
"EVENT_TEST_AUTOPURGE",
@ -59,7 +59,7 @@ TEST_EVENT_TYPES = (
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""

View File

@ -47,12 +47,12 @@ from .db_schema_32 import (
StatisticsShortTerm,
)
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""

View File

@ -54,12 +54,12 @@ from .common import (
)
from tests.common import MockPlatform, mock_platform
from tests.typing import RecorderInstanceGenerator, WebSocketGenerator
from tests.typing import RecorderInstanceContextManager, WebSocketGenerator
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""

View File

@ -27,7 +27,7 @@ from .common import (
)
from tests.common import async_test_home_assistant
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
SCHEMA_VERSION_POSTFIX = "23_with_newer_columns"
SCHEMA_MODULE = get_schema_module_path(SCHEMA_VERSION_POSTFIX)
@ -37,7 +37,8 @@ SCHEMA_MODULE = get_schema_module_path(SCHEMA_VERSION_POSTFIX)
@pytest.mark.usefixtures("skip_by_db_engine")
@pytest.mark.parametrize("persistent_database", [True])
async def test_delete_duplicates(
async_test_recorder: RecorderInstanceGenerator, caplog: pytest.LogCaptureFixture
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test removal of duplicated statistics.
@ -224,7 +225,8 @@ async def test_delete_duplicates(
@pytest.mark.usefixtures("skip_by_db_engine")
@pytest.mark.parametrize("persistent_database", [True])
async def test_delete_duplicates_many(
async_test_recorder: RecorderInstanceGenerator, caplog: pytest.LogCaptureFixture
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test removal of duplicated statistics.
@ -418,7 +420,7 @@ async def test_delete_duplicates_many(
@pytest.mark.usefixtures("skip_by_db_engine")
@pytest.mark.parametrize("persistent_database", [True])
async def test_delete_duplicates_non_identical(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
tmp_path: Path,
) -> None:
@ -613,7 +615,7 @@ async def test_delete_duplicates_non_identical(
@pytest.mark.skip_on_db_engine(["mysql", "postgresql"])
@pytest.mark.usefixtures("skip_by_db_engine")
async def test_delete_duplicates_short_term(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
tmp_path: Path,
) -> None:

View File

@ -55,12 +55,12 @@ from .common import (
)
from tests.common import async_test_home_assistant
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager, RecorderInstanceGenerator
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder."""

View File

@ -23,7 +23,7 @@ from .common import async_wait_recording_done
from .conftest import instrument_migration
from tests.common import async_test_home_assistant
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
CREATE_ENGINE_TARGET = "homeassistant.components.recorder.core.create_engine"
SCHEMA_MODULE_30 = "tests.components.recorder.db_schema_30"
@ -73,7 +73,7 @@ def _create_engine_test(
@pytest.mark.parametrize("persistent_database", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_migrate_times(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test we can migrate times in the events and states tables.
@ -240,7 +240,7 @@ async def test_migrate_times(
@pytest.mark.parametrize("persistent_database", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_migrate_can_resume_entity_id_post_migration(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
recorder_db_url: str,
) -> None:
@ -351,7 +351,7 @@ async def test_migrate_can_resume_entity_id_post_migration(
@pytest.mark.parametrize("persistent_database", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_migrate_can_resume_ix_states_event_id_removed(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
recorder_db_url: str,
) -> None:
@ -490,7 +490,7 @@ async def test_migrate_can_resume_ix_states_event_id_removed(
@pytest.mark.parametrize("persistent_database", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_out_of_disk_space_while_rebuild_states_table(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
recorder_db_url: str,
) -> None:
@ -670,7 +670,7 @@ async def test_out_of_disk_space_while_rebuild_states_table(
@pytest.mark.parametrize("persistent_database", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_out_of_disk_space_while_removing_foreign_key(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
caplog: pytest.LogCaptureFixture,
recorder_db_url: str,
) -> None:

View File

@ -41,7 +41,11 @@ from .common import (
from .conftest import InstrumentedMigration
from tests.common import async_fire_time_changed
from tests.typing import RecorderInstanceGenerator, WebSocketGenerator
from tests.typing import (
RecorderInstanceContextManager,
RecorderInstanceGenerator,
WebSocketGenerator,
)
@pytest.fixture
@ -2623,7 +2627,7 @@ async def test_recorder_info_no_instance(
async def test_recorder_info_migration_queue_exhausted(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
instrument_migration: InstrumentedMigration,
) -> None:
"""Test getting recorder status when recorder queue is exhausted."""

View File

@ -57,7 +57,7 @@ from tests.components.recorder.common import (
)
from tests.typing import (
MockHAClientWebSocket,
RecorderInstanceGenerator,
RecorderInstanceContextManager,
WebSocketGenerator,
)
@ -102,7 +102,7 @@ KW_SENSOR_ATTRIBUTES = {
@pytest.fixture
async def mock_recorder_before_hass(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> None:
"""Set up recorder patches."""

View File

@ -24,7 +24,7 @@ from tests.components.recorder.common import (
async_wait_recording_done,
do_adhoc_statistics,
)
from tests.typing import RecorderInstanceGenerator
from tests.typing import RecorderInstanceContextManager
POWER_SENSOR_ATTRIBUTES = {
"device_class": "energy",
@ -47,7 +47,7 @@ def disable_db_issue_creation():
@pytest.mark.parametrize("enable_missing_statistics", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_compile_missing_statistics(
async_test_recorder: RecorderInstanceGenerator, freezer: FrozenDateTimeFactory
async_test_recorder: RecorderInstanceContextManager, freezer: FrozenDateTimeFactory
) -> None:
"""Test compile missing statistics."""
three_days_ago = datetime(2021, 1, 1, 0, 0, 0, tzinfo=dt_util.UTC)

View File

@ -102,6 +102,7 @@ from .typing import (
MqttMockHAClient,
MqttMockHAClientGenerator,
MqttMockPahoClient,
RecorderInstanceContextManager,
RecorderInstanceGenerator,
WebSocketGenerator,
)
@ -1536,7 +1537,7 @@ async def async_test_recorder(
enable_migrate_event_type_ids: bool,
enable_migrate_entity_ids: bool,
enable_migrate_event_ids: bool,
) -> AsyncGenerator[RecorderInstanceGenerator]:
) -> AsyncGenerator[RecorderInstanceContextManager]:
"""Yield context manager to setup recorder instance."""
# pylint: disable-next=import-outside-toplevel
from homeassistant.components import recorder
@ -1702,7 +1703,7 @@ async def async_test_recorder(
@pytest.fixture
async def async_setup_recorder_instance(
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
) -> AsyncGenerator[RecorderInstanceGenerator]:
"""Yield callable to setup recorder instance."""
@ -1715,7 +1716,7 @@ async def async_setup_recorder_instance(
expected_setup_result: bool = True,
wait_recorder: bool = True,
wait_recorder_setup: bool = True,
) -> AsyncGenerator[recorder.Recorder]:
) -> recorder.Recorder:
"""Set up and return recorder instance."""
return await stack.enter_async_context(
@ -1734,7 +1735,7 @@ async def async_setup_recorder_instance(
@pytest.fixture
async def recorder_mock(
recorder_config: dict[str, Any] | None,
async_test_recorder: RecorderInstanceGenerator,
async_test_recorder: RecorderInstanceContextManager,
hass: HomeAssistant,
) -> AsyncGenerator[recorder.Recorder]:
"""Fixture with in-memory recorder."""

View File

@ -3,6 +3,7 @@
from __future__ import annotations
from collections.abc import Callable, Coroutine
from contextlib import AbstractAsyncContextManager
from typing import TYPE_CHECKING, Any
from unittest.mock import MagicMock
@ -30,6 +31,10 @@ type MqttMockHAClient = MagicMock
"""MagicMock for `homeassistant.components.mqtt.MQTT`."""
type MqttMockHAClientGenerator = Callable[..., Coroutine[Any, Any, MqttMockHAClient]]
"""MagicMock generator for `homeassistant.components.mqtt.MQTT`."""
type RecorderInstanceContextManager = Callable[
..., AbstractAsyncContextManager[Recorder]
]
"""ContextManager for `homeassistant.components.recorder.Recorder`."""
type RecorderInstanceGenerator = Callable[..., Coroutine[Any, Any, Recorder]]
"""Instance generator for `homeassistant.components.recorder.Recorder`."""
type WebSocketGenerator = Callable[..., Coroutine[Any, Any, MockHAClientWebSocket]]