From 1ad8151bd1f6bb3977cecd2cb38d848e062dc665 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 20 May 2024 19:03:04 +0200 Subject: [PATCH] Use PEP 695 type alias in tests (#117797) --- .core_files.yaml | 1 + tests/components/application_credentials/test_init.py | 2 +- tests/components/crownstone/test_config_flow.py | 2 +- tests/components/dlink/conftest.py | 2 +- tests/components/dlna_dms/test_dms_device_source.py | 2 +- tests/components/electric_kiwi/conftest.py | 4 ++-- tests/components/google/conftest.py | 4 ++-- tests/components/google/test_calendar.py | 2 +- tests/components/google/test_init.py | 2 +- tests/components/google_assistant_sdk/conftest.py | 2 +- tests/components/google_mail/conftest.py | 2 +- tests/components/google_sheets/test_init.py | 2 +- tests/components/lastfm/conftest.py | 2 +- tests/components/lidarr/conftest.py | 2 +- tests/components/local_calendar/conftest.py | 4 ++-- tests/components/mqtt/test_common.py | 6 +++--- tests/components/nest/common.py | 2 +- tests/components/nest/test_climate.py | 2 +- tests/components/rainbird/test_calendar.py | 2 +- tests/components/rest_command/conftest.py | 2 +- tests/components/rtsp_to_webrtc/conftest.py | 2 +- tests/components/trend/conftest.py | 2 +- tests/components/twinkly/conftest.py | 2 +- tests/components/twinkly/test_diagnostics.py | 2 +- tests/components/twitch/conftest.py | 2 +- tests/components/vera/common.py | 2 +- tests/components/youtube/conftest.py | 2 +- tests/conftest.py | 2 +- tests/typing.py | 10 +++++----- 29 files changed, 38 insertions(+), 37 deletions(-) diff --git a/.core_files.yaml b/.core_files.yaml index f5ffdee9142..f59b84ddbf1 100644 --- a/.core_files.yaml +++ b/.core_files.yaml @@ -137,6 +137,7 @@ tests: &tests - tests/syrupy.py - tests/test_util/** - tests/testing_config/** + - tests/typing.py - tests/util/** other: &other diff --git a/tests/components/application_credentials/test_init.py b/tests/components/application_credentials/test_init.py index 523abc7fd84..f0cc79671c8 100644 --- a/tests/components/application_credentials/test_init.py +++ b/tests/components/application_credentials/test_init.py @@ -213,7 +213,7 @@ class Client: return resp.get("result") -ClientFixture = Callable[[], Client] +type ClientFixture = Callable[[], Client] @pytest.fixture diff --git a/tests/components/crownstone/test_config_flow.py b/tests/components/crownstone/test_config_flow.py index 3525d8c3f53..d8b2d805c8e 100644 --- a/tests/components/crownstone/test_config_flow.py +++ b/tests/components/crownstone/test_config_flow.py @@ -30,7 +30,7 @@ from homeassistant.data_entry_flow import FlowResultType from tests.common import MockConfigEntry -MockFixture = Generator[MagicMock | AsyncMock, None, None] +type MockFixture = Generator[MagicMock | AsyncMock, None, None] @pytest.fixture(name="crownstone_setup") diff --git a/tests/components/dlink/conftest.py b/tests/components/dlink/conftest.py index 98cf042c0a3..c57aaffc1c7 100644 --- a/tests/components/dlink/conftest.py +++ b/tests/components/dlink/conftest.py @@ -41,7 +41,7 @@ CONF_DHCP_FLOW_NEW_IP = dhcp.DhcpServiceInfo( hostname="dsp-w215", ) -ComponentSetup = Callable[[], Awaitable[None]] +type ComponentSetup = Callable[[], Awaitable[None]] def create_entry(hass: HomeAssistant, unique_id: str | None = None) -> MockConfigEntry: diff --git a/tests/components/dlna_dms/test_dms_device_source.py b/tests/components/dlna_dms/test_dms_device_source.py index bb3c9230534..23d9e6927ae 100644 --- a/tests/components/dlna_dms/test_dms_device_source.py +++ b/tests/components/dlna_dms/test_dms_device_source.py @@ -38,7 +38,7 @@ pytestmark = [ ] -BrowseResultList = list[didl_lite.DidlObject | didl_lite.Descriptor] +type BrowseResultList = list[didl_lite.DidlObject | didl_lite.Descriptor] async def async_resolve_media( diff --git a/tests/components/electric_kiwi/conftest.py b/tests/components/electric_kiwi/conftest.py index 8052ae5e129..b1e222cdc46 100644 --- a/tests/components/electric_kiwi/conftest.py +++ b/tests/components/electric_kiwi/conftest.py @@ -23,8 +23,8 @@ CLIENT_ID = "1234" 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) diff --git a/tests/components/google/conftest.py b/tests/components/google/conftest.py index 037c652f400..d69770a9b0b 100644 --- a/tests/components/google/conftest.py +++ b/tests/components/google/conftest.py @@ -27,8 +27,8 @@ from homeassistant.util import dt as dt_util 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] diff --git a/tests/components/google/test_calendar.py b/tests/components/google/test_calendar.py index f21531a823c..4f0e399bbbb 100644 --- a/tests/components/google/test_calendar.py +++ b/tests/components/google/test_calendar.py @@ -103,7 +103,7 @@ class Client: return resp.get("result") -ClientFixture = Callable[[], Awaitable[Client]] +type ClientFixture = Callable[[], Awaitable[Client]] @pytest.fixture diff --git a/tests/components/google/test_init.py b/tests/components/google/test_init.py index 2a26776b031..7b7ab90fadb 100644 --- a/tests/components/google/test_init.py +++ b/tests/components/google/test_init.py @@ -39,7 +39,7 @@ from tests.test_util.aiohttp import AiohttpClientMocker 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" diff --git a/tests/components/google_assistant_sdk/conftest.py b/tests/components/google_assistant_sdk/conftest.py index 6922b078574..742e89cab08 100644 --- a/tests/components/google_assistant_sdk/conftest.py +++ b/tests/components/google_assistant_sdk/conftest.py @@ -17,7 +17,7 @@ from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry -ComponentSetup = Callable[[], Awaitable[None]] +type ComponentSetup = Callable[[], Awaitable[None]] CLIENT_ID = "1234" CLIENT_SECRET = "5678" diff --git a/tests/components/google_mail/conftest.py b/tests/components/google_mail/conftest.py index 947d5fe2fb1..7e63282d181 100644 --- a/tests/components/google_mail/conftest.py +++ b/tests/components/google_mail/conftest.py @@ -19,7 +19,7 @@ from homeassistant.setup import async_setup_component 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" diff --git a/tests/components/google_sheets/test_init.py b/tests/components/google_sheets/test_init.py index f474e44e925..0842debc38d 100644 --- a/tests/components/google_sheets/test_init.py +++ b/tests/components/google_sheets/test_init.py @@ -25,7 +25,7 @@ from tests.test_util.aiohttp import AiohttpClientMocker TEST_SHEET_ID = "google-sheet-it" -ComponentSetup = Callable[[], Awaitable[None]] +type ComponentSetup = Callable[[], Awaitable[None]] @pytest.fixture(name="scopes") diff --git a/tests/components/lastfm/conftest.py b/tests/components/lastfm/conftest.py index 0575df2bbca..e17a1ccfa8a 100644 --- a/tests/components/lastfm/conftest.py +++ b/tests/components/lastfm/conftest.py @@ -20,7 +20,7 @@ from tests.components.lastfm import ( MockUser, ) -ComponentSetup = Callable[[MockConfigEntry, MockUser], Awaitable[None]] +type ComponentSetup = Callable[[MockConfigEntry, MockUser], Awaitable[None]] @pytest.fixture(name="config_entry") diff --git a/tests/components/lidarr/conftest.py b/tests/components/lidarr/conftest.py index 5aabc0a822b..f32d29a7827 100644 --- a/tests/components/lidarr/conftest.py +++ b/tests/components/lidarr/conftest.py @@ -32,7 +32,7 @@ MOCK_INPUT = {CONF_URL: URL, CONF_VERIFY_SSL: False} CONF_DATA = MOCK_INPUT | {CONF_API_KEY: API_KEY} -ComponentSetup = Callable[[], Awaitable[None]] +type ComponentSetup = Callable[[], Awaitable[None]] def mock_error( diff --git a/tests/components/local_calendar/conftest.py b/tests/components/local_calendar/conftest.py index 228a7783d73..9556a7c2ca5 100644 --- a/tests/components/local_calendar/conftest.py +++ b/tests/components/local_calendar/conftest.py @@ -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") @@ -169,7 +169,7 @@ class Client: return resp.get("result") -ClientFixture = Callable[[], Awaitable[Client]] +type ClientFixture = Callable[[], Awaitable[Client]] @pytest.fixture diff --git a/tests/components/mqtt/test_common.py b/tests/components/mqtt/test_common.py index 6ab9eec2425..f33eb1c850b 100644 --- a/tests/components/mqtt/test_common.py +++ b/tests/components/mqtt/test_common.py @@ -65,9 +65,9 @@ _SENTINEL = object() 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]: diff --git a/tests/components/nest/common.py b/tests/components/nest/common.py index cd13fb40344..01aac79af02 100644 --- a/tests/components/nest/common.py +++ b/tests/components/nest/common.py @@ -19,7 +19,7 @@ from homeassistant.components.application_credentials import ClientCredential 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 diff --git a/tests/components/nest/test_climate.py b/tests/components/nest/test_climate.py index a3698cf0e82..3aab77c4759 100644 --- a/tests/components/nest/test_climate.py +++ b/tests/components/nest/test_climate.py @@ -52,7 +52,7 @@ from .conftest import FakeAuth 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" diff --git a/tests/components/rainbird/test_calendar.py b/tests/components/rainbird/test_calendar.py index 1bc692e3930..860cebfa075 100644 --- a/tests/components/rainbird/test_calendar.py +++ b/tests/components/rainbird/test_calendar.py @@ -22,7 +22,7 @@ from tests.common import MockConfigEntry 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 diff --git a/tests/components/rest_command/conftest.py b/tests/components/rest_command/conftest.py index ec1cfb16ee6..68d14844ea7 100644 --- a/tests/components/rest_command/conftest.py +++ b/tests/components/rest_command/conftest.py @@ -11,7 +11,7 @@ from homeassistant.setup import async_setup_component 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 = { diff --git a/tests/components/rtsp_to_webrtc/conftest.py b/tests/components/rtsp_to_webrtc/conftest.py index 067e4580c94..f80aedb2808 100644 --- a/tests/components/rtsp_to_webrtc/conftest.py +++ b/tests/components/rtsp_to_webrtc/conftest.py @@ -23,7 +23,7 @@ SERVER_URL = "http://127.0.0.1:8083" CONFIG_ENTRY_DATA = {"server_url": SERVER_URL} # Typing helpers -ComponentSetup = Callable[[], Awaitable[None]] +type ComponentSetup = Callable[[], Awaitable[None]] type AsyncYieldFixture[_T] = AsyncGenerator[_T, None] diff --git a/tests/components/trend/conftest.py b/tests/components/trend/conftest.py index 5263b86d268..ca27094565a 100644 --- a/tests/components/trend/conftest.py +++ b/tests/components/trend/conftest.py @@ -10,7 +10,7 @@ from homeassistant.core import HomeAssistant 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") diff --git a/tests/components/twinkly/conftest.py b/tests/components/twinkly/conftest.py index 6705d570205..19361af2003 100644 --- a/tests/components/twinkly/conftest.py +++ b/tests/components/twinkly/conftest.py @@ -13,7 +13,7 @@ from . import TEST_MODEL, TEST_NAME, TEST_UID, ClientMock from tests.common import MockConfigEntry -ComponentSetup = Callable[[], Awaitable[ClientMock]] +type ComponentSetup = Callable[[], Awaitable[ClientMock]] DOMAIN = "twinkly" TITLE = "Twinkly" diff --git a/tests/components/twinkly/test_diagnostics.py b/tests/components/twinkly/test_diagnostics.py index 680f82365c0..5cb9fc1fe9e 100644 --- a/tests/components/twinkly/test_diagnostics.py +++ b/tests/components/twinkly/test_diagnostics.py @@ -11,7 +11,7 @@ from . import ClientMock 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" diff --git a/tests/components/twitch/conftest.py b/tests/components/twitch/conftest.py index 1cebc068831..e950bb16c5e 100644 --- a/tests/components/twitch/conftest.py +++ b/tests/components/twitch/conftest.py @@ -18,7 +18,7 @@ from tests.common import MockConfigEntry 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" diff --git a/tests/components/vera/common.py b/tests/components/vera/common.py index af21bf5d3a3..5e0fac6c84a 100644 --- a/tests/components/vera/common.py +++ b/tests/components/vera/common.py @@ -20,7 +20,7 @@ from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry -SetupCallback = Callable[[pv.VeraController, dict], None] +type SetupCallback = Callable[[pv.VeraController, dict], None] class ControllerData(NamedTuple): diff --git a/tests/components/youtube/conftest.py b/tests/components/youtube/conftest.py index a90dbba8aaa..0673efd42b5 100644 --- a/tests/components/youtube/conftest.py +++ b/tests/components/youtube/conftest.py @@ -19,7 +19,7 @@ from tests.common import MockConfigEntry 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" diff --git a/tests/conftest.py b/tests/conftest.py index 3bcfcfa40f6..c8309ec6b50 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1034,7 +1034,7 @@ async def _mqtt_mock_entry( 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, diff --git a/tests/typing.py b/tests/typing.py index 3938383d37f..7b61949a9c4 100644 --- a/tests/typing.py +++ b/tests/typing.py @@ -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]]