Add typing to tests with single hass argument (2) (#87675)
* Add typing to tests with single hass argument (2) * a few more
This commit is contained in:
parent
1bbc03d0ba
commit
c98b4e3204
50 changed files with 816 additions and 671 deletions
|
@ -69,7 +69,7 @@ def manager(hass):
|
|||
return manager
|
||||
|
||||
|
||||
async def test_call_setup_entry(hass):
|
||||
async def test_call_setup_entry(hass: HomeAssistant) -> None:
|
||||
"""Test we call <component>.setup_entry."""
|
||||
entry = MockConfigEntry(domain="comp")
|
||||
entry.add_to_hass(hass)
|
||||
|
@ -98,7 +98,7 @@ async def test_call_setup_entry(hass):
|
|||
assert entry.supports_unload
|
||||
|
||||
|
||||
async def test_call_setup_entry_without_reload_support(hass):
|
||||
async def test_call_setup_entry_without_reload_support(hass: HomeAssistant) -> None:
|
||||
"""Test we call <component>.setup_entry and the <component> does not support unloading."""
|
||||
entry = MockConfigEntry(domain="comp")
|
||||
entry.add_to_hass(hass)
|
||||
|
@ -127,7 +127,7 @@ async def test_call_setup_entry_without_reload_support(hass):
|
|||
assert not entry.supports_unload
|
||||
|
||||
|
||||
async def test_call_async_migrate_entry(hass):
|
||||
async def test_call_async_migrate_entry(hass: HomeAssistant) -> None:
|
||||
"""Test we call <component>.async_migrate_entry when version mismatch."""
|
||||
entry = MockConfigEntry(domain="comp")
|
||||
assert not entry.supports_unload
|
||||
|
@ -157,7 +157,7 @@ async def test_call_async_migrate_entry(hass):
|
|||
assert entry.supports_unload
|
||||
|
||||
|
||||
async def test_call_async_migrate_entry_failure_false(hass):
|
||||
async def test_call_async_migrate_entry_failure_false(hass: HomeAssistant) -> None:
|
||||
"""Test migration fails if returns false."""
|
||||
entry = MockConfigEntry(domain="comp")
|
||||
entry.version = 2
|
||||
|
@ -185,7 +185,7 @@ async def test_call_async_migrate_entry_failure_false(hass):
|
|||
assert not entry.supports_unload
|
||||
|
||||
|
||||
async def test_call_async_migrate_entry_failure_exception(hass):
|
||||
async def test_call_async_migrate_entry_failure_exception(hass: HomeAssistant) -> None:
|
||||
"""Test migration fails if exception raised."""
|
||||
entry = MockConfigEntry(domain="comp")
|
||||
entry.version = 2
|
||||
|
@ -213,7 +213,7 @@ async def test_call_async_migrate_entry_failure_exception(hass):
|
|||
assert not entry.supports_unload
|
||||
|
||||
|
||||
async def test_call_async_migrate_entry_failure_not_bool(hass):
|
||||
async def test_call_async_migrate_entry_failure_not_bool(hass: HomeAssistant) -> None:
|
||||
"""Test migration fails if boolean not returned."""
|
||||
entry = MockConfigEntry(domain="comp")
|
||||
entry.version = 2
|
||||
|
@ -241,7 +241,9 @@ async def test_call_async_migrate_entry_failure_not_bool(hass):
|
|||
assert not entry.supports_unload
|
||||
|
||||
|
||||
async def test_call_async_migrate_entry_failure_not_supported(hass):
|
||||
async def test_call_async_migrate_entry_failure_not_supported(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test migration fails if async_migrate_entry not implemented."""
|
||||
entry = MockConfigEntry(domain="comp")
|
||||
entry.version = 2
|
||||
|
@ -567,7 +569,7 @@ async def test_domains_gets_domains_excludes_ignore_and_disabled(manager):
|
|||
]
|
||||
|
||||
|
||||
async def test_saving_and_loading(hass):
|
||||
async def test_saving_and_loading(hass: HomeAssistant) -> None:
|
||||
"""Test that we're saving and loading correctly."""
|
||||
mock_integration(
|
||||
hass, MockModule("test", async_setup_entry=lambda *args: mock_coro(True))
|
||||
|
@ -639,7 +641,7 @@ async def test_saving_and_loading(hass):
|
|||
assert orig.pref_disable_polling == loaded.pref_disable_polling
|
||||
|
||||
|
||||
async def test_forward_entry_sets_up_component(hass):
|
||||
async def test_forward_entry_sets_up_component(hass: HomeAssistant) -> None:
|
||||
"""Test we setup the component entry is forwarded to."""
|
||||
entry = MockConfigEntry(domain="original")
|
||||
|
||||
|
@ -658,7 +660,9 @@ async def test_forward_entry_sets_up_component(hass):
|
|||
assert len(mock_forwarded_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_forward_entry_does_not_setup_entry_if_setup_fails(hass):
|
||||
async def test_forward_entry_does_not_setup_entry_if_setup_fails(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test we do not set up entry if component setup fails."""
|
||||
entry = MockConfigEntry(domain="original")
|
||||
|
||||
|
@ -676,7 +680,7 @@ async def test_forward_entry_does_not_setup_entry_if_setup_fails(hass):
|
|||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_discovery_notification(hass):
|
||||
async def test_discovery_notification(hass: HomeAssistant) -> None:
|
||||
"""Test that we create/dismiss a notification when source is discovery."""
|
||||
mock_integration(hass, MockModule("test"))
|
||||
mock_entity_platform(hass, "config_flow.test", None)
|
||||
|
@ -728,7 +732,7 @@ async def test_discovery_notification(hass):
|
|||
assert state is None
|
||||
|
||||
|
||||
async def test_reauth_notification(hass):
|
||||
async def test_reauth_notification(hass: HomeAssistant) -> None:
|
||||
"""Test that we create/dismiss a notification when source is reauth."""
|
||||
mock_integration(hass, MockModule("test"))
|
||||
mock_entity_platform(hass, "config_flow.test", None)
|
||||
|
@ -795,7 +799,7 @@ async def test_reauth_notification(hass):
|
|||
assert state is None
|
||||
|
||||
|
||||
async def test_discovery_notification_not_created(hass):
|
||||
async def test_discovery_notification_not_created(hass: HomeAssistant) -> None:
|
||||
"""Test that we not create a notification when discovery is aborted."""
|
||||
mock_integration(hass, MockModule("test"))
|
||||
mock_entity_platform(hass, "config_flow.test", None)
|
||||
|
@ -819,7 +823,7 @@ async def test_discovery_notification_not_created(hass):
|
|||
assert state is None
|
||||
|
||||
|
||||
async def test_loading_default_config(hass):
|
||||
async def test_loading_default_config(hass: HomeAssistant) -> None:
|
||||
"""Test loading the default config."""
|
||||
manager = config_entries.ConfigEntries(hass, {})
|
||||
|
||||
|
@ -938,7 +942,7 @@ async def test_setup_raise_not_ready_from_exception(hass, caplog):
|
|||
)
|
||||
|
||||
|
||||
async def test_setup_retrying_during_unload(hass):
|
||||
async def test_setup_retrying_during_unload(hass: HomeAssistant) -> None:
|
||||
"""Test if we unload an entry that is in retry mode."""
|
||||
entry = MockConfigEntry(domain="test")
|
||||
|
||||
|
@ -958,7 +962,7 @@ async def test_setup_retrying_during_unload(hass):
|
|||
assert len(mock_call.return_value.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_setup_retrying_during_unload_before_started(hass):
|
||||
async def test_setup_retrying_during_unload_before_started(hass: HomeAssistant) -> None:
|
||||
"""Test if we unload an entry that is in retry mode before started."""
|
||||
entry = MockConfigEntry(domain="test")
|
||||
hass.state = CoreState.starting
|
||||
|
@ -985,7 +989,7 @@ async def test_setup_retrying_during_unload_before_started(hass):
|
|||
)
|
||||
|
||||
|
||||
async def test_create_entry_options(hass):
|
||||
async def test_create_entry_options(hass: HomeAssistant) -> None:
|
||||
"""Test a config entry being created with options."""
|
||||
|
||||
async def mock_async_setup(hass, config):
|
||||
|
@ -1417,7 +1421,7 @@ async def test_entry_enable_without_reload_support(hass, manager):
|
|||
assert entry.state is config_entries.ConfigEntryState.FAILED_UNLOAD
|
||||
|
||||
|
||||
async def test_init_custom_integration(hass):
|
||||
async def test_init_custom_integration(hass: HomeAssistant) -> None:
|
||||
"""Test initializing flow for custom integration."""
|
||||
integration = loader.Integration(
|
||||
hass,
|
||||
|
@ -1432,13 +1436,15 @@ async def test_init_custom_integration(hass):
|
|||
await hass.config_entries.flow.async_init("bla", context={"source": "user"})
|
||||
|
||||
|
||||
async def test_support_entry_unload(hass):
|
||||
async def test_support_entry_unload(hass: HomeAssistant) -> None:
|
||||
"""Test unloading entry."""
|
||||
assert await config_entries.support_entry_unload(hass, "light")
|
||||
assert not await config_entries.support_entry_unload(hass, "auth")
|
||||
|
||||
|
||||
async def test_reload_entry_entity_registry_ignores_no_entry(hass):
|
||||
async def test_reload_entry_entity_registry_ignores_no_entry(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test reloading entry in entity registry skips if no config entry linked."""
|
||||
handler = config_entries.EntityRegistryDisabledHandler(hass)
|
||||
registry = mock_registry(hass)
|
||||
|
@ -1453,7 +1459,7 @@ async def test_reload_entry_entity_registry_ignores_no_entry(hass):
|
|||
assert handler._remove_call_later is None
|
||||
|
||||
|
||||
async def test_reload_entry_entity_registry_works(hass):
|
||||
async def test_reload_entry_entity_registry_works(hass: HomeAssistant) -> None:
|
||||
"""Test we schedule an entry to be reloaded if disabled_by is updated."""
|
||||
handler = config_entries.EntityRegistryDisabledHandler(hass)
|
||||
handler.async_setup()
|
||||
|
@ -2334,7 +2340,7 @@ async def test_partial_flows_hidden(hass, manager):
|
|||
assert state is not None
|
||||
|
||||
|
||||
async def test_async_setup_init_entry(hass):
|
||||
async def test_async_setup_init_entry(hass: HomeAssistant) -> None:
|
||||
"""Test a config entry being initialized during integration setup."""
|
||||
|
||||
async def mock_async_setup(hass, config):
|
||||
|
@ -2378,7 +2384,9 @@ async def test_async_setup_init_entry(hass):
|
|||
assert entries[0].state is config_entries.ConfigEntryState.LOADED
|
||||
|
||||
|
||||
async def test_async_setup_init_entry_completes_before_loaded_event_fires(hass):
|
||||
async def test_async_setup_init_entry_completes_before_loaded_event_fires(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test a config entry being initialized during integration setup before the loaded event fires."""
|
||||
load_events: list[Event] = []
|
||||
|
||||
|
@ -2444,7 +2452,7 @@ async def test_async_setup_init_entry_completes_before_loaded_event_fires(hass):
|
|||
listener()
|
||||
|
||||
|
||||
async def test_async_setup_update_entry(hass):
|
||||
async def test_async_setup_update_entry(hass: HomeAssistant) -> None:
|
||||
"""Test a config entry being updated during integration setup."""
|
||||
entry = MockConfigEntry(domain="comp", data={"value": "initial"})
|
||||
entry.add_to_hass(hass)
|
||||
|
@ -3090,7 +3098,7 @@ async def test_setup_raise_auth_failed_from_future_coordinator_update(hass, capl
|
|||
assert len(flows) == 1
|
||||
|
||||
|
||||
async def test_initialize_and_shutdown(hass):
|
||||
async def test_initialize_and_shutdown(hass: HomeAssistant) -> None:
|
||||
"""Test we call the shutdown function at stop."""
|
||||
manager = config_entries.ConfigEntries(hass, {})
|
||||
|
||||
|
@ -3102,7 +3110,7 @@ async def test_initialize_and_shutdown(hass):
|
|||
assert mock_async_shutdown.called
|
||||
|
||||
|
||||
async def test_setup_retrying_during_shutdown(hass):
|
||||
async def test_setup_retrying_during_shutdown(hass: HomeAssistant) -> None:
|
||||
"""Test if we shutdown an entry that is in retry mode."""
|
||||
entry = MockConfigEntry(domain="test")
|
||||
|
||||
|
@ -3376,7 +3384,7 @@ async def test_disallow_entry_reload_with_setup_in_progresss(hass, manager):
|
|||
assert entry.state is config_entries.ConfigEntryState.SETUP_IN_PROGRESS
|
||||
|
||||
|
||||
async def test_reauth(hass):
|
||||
async def test_reauth(hass: HomeAssistant) -> None:
|
||||
"""Test the async_reauth_helper."""
|
||||
entry = MockConfigEntry(title="test_title", domain="test")
|
||||
entry2 = MockConfigEntry(title="test_title", domain="test")
|
||||
|
@ -3424,7 +3432,7 @@ async def test_reauth(hass):
|
|||
assert len(hass.config_entries.flow.async_progress()) == 2
|
||||
|
||||
|
||||
async def test_get_active_flows(hass):
|
||||
async def test_get_active_flows(hass: HomeAssistant) -> None:
|
||||
"""Test the async_get_active_flows helper."""
|
||||
entry = MockConfigEntry(title="test_title", domain="test")
|
||||
mock_setup_entry = AsyncMock(return_value=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue