Skip to content

Commit

Permalink
Use PEP 695 type alias in tests (home-assistant#117797)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored May 20, 2024
1 parent e8aa4b0 commit 1ad8151
Show file tree
Hide file tree
Showing 29 changed files with 38 additions and 37 deletions.
1 change: 1 addition & 0 deletions .core_files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ tests: &tests
- tests/syrupy.py
- tests/test_util/**
- tests/testing_config/**
- tests/typing.py
- tests/util/**

other: &other
Expand Down
2 changes: 1 addition & 1 deletion tests/components/application_credentials/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async def cmd_result(self, cmd: str, payload: dict[str, Any] | None = None) -> A
return resp.get("result")


ClientFixture = Callable[[], Client]
type ClientFixture = Callable[[], Client]


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/components/crownstone/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from tests.common import MockConfigEntry

MockFixture = Generator[MagicMock | AsyncMock, None, None]
type MockFixture = Generator[MagicMock | AsyncMock, None, None]


@pytest.fixture(name="crownstone_setup")
Expand Down
2 changes: 1 addition & 1 deletion tests/components/dlink/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
hostname="dsp-w215",
)

ComponentSetup = Callable[[], Awaitable[None]]
type ComponentSetup = Callable[[], Awaitable[None]]


def create_entry(hass: HomeAssistant, unique_id: str | None = None) -> MockConfigEntry:
Expand Down
2 changes: 1 addition & 1 deletion tests/components/dlna_dms/test_dms_device_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
]


BrowseResultList = list[didl_lite.DidlObject | didl_lite.Descriptor]
type BrowseResultList = list[didl_lite.DidlObject | didl_lite.Descriptor]


async def async_resolve_media(
Expand Down
4 changes: 2 additions & 2 deletions tests/components/electric_kiwi/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
CLIENT_SECRET = "5678"
REDIRECT_URI = "https://example.com/auth/external/callback"

YieldFixture = Generator[AsyncMock, None, None]
ComponentSetup = Callable[[], Awaitable[bool]]
type YieldFixture = Generator[AsyncMock, None, None]
type ComponentSetup = Callable[[], Awaitable[bool]]


@pytest.fixture(autouse=True)
Expand Down
4 changes: 2 additions & 2 deletions tests/components/google/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from tests.common import MockConfigEntry
from tests.test_util.aiohttp import AiohttpClientMocker

ApiResult = Callable[[dict[str, Any]], None]
ComponentSetup = Callable[[], Awaitable[bool]]
type ApiResult = Callable[[dict[str, Any]], None]
type ComponentSetup = Callable[[], Awaitable[bool]]
type AsyncYieldFixture[_T] = AsyncGenerator[_T, None]


Expand Down
2 changes: 1 addition & 1 deletion tests/components/google/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async def cmd_result(self, cmd: str, payload: dict[str, Any] | None = None) -> A
return resp.get("result")


ClientFixture = Callable[[], Awaitable[Client]]
type ClientFixture = Callable[[], Awaitable[Client]]


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/components/google/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
EXPIRED_TOKEN_TIMESTAMP = datetime.datetime(2022, 4, 8).timestamp()

# Typing helpers
HassApi = Callable[[], Awaitable[dict[str, Any]]]
type HassApi = Callable[[], Awaitable[dict[str, Any]]]

TEST_EVENT_SUMMARY = "Test Summary"
TEST_EVENT_DESCRIPTION = "Test Description"
Expand Down
2 changes: 1 addition & 1 deletion tests/components/google_assistant_sdk/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from tests.common import MockConfigEntry

ComponentSetup = Callable[[], Awaitable[None]]
type ComponentSetup = Callable[[], Awaitable[None]]

CLIENT_ID = "1234"
CLIENT_SECRET = "5678"
Expand Down
2 changes: 1 addition & 1 deletion tests/components/google_mail/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from tests.common import MockConfigEntry, load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker

ComponentSetup = Callable[[], Awaitable[None]]
type ComponentSetup = Callable[[], Awaitable[None]]

BUILD = "homeassistant.components.google_mail.api.build"
CLIENT_ID = "1234"
Expand Down
2 changes: 1 addition & 1 deletion tests/components/google_sheets/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

TEST_SHEET_ID = "google-sheet-it"

ComponentSetup = Callable[[], Awaitable[None]]
type ComponentSetup = Callable[[], Awaitable[None]]


@pytest.fixture(name="scopes")
Expand Down
2 changes: 1 addition & 1 deletion tests/components/lastfm/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
MockUser,
)

ComponentSetup = Callable[[MockConfigEntry, MockUser], Awaitable[None]]
type ComponentSetup = Callable[[MockConfigEntry, MockUser], Awaitable[None]]


@pytest.fixture(name="config_entry")
Expand Down
2 changes: 1 addition & 1 deletion tests/components/lidarr/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

CONF_DATA = MOCK_INPUT | {CONF_API_KEY: API_KEY}

ComponentSetup = Callable[[], Awaitable[None]]
type ComponentSetup = Callable[[], Awaitable[None]]


def mock_error(
Expand Down
4 changes: 2 additions & 2 deletions tests/components/local_calendar/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry)
await hass.async_block_till_done()


GetEventsFn = Callable[[str, str], Awaitable[list[dict[str, Any]]]]
type GetEventsFn = Callable[[str, str], Awaitable[list[dict[str, Any]]]]


@pytest.fixture(name="get_events")
Expand Down Expand Up @@ -169,7 +169,7 @@ async def cmd_result(
return resp.get("result")


ClientFixture = Callable[[], Awaitable[Client]]
type ClientFixture = Callable[[], Awaitable[Client]]


@pytest.fixture
Expand Down
6 changes: 3 additions & 3 deletions tests/components/mqtt/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@

DISCOVERY_COUNT = len(MQTT)

_MqttMessageType = list[tuple[str, str]]
_AttributesType = list[tuple[str, Any]]
_StateDataType = list[tuple[_MqttMessageType, str | None, _AttributesType | None]]
type _MqttMessageType = list[tuple[str, str]]
type _AttributesType = list[tuple[str, Any]]
type _StateDataType = list[tuple[_MqttMessageType, str | None, _AttributesType | None]]


def help_all_subscribe_calls(mqtt_client_mock: MqttMockPahoClient) -> list[Any]:
Expand Down
2 changes: 1 addition & 1 deletion tests/components/nest/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from homeassistant.components.nest import DOMAIN

# Typing helpers
PlatformSetup = Callable[[], Awaitable[None]]
type PlatformSetup = Callable[[], Awaitable[None]]
type YieldFixture[_T] = Generator[_T, None, None]

WEB_AUTH_DOMAIN = DOMAIN
Expand Down
2 changes: 1 addition & 1 deletion tests/components/nest/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

from tests.components.climate import common

CreateEvent = Callable[[dict[str, Any]], Awaitable[None]]
type CreateEvent = Callable[[dict[str, Any]], Awaitable[None]]

EVENT_ID = "some-event-id"

Expand Down
2 changes: 1 addition & 1 deletion tests/components/rainbird/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from tests.test_util.aiohttp import AiohttpClientMockResponse

TEST_ENTITY = "calendar.rain_bird_controller"
GetEventsFn = Callable[[str, str], Awaitable[dict[str, Any]]]
type GetEventsFn = Callable[[str, str], Awaitable[dict[str, Any]]]

SCHEDULE_RESPONSES = [
# Current controller status
Expand Down
2 changes: 1 addition & 1 deletion tests/components/rest_command/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from tests.common import assert_setup_component

ComponentSetup = Callable[[dict[str, Any] | None], Awaitable[None]]
type ComponentSetup = Callable[[dict[str, Any] | None], Awaitable[None]]

TEST_URL = "https://example.com/"
TEST_CONFIG = {
Expand Down
2 changes: 1 addition & 1 deletion tests/components/rtsp_to_webrtc/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
CONFIG_ENTRY_DATA = {"server_url": SERVER_URL}

# Typing helpers
ComponentSetup = Callable[[], Awaitable[None]]
type ComponentSetup = Callable[[], Awaitable[None]]
type AsyncYieldFixture[_T] = AsyncGenerator[_T, None]


Expand Down
2 changes: 1 addition & 1 deletion tests/components/trend/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from tests.common import MockConfigEntry

ComponentSetup = Callable[[dict[str, Any]], Awaitable[None]]
type ComponentSetup = Callable[[dict[str, Any]], Awaitable[None]]


@pytest.fixture(name="config_entry")
Expand Down
2 changes: 1 addition & 1 deletion tests/components/twinkly/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from tests.common import MockConfigEntry

ComponentSetup = Callable[[], Awaitable[ClientMock]]
type ComponentSetup = Callable[[], Awaitable[ClientMock]]

DOMAIN = "twinkly"
TITLE = "Twinkly"
Expand Down
2 changes: 1 addition & 1 deletion tests/components/twinkly/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator

ComponentSetup = Callable[[], Awaitable[ClientMock]]
type ComponentSetup = Callable[[], Awaitable[ClientMock]]

DOMAIN = "twinkly"

Expand Down
2 changes: 1 addition & 1 deletion tests/components/twitch/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from tests.components.twitch import TwitchMock
from tests.test_util.aiohttp import AiohttpClientMocker

ComponentSetup = Callable[[TwitchMock | None], Awaitable[None]]
type ComponentSetup = Callable[[TwitchMock | None], Awaitable[None]]

CLIENT_ID = "1234"
CLIENT_SECRET = "5678"
Expand Down
2 changes: 1 addition & 1 deletion tests/components/vera/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from tests.common import MockConfigEntry

SetupCallback = Callable[[pv.VeraController, dict], None]
type SetupCallback = Callable[[pv.VeraController, dict], None]


class ControllerData(NamedTuple):
Expand Down
2 changes: 1 addition & 1 deletion tests/components/youtube/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from tests.components.youtube import MockYouTube
from tests.test_util.aiohttp import AiohttpClientMocker

ComponentSetup = Callable[[], Awaitable[MockYouTube]]
type ComponentSetup = Callable[[], Awaitable[MockYouTube]]

CLIENT_ID = "1234"
CLIENT_SECRET = "5678"
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ def create_mock_mqtt(*args, **kwargs) -> MqttMockHAClient:
nonlocal real_mqtt_instance
real_mqtt_instance = real_mqtt(*args, **kwargs)
spec = [*dir(real_mqtt_instance), "_mqttc"]
mock_mqtt_instance = MqttMockHAClient(
mock_mqtt_instance = MagicMock(
return_value=real_mqtt_instance,
spec_set=spec,
wraps=real_mqtt_instance,
Expand Down
10 changes: 5 additions & 5 deletions tests/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class MockHAClientWebSocket(ClientWebSocketResponse):
remove_device: Callable[[str, str], Coroutine[Any, Any, Any]]


ClientSessionGenerator = Callable[..., Coroutine[Any, Any, TestClient]]
MqttMockPahoClient = MagicMock
type ClientSessionGenerator = Callable[..., Coroutine[Any, Any, TestClient]]
type MqttMockPahoClient = MagicMock
"""MagicMock for `paho.mqtt.client.Client`"""
MqttMockHAClient = MagicMock
type MqttMockHAClient = MagicMock
"""MagicMock for `homeassistant.components.mqtt.MQTT`."""
MqttMockHAClientGenerator = Callable[..., Coroutine[Any, Any, MqttMockHAClient]]
type MqttMockHAClientGenerator = Callable[..., Coroutine[Any, Any, MqttMockHAClient]]
"""MagicMock generator for `homeassistant.components.mqtt.MQTT`."""
type RecorderInstanceGenerator = Callable[..., Coroutine[Any, Any, Recorder]]
"""Instance generator for `homeassistant.components.recorder.Recorder`."""
WebSocketGenerator = Callable[..., Coroutine[Any, Any, MockHAClientWebSocket]]
type WebSocketGenerator = Callable[..., Coroutine[Any, Any, MockHAClientWebSocket]]

0 comments on commit 1ad8151

Please sign in to comment.