diff --git a/tests/helpers/test_category_registry.py b/tests/helpers/test_category_registry.py index 1800b3babe9..1317750ebec 100644 --- a/tests/helpers/test_category_registry.py +++ b/tests/helpers/test_category_registry.py @@ -340,7 +340,7 @@ async def test_load_categories( @pytest.mark.parametrize("load_registries", [False]) async def test_loading_categories_from_storage( - hass: HomeAssistant, hass_storage: Any + hass: HomeAssistant, hass_storage: dict[str, Any] ) -> None: """Test loading stored categories on start.""" hass_storage[cr.STORAGE_KEY] = { diff --git a/tests/helpers/test_device_registry.py b/tests/helpers/test_device_registry.py index da99f176a3c..3ad45d630df 100644 --- a/tests/helpers/test_device_registry.py +++ b/tests/helpers/test_device_registry.py @@ -534,7 +534,7 @@ async def test_migration_1_3_to_1_5( hass: HomeAssistant, hass_storage: dict[str, Any], mock_config_entry: MockConfigEntry, -): +) -> None: """Test migration from version 1.3 to 1.5.""" hass_storage[dr.STORAGE_KEY] = { "version": 1, @@ -659,7 +659,7 @@ async def test_migration_1_4_to_1_5( hass: HomeAssistant, hass_storage: dict[str, Any], mock_config_entry: MockConfigEntry, -): +) -> None: """Test migration from version 1.4 to 1.5.""" hass_storage[dr.STORAGE_KEY] = { "version": 1, @@ -1219,7 +1219,7 @@ async def test_format_mac( config_entry_id=mock_config_entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, ) - for mac in ["123456ABCDEF", "123456abcdef", "12:34:56:ab:cd:ef", "1234.56ab.cdef"]: + for mac in ("123456ABCDEF", "123456abcdef", "12:34:56:ab:cd:ef", "1234.56ab.cdef"): test_entry = device_registry.async_get_or_create( config_entry_id=mock_config_entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, mac)}, @@ -1230,14 +1230,14 @@ async def test_format_mac( } # This should not raise - for invalid in [ + for invalid in ( "invalid_mac", "123456ABCDEFG", # 1 extra char "12:34:56:ab:cdef", # not enough : "12:34:56:ab:cd:e:f", # too many : "1234.56abcdef", # not enough . "123.456.abc.def", # too many . - ]: + ): invalid_mac_entry = device_registry.async_get_or_create( config_entry_id=mock_config_entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, invalid)}, @@ -2235,7 +2235,7 @@ async def test_device_info_configuration_url_validation( hass: HomeAssistant, device_registry: dr.DeviceRegistry, configuration_url: str | URL | None, - expectation, + expectation: AbstractContextManager, ) -> None: """Test configuration URL of device info is properly validated.""" config_entry_1 = MockConfigEntry() diff --git a/tests/helpers/test_entity_registry.py b/tests/helpers/test_entity_registry.py index 4256707b7b1..4dc8d79be3f 100644 --- a/tests/helpers/test_entity_registry.py +++ b/tests/helpers/test_entity_registry.py @@ -30,7 +30,7 @@ from tests.common import ( YAML__OPEN_PATH = "homeassistant.util.yaml.loader.open" -async def test_get(entity_registry: er.EntityRegistry): +async def test_get(entity_registry: er.EntityRegistry) -> None: """Test we can get an item.""" entry = entity_registry.async_get_or_create("light", "hue", "1234") @@ -620,7 +620,7 @@ async def test_removing_config_entry_id( async def test_deleted_entity_removing_config_entry_id( entity_registry: er.EntityRegistry, -): +) -> None: """Test that we update config entry id in registry on deleted entity.""" mock_config = MockConfigEntry(domain="light", entry_id="mock-id-1") @@ -1528,9 +1528,7 @@ def test_entity_registry_items() -> None: assert entities.get_entry(entry2.id) is None -async def test_disabled_by_str_not_allowed( - hass: HomeAssistant, entity_registry: er.EntityRegistry -) -> None: +async def test_disabled_by_str_not_allowed(entity_registry: er.EntityRegistry) -> None: """Test we need to pass disabled by type.""" with pytest.raises(ValueError): entity_registry.async_get_or_create( @@ -1545,7 +1543,7 @@ async def test_disabled_by_str_not_allowed( async def test_entity_category_str_not_allowed( - hass: HomeAssistant, entity_registry: er.EntityRegistry + entity_registry: er.EntityRegistry, ) -> None: """Test we need to pass entity category type.""" with pytest.raises(ValueError): @@ -1574,9 +1572,7 @@ async def test_hidden_by_str_not_allowed(entity_registry: er.EntityRegistry) -> ) -async def test_unique_id_non_hashable( - hass: HomeAssistant, entity_registry: er.EntityRegistry -) -> None: +async def test_unique_id_non_hashable(entity_registry: er.EntityRegistry) -> None: """Test unique_id which is not hashable.""" with pytest.raises(TypeError): entity_registry.async_get_or_create("light", "hue", ["not", "valid"]) @@ -1587,9 +1583,7 @@ async def test_unique_id_non_hashable( async def test_unique_id_non_string( - hass: HomeAssistant, - entity_registry: er.EntityRegistry, - caplog: pytest.LogCaptureFixture, + entity_registry: er.EntityRegistry, caplog: pytest.LogCaptureFixture ) -> None: """Test unique_id which is not a string.""" entity_registry.async_get_or_create("light", "hue", 1234) @@ -1683,7 +1677,7 @@ async def test_restore_entity( hass: HomeAssistant, entity_registry: er.EntityRegistry, freezer: FrozenDateTimeFactory, -): +) -> None: """Make sure entity registry id is stable and entity_id is reused if possible.""" update_events = async_capture_events(hass, er.EVENT_ENTITY_REGISTRY_UPDATED) config_entry = MockConfigEntry(domain="light") @@ -1777,7 +1771,7 @@ async def test_restore_entity( async def test_async_migrate_entry_delete_self( hass: HomeAssistant, entity_registry: er.EntityRegistry -): +) -> None: """Test async_migrate_entry.""" config_entry1 = MockConfigEntry(domain="test1") config_entry2 = MockConfigEntry(domain="test2") @@ -1812,7 +1806,7 @@ async def test_async_migrate_entry_delete_self( async def test_async_migrate_entry_delete_other( hass: HomeAssistant, entity_registry: er.EntityRegistry -): +) -> None: """Test async_migrate_entry.""" config_entry1 = MockConfigEntry(domain="test1") config_entry2 = MockConfigEntry(domain="test2") diff --git a/tests/helpers/test_floor_registry.py b/tests/helpers/test_floor_registry.py index 95381e82389..3b07563fd11 100644 --- a/tests/helpers/test_floor_registry.py +++ b/tests/helpers/test_floor_registry.py @@ -8,14 +8,6 @@ import pytest from homeassistant.core import HomeAssistant from homeassistant.helpers import area_registry as ar, floor_registry as fr -from homeassistant.helpers.floor_registry import ( - EVENT_FLOOR_REGISTRY_UPDATED, - STORAGE_KEY, - STORAGE_VERSION_MAJOR, - FloorRegistry, - async_get, - async_load, -) from tests.common import async_capture_events, flush_store @@ -30,7 +22,7 @@ async def test_create_floor( hass: HomeAssistant, floor_registry: fr.FloorRegistry ) -> None: """Make sure that we can create floors.""" - update_events = async_capture_events(hass, EVENT_FLOOR_REGISTRY_UPDATED) + update_events = async_capture_events(hass, fr.EVENT_FLOOR_REGISTRY_UPDATED) floor = floor_registry.async_create( name="First floor", icon="mdi:home-floor-1", @@ -59,7 +51,7 @@ async def test_create_floor_with_name_already_in_use( hass: HomeAssistant, floor_registry: fr.FloorRegistry ) -> None: """Make sure that we can't create a floor with a name already in use.""" - update_events = async_capture_events(hass, EVENT_FLOOR_REGISTRY_UPDATED) + update_events = async_capture_events(hass, fr.EVENT_FLOOR_REGISTRY_UPDATED) floor_registry.async_create("First floor") with pytest.raises( @@ -75,7 +67,7 @@ async def test_create_floor_with_name_already_in_use( async def test_create_floor_with_id_already_in_use( - hass: HomeAssistant, floor_registry: fr.FloorRegistry + floor_registry: fr.FloorRegistry, ) -> None: """Make sure that we can't create an floor with an id already in use.""" floor = floor_registry.async_create("First") @@ -92,7 +84,7 @@ async def test_delete_floor( hass: HomeAssistant, floor_registry: fr.FloorRegistry ) -> None: """Make sure that we can delete a floor.""" - update_events = async_capture_events(hass, EVENT_FLOOR_REGISTRY_UPDATED) + update_events = async_capture_events(hass, fr.EVENT_FLOOR_REGISTRY_UPDATED) floor = floor_registry.async_create("First floor") assert len(floor_registry.floors) == 1 @@ -127,7 +119,7 @@ async def test_update_floor( hass: HomeAssistant, floor_registry: fr.FloorRegistry ) -> None: """Make sure that we can update floors.""" - update_events = async_capture_events(hass, EVENT_FLOOR_REGISTRY_UPDATED) + update_events = async_capture_events(hass, fr.EVENT_FLOOR_REGISTRY_UPDATED) floor = floor_registry.async_create("First floor") assert len(floor_registry.floors) == 1 @@ -171,7 +163,7 @@ async def test_update_floor_with_same_data( hass: HomeAssistant, floor_registry: fr.FloorRegistry ) -> None: """Make sure that we can reapply the same data to a floor and it won't update.""" - update_events = async_capture_events(hass, EVENT_FLOOR_REGISTRY_UPDATED) + update_events = async_capture_events(hass, fr.EVENT_FLOOR_REGISTRY_UPDATED) floor = floor_registry.async_create( "First floor", icon="mdi:home-floor-1", @@ -262,7 +254,7 @@ async def test_load_floors( assert len(floor_registry.floors) == 2 - registry2 = FloorRegistry(hass) + registry2 = fr.FloorRegistry(hass) await flush_store(floor_registry._store) await registry2.async_load() @@ -288,11 +280,11 @@ async def test_load_floors( @pytest.mark.parametrize("load_registries", [False]) async def test_loading_floors_from_storage( - hass: HomeAssistant, hass_storage: Any + hass: HomeAssistant, hass_storage: dict[str, Any] ) -> None: """Test loading stored floors on start.""" - hass_storage[STORAGE_KEY] = { - "version": STORAGE_VERSION_MAJOR, + hass_storage[fr.STORAGE_KEY] = { + "version": fr.STORAGE_VERSION_MAJOR, "data": { "floors": [ { @@ -306,8 +298,8 @@ async def test_loading_floors_from_storage( }, } - await async_load(hass) - registry = async_get(hass) + await fr.async_load(hass) + registry = fr.async_get(hass) assert len(registry.floors) == 1 diff --git a/tests/helpers/test_label_registry.py b/tests/helpers/test_label_registry.py index af53ef51f98..445319a4b62 100644 --- a/tests/helpers/test_label_registry.py +++ b/tests/helpers/test_label_registry.py @@ -12,14 +12,6 @@ from homeassistant.helpers import ( entity_registry as er, label_registry as lr, ) -from homeassistant.helpers.label_registry import ( - EVENT_LABEL_REGISTRY_UPDATED, - STORAGE_KEY, - STORAGE_VERSION_MAJOR, - LabelRegistry, - async_get, - async_load, -) from tests.common import MockConfigEntry, async_capture_events, flush_store @@ -34,7 +26,7 @@ async def test_create_label( hass: HomeAssistant, label_registry: lr.LabelRegistry ) -> None: """Make sure that we can create labels.""" - update_events = async_capture_events(hass, EVENT_LABEL_REGISTRY_UPDATED) + update_events = async_capture_events(hass, lr.EVENT_LABEL_REGISTRY_UPDATED) label = label_registry.async_create( name="My Label", color="#FF0000", @@ -63,7 +55,7 @@ async def test_create_label_with_name_already_in_use( hass: HomeAssistant, label_registry: lr.LabelRegistry ) -> None: """Make sure that we can't create a label with a ID already in use.""" - update_events = async_capture_events(hass, EVENT_LABEL_REGISTRY_UPDATED) + update_events = async_capture_events(hass, lr.EVENT_LABEL_REGISTRY_UPDATED) label_registry.async_create("mock") with pytest.raises( @@ -95,7 +87,7 @@ async def test_delete_label( hass: HomeAssistant, label_registry: lr.LabelRegistry ) -> None: """Make sure that we can delete a label.""" - update_events = async_capture_events(hass, EVENT_LABEL_REGISTRY_UPDATED) + update_events = async_capture_events(hass, lr.EVENT_LABEL_REGISTRY_UPDATED) label = label_registry.async_create("Label") assert len(label_registry.labels) == 1 @@ -130,7 +122,7 @@ async def test_update_label( hass: HomeAssistant, label_registry: lr.LabelRegistry ) -> None: """Make sure that we can update labels.""" - update_events = async_capture_events(hass, EVENT_LABEL_REGISTRY_UPDATED) + update_events = async_capture_events(hass, lr.EVENT_LABEL_REGISTRY_UPDATED) label = label_registry.async_create("Mock") assert len(label_registry.labels) == 1 @@ -174,7 +166,7 @@ async def test_update_label_with_same_data( hass: HomeAssistant, label_registry: lr.LabelRegistry ) -> None: """Make sure that we can reapply the same data to the label and it won't update.""" - update_events = async_capture_events(hass, EVENT_LABEL_REGISTRY_UPDATED) + update_events = async_capture_events(hass, lr.EVENT_LABEL_REGISTRY_UPDATED) label = label_registry.async_create( "mock", color="#FFFFFF", @@ -202,7 +194,7 @@ async def test_update_label_with_same_data( async def test_update_label_with_same_name_change_case( - hass: HomeAssistant, label_registry: lr.LabelRegistry + label_registry: lr.LabelRegistry, ) -> None: """Make sure that we can reapply the same name with a different case to the label.""" label = label_registry.async_create("mock") @@ -268,7 +260,7 @@ async def test_load_labels( assert len(label_registry.labels) == 2 - registry2 = LabelRegistry(hass) + registry2 = lr.LabelRegistry(hass) await flush_store(label_registry._store) await registry2.async_load() @@ -293,11 +285,11 @@ async def test_load_labels( @pytest.mark.parametrize("load_registries", [False]) async def test_loading_label_from_storage( - hass: HomeAssistant, hass_storage: Any + hass: HomeAssistant, hass_storage: dict[str, Any] ) -> None: """Test loading stored labels on start.""" - hass_storage[STORAGE_KEY] = { - "version": STORAGE_VERSION_MAJOR, + hass_storage[lr.STORAGE_KEY] = { + "version": lr.STORAGE_VERSION_MAJOR, "data": { "labels": [ { @@ -311,8 +303,8 @@ async def test_loading_label_from_storage( }, } - await async_load(hass) - registry = async_get(hass) + await lr.async_load(hass) + registry = lr.async_get(hass) assert len(registry.labels) == 1 diff --git a/tests/helpers/test_normalized_name_base_registry.py b/tests/helpers/test_normalized_name_base_registry.py index 71f5c94285a..9783e64eeff 100644 --- a/tests/helpers/test_normalized_name_base_registry.py +++ b/tests/helpers/test_normalized_name_base_registry.py @@ -10,12 +10,12 @@ from homeassistant.helpers.normalized_name_base_registry import ( @pytest.fixture -def registry_items(): +def registry_items() -> NormalizedNameBaseRegistryItems: """Fixture for registry items.""" return NormalizedNameBaseRegistryItems[NormalizedNameBaseRegistryEntry]() -def test_normalize_name(): +def test_normalize_name() -> None: """Test normalize_name.""" assert normalize_name("Hello World") == "helloworld" assert normalize_name("HELLO WORLD") == "helloworld" @@ -24,7 +24,7 @@ def test_normalize_name(): def test_registry_items( registry_items: NormalizedNameBaseRegistryItems[NormalizedNameBaseRegistryEntry], -): +) -> None: """Test registry items.""" entry = NormalizedNameBaseRegistryEntry( name="Hello World", normalized_name="helloworld" @@ -46,12 +46,12 @@ def test_registry_items( # test delete entry del registry_items["key"] assert "key" not in registry_items - assert list(registry_items.values()) == [] + assert not registry_items.values() def test_key_already_in_use( registry_items: NormalizedNameBaseRegistryItems[NormalizedNameBaseRegistryEntry], -): +) -> None: """Test key already in use.""" entry = NormalizedNameBaseRegistryEntry( name="Hello World", normalized_name="helloworld"