mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
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:
@@ -7,9 +7,10 @@ from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant import bootstrap, core, runner
|
||||
from homeassistant import bootstrap, runner
|
||||
import homeassistant.config as config_util
|
||||
from homeassistant.const import SIGNAL_BOOTSTRAP_INTEGRATIONS
|
||||
from homeassistant.core import HomeAssistant, async_get_hass, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
@@ -45,7 +46,7 @@ def mock_http_start_stop():
|
||||
|
||||
|
||||
@patch("homeassistant.bootstrap.async_enable_logging", Mock())
|
||||
async def test_home_assistant_core_config_validation(hass):
|
||||
async def test_home_assistant_core_config_validation(hass: HomeAssistant) -> None:
|
||||
"""Test if we pass in wrong information for HA conf."""
|
||||
# Extensive HA conf validation testing is done
|
||||
result = await bootstrap.async_from_config_dict(
|
||||
@@ -79,7 +80,7 @@ async def test_async_enable_logging(hass, caplog):
|
||||
assert "Error rolling over log file" in caplog.text
|
||||
|
||||
|
||||
async def test_load_hassio(hass):
|
||||
async def test_load_hassio(hass: HomeAssistant) -> None:
|
||||
"""Test that we load Hass.io component."""
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
assert bootstrap._get_domains(hass, {}) == set()
|
||||
@@ -89,7 +90,7 @@ async def test_load_hassio(hass):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
async def test_empty_setup(hass):
|
||||
async def test_empty_setup(hass: HomeAssistant) -> None:
|
||||
"""Test an empty set up loads the core."""
|
||||
await bootstrap.async_from_config_dict({}, hass)
|
||||
for domain in bootstrap.CORE_INTEGRATIONS:
|
||||
@@ -110,7 +111,7 @@ async def test_core_failure_loads_safe_mode(hass, caplog):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
async def test_setting_up_config(hass):
|
||||
async def test_setting_up_config(hass: HomeAssistant) -> None:
|
||||
"""Test we set up domains in config."""
|
||||
await bootstrap._async_set_up_integrations(
|
||||
hass, {"group hello": {}, "homeassistant": {}}
|
||||
@@ -120,7 +121,7 @@ async def test_setting_up_config(hass):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
async def test_setup_after_deps_all_present(hass):
|
||||
async def test_setup_after_deps_all_present(hass: HomeAssistant) -> None:
|
||||
"""Test after_dependencies when all present."""
|
||||
order = []
|
||||
|
||||
@@ -165,7 +166,7 @@ async def test_setup_after_deps_all_present(hass):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
async def test_setup_after_deps_in_stage_1_ignored(hass):
|
||||
async def test_setup_after_deps_in_stage_1_ignored(hass: HomeAssistant) -> None:
|
||||
"""Test after_dependencies are ignored in stage 1."""
|
||||
# This test relies on this
|
||||
assert "cloud" in bootstrap.STAGE_1_INTEGRATIONS
|
||||
@@ -212,7 +213,7 @@ async def test_setup_after_deps_in_stage_1_ignored(hass):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
async def test_setup_frontend_before_recorder(hass):
|
||||
async def test_setup_frontend_before_recorder(hass: HomeAssistant) -> None:
|
||||
"""Test frontend is setup before recorder."""
|
||||
order = []
|
||||
|
||||
@@ -288,7 +289,7 @@ async def test_setup_frontend_before_recorder(hass):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
async def test_setup_after_deps_via_platform(hass):
|
||||
async def test_setup_after_deps_via_platform(hass: HomeAssistant) -> None:
|
||||
"""Test after_dependencies set up via platform."""
|
||||
order = []
|
||||
after_dep_event = asyncio.Event()
|
||||
@@ -320,7 +321,7 @@ async def test_setup_after_deps_via_platform(hass):
|
||||
)
|
||||
mock_entity_platform(hass, "light.platform_int", MockPlatform())
|
||||
|
||||
@core.callback
|
||||
@callback
|
||||
def continue_loading(_):
|
||||
"""When light component loaded, continue other loading."""
|
||||
after_dep_event.set()
|
||||
@@ -338,7 +339,7 @@ async def test_setup_after_deps_via_platform(hass):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
async def test_setup_after_deps_not_trigger_load(hass):
|
||||
async def test_setup_after_deps_not_trigger_load(hass: HomeAssistant) -> None:
|
||||
"""Test after_dependencies does not trigger loading it."""
|
||||
order = []
|
||||
|
||||
@@ -377,7 +378,7 @@ async def test_setup_after_deps_not_trigger_load(hass):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
async def test_setup_after_deps_not_present(hass):
|
||||
async def test_setup_after_deps_not_present(hass: HomeAssistant) -> None:
|
||||
"""Test after_dependencies when referenced integration doesn't exist."""
|
||||
order = []
|
||||
|
||||
@@ -501,7 +502,7 @@ async def test_setup_hass(
|
||||
assert len(mock_ensure_config_exists.mock_calls) == 1
|
||||
assert len(mock_process_ha_config_upgrade.mock_calls) == 1
|
||||
|
||||
assert hass == core.async_get_hass()
|
||||
assert hass == async_get_hass()
|
||||
|
||||
|
||||
async def test_setup_hass_takes_longer_than_log_slow_startup(
|
||||
@@ -708,7 +709,9 @@ async def test_setup_safe_mode_if_no_frontend(
|
||||
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
async def test_empty_integrations_list_is_only_sent_at_the_end_of_bootstrap(hass):
|
||||
async def test_empty_integrations_list_is_only_sent_at_the_end_of_bootstrap(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test empty integrations list is only sent at the end of bootstrap."""
|
||||
order = []
|
||||
|
||||
@@ -743,7 +746,7 @@ async def test_empty_integrations_list_is_only_sent_at_the_end_of_bootstrap(hass
|
||||
|
||||
integrations = []
|
||||
|
||||
@core.callback
|
||||
@callback
|
||||
def _bootstrap_integrations(data):
|
||||
integrations.append(data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user