Improve type hints in tests (q-z) (#118381)

This commit is contained in:
epenet 2024-05-30 08:48:02 +02:00 committed by GitHub
parent 242ee04642
commit 1317837986
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 74 additions and 40 deletions

View file

@ -1262,7 +1262,7 @@ async def test_auto_purge_disabled(
async def test_auto_statistics(
hass: HomeAssistant,
setup_recorder: None,
freezer,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test periodic statistics scheduling."""
timezone = "Europe/Copenhagen"

View file

@ -721,7 +721,7 @@ async def test_no_issue_for_mariadb_with_MDEV_25020(
async def test_basic_sanity_check(
hass: HomeAssistant, setup_recorder: None, recorder_db_url
hass: HomeAssistant, setup_recorder: None, recorder_db_url: str
) -> None:
"""Test the basic sanity checks with a missing table."""
if recorder_db_url.startswith(("mysql://", "postgresql://")):
@ -742,7 +742,7 @@ async def test_combined_checks(
hass: HomeAssistant,
setup_recorder: None,
caplog: pytest.LogCaptureFixture,
recorder_db_url,
recorder_db_url: str,
) -> None:
"""Run Checks on the open database."""
if recorder_db_url.startswith(("mysql://", "postgresql://")):
@ -831,7 +831,7 @@ async def test_end_incomplete_runs(
async def test_periodic_db_cleanups(
hass: HomeAssistant, setup_recorder: None, recorder_db_url
hass: HomeAssistant, setup_recorder: None, recorder_db_url: str
) -> None:
"""Test periodic db cleanups."""
if recorder_db_url.startswith(("mysql://", "postgresql://")):

View file

@ -432,7 +432,9 @@ async def test_step_unauth(
@pytest.mark.freeze_time("2022-07-19 07:53:05")
async def test_list_issues(
hass: HomeAssistant, hass_storage: dict[str, Any], hass_ws_client
hass: HomeAssistant,
hass_storage: dict[str, Any],
hass_ws_client: WebSocketGenerator,
) -> None:
"""Test we can list issues."""
@ -581,7 +583,9 @@ async def test_fix_issue_aborted(
@pytest.mark.freeze_time("2022-07-19 07:53:05")
async def test_get_issue_data(hass: HomeAssistant, hass_ws_client) -> None:
async def test_get_issue_data(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test we can get issue data."""
assert await async_setup_component(hass, DOMAIN, {})

View file

@ -6,6 +6,7 @@ from collections.abc import Callable, Coroutine
from typing import Any
from unittest.mock import patch
from freezegun.api import FrozenDateTimeFactory
import pytest
from homeassistant.components.schedule import STORAGE_VERSION, STORAGE_VERSION_MINOR
@ -181,7 +182,7 @@ async def test_events_one_day(
hass: HomeAssistant,
schedule_setup: Callable[..., Coroutine[Any, Any, bool]],
caplog: pytest.LogCaptureFixture,
freezer,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test events only during one day of the week."""
freezer.move_to("2022-08-30 13:20:00-07:00")
@ -225,7 +226,7 @@ async def test_adjacent_cross_midnight(
hass: HomeAssistant,
schedule_setup: Callable[..., Coroutine[Any, Any, bool]],
caplog: pytest.LogCaptureFixture,
freezer,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test adjacent events don't toggle on->off->on."""
freezer.move_to("2022-08-30 13:20:00-07:00")
@ -286,7 +287,7 @@ async def test_adjacent_within_day(
hass: HomeAssistant,
schedule_setup: Callable[..., Coroutine[Any, Any, bool]],
caplog: pytest.LogCaptureFixture,
freezer,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test adjacent events don't toggle on->off->on."""
freezer.move_to("2022-08-30 13:20:00-07:00")
@ -349,7 +350,7 @@ async def test_non_adjacent_within_day(
hass: HomeAssistant,
schedule_setup: Callable[..., Coroutine[Any, Any, bool]],
caplog: pytest.LogCaptureFixture,
freezer,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test adjacent events don't toggle on->off->on."""
freezer.move_to("2022-08-30 13:20:00-07:00")
@ -429,7 +430,7 @@ async def test_to_midnight(
schedule_setup: Callable[..., Coroutine[Any, Any, bool]],
caplog: pytest.LogCaptureFixture,
schedule: list[dict[str, str]],
freezer,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test time range allow to 24:00."""
freezer.move_to("2022-08-30 13:20:00-07:00")
@ -516,7 +517,7 @@ async def test_load(
async def test_schedule_updates(
hass: HomeAssistant,
schedule_setup: Callable[..., Coroutine[Any, Any, bool]],
freezer,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the schedule updates when time changes."""
freezer.move_to("2022-08-10 20:10:00-07:00")
@ -678,7 +679,7 @@ async def test_ws_create(
hass_ws_client: WebSocketGenerator,
entity_registry: er.EntityRegistry,
schedule_setup: Callable[..., Coroutine[Any, Any, bool]],
freezer,
freezer: FrozenDateTimeFactory,
to: str,
next_event: str,
saved_to: str,

View file

@ -1,5 +1,7 @@
"""Tests for the tag component."""
from typing import Any
from freezegun.api import FrozenDateTimeFactory
import pytest
@ -18,7 +20,7 @@ from tests.typing import WebSocketGenerator
@pytest.fixture
def storage_setup_named_tag(
hass: HomeAssistant,
hass_storage,
hass_storage: dict[str, Any],
):
"""Storage setup for test case of named tags."""
@ -76,7 +78,7 @@ async def test_named_tag_scanned_event(
@pytest.fixture
def storage_setup_unnamed_tag(hass: HomeAssistant, hass_storage):
def storage_setup_unnamed_tag(hass: HomeAssistant, hass_storage: dict[str, Any]):
"""Storage setup for test case of unnamed tags."""
async def _storage(items=None):

View file

@ -1,6 +1,7 @@
"""Tests for the tag component."""
import logging
from typing import Any
from freezegun.api import FrozenDateTimeFactory
import pytest
@ -20,7 +21,7 @@ from tests.typing import WebSocketGenerator
@pytest.fixture
def storage_setup(hass: HomeAssistant, hass_storage):
def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
"""Storage setup."""
async def _storage(items=None):

View file

@ -1,5 +1,7 @@
"""Tests for tag triggers."""
from typing import Any
import pytest
from homeassistant.components import automation
@ -18,7 +20,7 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None:
@pytest.fixture
def tag_setup(hass: HomeAssistant, hass_storage):
def tag_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
"""Tag setup."""
async def _storage(items=None):

View file

@ -2,6 +2,7 @@
from datetime import timedelta
import logging
from typing import Any
from unittest.mock import patch
import pytest
@ -59,7 +60,7 @@ _LOGGER = logging.getLogger(__name__)
@pytest.fixture
def storage_setup(hass: HomeAssistant, hass_storage):
def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
"""Storage setup."""
async def _storage(items=None, config=None):

View file

@ -658,7 +658,9 @@ async def test_dst1(
assert state.state == STATE_OFF
async def test_dst2(hass, freezer, hass_tz_info):
async def test_dst2(
hass: HomeAssistant, freezer: FrozenDateTimeFactory, hass_tz_info
) -> None:
"""Test DST when there's a time switch in the East."""
hass.config.time_zone = "CET"
dt_util.set_default_time_zone(dt_util.get_time_zone("CET"))
@ -684,7 +686,9 @@ async def test_dst2(hass, freezer, hass_tz_info):
assert state.state == STATE_OFF
async def test_dst3(hass, freezer, hass_tz_info):
async def test_dst3(
hass: HomeAssistant, freezer: FrozenDateTimeFactory, hass_tz_info
) -> None:
"""Test DST when there's a time switch forward in the West."""
hass.config.time_zone = "US/Pacific"
dt_util.set_default_time_zone(dt_util.get_time_zone("US/Pacific"))
@ -712,7 +716,9 @@ async def test_dst3(hass, freezer, hass_tz_info):
assert state.state == STATE_OFF
async def test_dst4(hass, freezer, hass_tz_info):
async def test_dst4(
hass: HomeAssistant, freezer: FrozenDateTimeFactory, hass_tz_info
) -> None:
"""Test DST when there's a time switch backward in the West."""
hass.config.time_zone = "US/Pacific"
dt_util.set_default_time_zone(dt_util.get_time_zone("US/Pacific"))

View file

@ -122,7 +122,7 @@ async def _assert_contexts(client, next_id, contexts, domain=None, item_id=None)
async def test_get_trace(
hass: HomeAssistant,
hass_storage: dict[str, Any],
hass_ws_client,
hass_ws_client: WebSocketGenerator,
domain,
prefix,
extra_trace_keys,
@ -425,7 +425,10 @@ async def test_get_trace(
@pytest.mark.parametrize("domain", ["automation", "script"])
async def test_restore_traces(
hass: HomeAssistant, hass_storage: dict[str, Any], hass_ws_client, domain
hass: HomeAssistant,
hass_storage: dict[str, Any],
hass_ws_client: WebSocketGenerator,
domain: str,
) -> None:
"""Test restored traces."""
hass.set_state(CoreState.not_running)
@ -595,9 +598,9 @@ async def test_trace_overflow(
async def test_restore_traces_overflow(
hass: HomeAssistant,
hass_storage: dict[str, Any],
hass_ws_client,
domain,
num_restored_moon_traces,
hass_ws_client: WebSocketGenerator,
domain: str,
num_restored_moon_traces: int,
) -> None:
"""Test restored traces are evicted first."""
hass.set_state(CoreState.not_running)
@ -675,10 +678,10 @@ async def test_restore_traces_overflow(
async def test_restore_traces_late_overflow(
hass: HomeAssistant,
hass_storage: dict[str, Any],
hass_ws_client,
domain,
num_restored_moon_traces,
restored_run_id,
hass_ws_client: WebSocketGenerator,
domain: str,
num_restored_moon_traces: int,
restored_run_id: str,
) -> None:
"""Test restored traces are evicted first."""
hass.set_state(CoreState.not_running)

View file

@ -23,8 +23,11 @@ from tests.typing import WebSocketGenerator
async def test_deprecated_entity(
hass: HomeAssistant, ufp: MockUFPFixture, hass_ws_client, doorbell: Camera
):
hass: HomeAssistant,
ufp: MockUFPFixture,
hass_ws_client: WebSocketGenerator,
doorbell: Camera,
) -> None:
"""Test Deprecate entity repair does not exist by default (new installs)."""
await init_entry(hass, ufp, [doorbell])
@ -47,9 +50,9 @@ async def test_deprecated_entity_no_automations(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
ufp: MockUFPFixture,
hass_ws_client,
hass_ws_client: WebSocketGenerator,
doorbell: Camera,
):
) -> None:
"""Test Deprecate entity repair exists for existing installs."""
entity_registry.async_get_or_create(
Platform.SWITCH,

View file

@ -110,7 +110,9 @@ async def test_options(hass: HomeAssistant) -> None:
)
async def test_already_configured(hass: HomeAssistant, requests_mock) -> None:
async def test_already_configured(
hass: HomeAssistant, requests_mock: requests_mock.Mocker
) -> None:
"""Test duplicate entry aborts and updates data."""
config_entry = MockConfigEntry(

View file

@ -519,7 +519,7 @@ def network_backup() -> zigpy.backups.NetworkBackup:
@pytest.fixture
def core_rs(hass_storage):
def core_rs(hass_storage: dict[str, Any]):
"""Core.restore_state fixture."""
def _storage(entity_id, state, attributes={}):

View file

@ -1,5 +1,6 @@
"""Test ZHA select entities."""
from typing import Any
from unittest.mock import call, patch
import pytest
@ -90,7 +91,7 @@ async def light(hass, zigpy_device_mock):
@pytest.fixture
def core_rs(hass_storage):
def core_rs(hass_storage: dict[str, Any]):
"""Core.restore_state fixture."""
def _storage(entity_id, state):

View file

@ -2,6 +2,7 @@
from datetime import timedelta
import math
from typing import Any
from unittest.mock import MagicMock, patch
import pytest
@ -646,7 +647,7 @@ def hass_ms(hass: HomeAssistant):
@pytest.fixture
def core_rs(hass_storage):
def core_rs(hass_storage: dict[str, Any]):
"""Core.restore_state fixture."""
def _storage(entity_id, uom, state):

View file

@ -64,6 +64,7 @@ from .conftest import (
from .data import BASE_CUSTOM_CONFIGURATION, CONFIG_WITH_ALARM_OPTIONS
from tests.common import MockConfigEntry, MockUser
from tests.typing import MockHAClientWebSocket, WebSocketGenerator
IEEE_SWITCH_DEVICE = "01:2d:6f:00:0a:90:69:e7"
IEEE_GROUPABLE_DEVICE = "01:2d:6f:00:0a:90:69:e8"
@ -151,7 +152,12 @@ async def device_groupable(hass, zigpy_device_mock, zha_device_joined):
@pytest.fixture
async def zha_client(hass, hass_ws_client, device_switch, device_groupable):
async def zha_client(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_switch,
device_groupable,
) -> MockHAClientWebSocket:
"""Get ZHA WebSocket client."""
# load the ZHA API

View file

@ -1,5 +1,6 @@
"""Test zone component."""
from typing import Any
from unittest.mock import patch
import pytest
@ -24,7 +25,7 @@ from tests.typing import WebSocketGenerator
@pytest.fixture
def storage_setup(hass, hass_storage):
def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
"""Storage setup."""
async def _storage(items=None, config=None):