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 f5ffdee9142503..f59b84ddbf1c3a 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 523abc7fd845cb..f0cc79671c8c86 100644 --- a/tests/components/application_credentials/test_init.py +++ b/tests/components/application_credentials/test_init.py @@ -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 diff --git a/tests/components/crownstone/test_config_flow.py b/tests/components/crownstone/test_config_flow.py index 3525d8c3f53cff..d8b2d805c8e50b 100644 --- a/tests/components/crownstone/test_config_flow.py +++ b/tests/components/crownstone/test_config_flow.py @@ -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") diff --git a/tests/components/dlink/conftest.py b/tests/components/dlink/conftest.py index 98cf042c0a339f..c57aaffc1c7477 100644 --- a/tests/components/dlink/conftest.py +++ b/tests/components/dlink/conftest.py @@ -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: diff --git a/tests/components/dlna_dms/test_dms_device_source.py b/tests/components/dlna_dms/test_dms_device_source.py index bb3c923053403a..23d9e6927ae97f 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 @@ ] -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 8052ae5e129f25..b1e222cdc46046 100644 --- a/tests/components/electric_kiwi/conftest.py +++ b/tests/components/electric_kiwi/conftest.py @@ -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) diff --git a/tests/components/google/conftest.py b/tests/components/google/conftest.py index 037c652f4006c6..d69770a9b0b2b5 100644 --- a/tests/components/google/conftest.py +++ b/tests/components/google/conftest.py @@ -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] diff --git a/tests/components/google/test_calendar.py b/tests/components/google/test_calendar.py index f21531a823c219..4f0e399bbbb6ba 100644 --- a/tests/components/google/test_calendar.py +++ b/tests/components/google/test_calendar.py @@ -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 diff --git a/tests/components/google/test_init.py b/tests/components/google/test_init.py index 2a26776b031e9a..7b7ab90fadbc6c 100644 --- a/tests/components/google/test_init.py +++ b/tests/components/google/test_init.py @@ -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" diff --git a/tests/components/google_assistant_sdk/conftest.py b/tests/components/google_assistant_sdk/conftest.py index 6922b07857402c..742e89cab0873c 100644 --- a/tests/components/google_assistant_sdk/conftest.py +++ b/tests/components/google_assistant_sdk/conftest.py @@ -17,7 +17,7 @@ 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 947d5fe2fb1f8a..7e63282d181379 100644 --- a/tests/components/google_mail/conftest.py +++ b/tests/components/google_mail/conftest.py @@ -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" diff --git a/tests/components/google_sheets/test_init.py b/tests/components/google_sheets/test_init.py index f474e44e925b51..0842debc38da35 100644 --- a/tests/components/google_sheets/test_init.py +++ b/tests/components/google_sheets/test_init.py @@ -25,7 +25,7 @@ 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 0575df2bbca21d..e17a1ccfa8ab93 100644 --- a/tests/components/lastfm/conftest.py +++ b/tests/components/lastfm/conftest.py @@ -20,7 +20,7 @@ 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 5aabc0a822b6cb..f32d29a7827476 100644 --- a/tests/components/lidarr/conftest.py +++ b/tests/components/lidarr/conftest.py @@ -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( diff --git a/tests/components/local_calendar/conftest.py b/tests/components/local_calendar/conftest.py index 228a7783d730be..9556a7c2ca5aff 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 @@ async def cmd_result( 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 6ab9eec24250ad..f33eb1c850b742 100644 --- a/tests/components/mqtt/test_common.py +++ b/tests/components/mqtt/test_common.py @@ -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]: diff --git a/tests/components/nest/common.py b/tests/components/nest/common.py index cd13fb40344804..01aac79af020d3 100644 --- a/tests/components/nest/common.py +++ b/tests/components/nest/common.py @@ -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 diff --git a/tests/components/nest/test_climate.py b/tests/components/nest/test_climate.py index a3698cf0e824f6..3aab77c4759d97 100644 --- a/tests/components/nest/test_climate.py +++ b/tests/components/nest/test_climate.py @@ -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" diff --git a/tests/components/rainbird/test_calendar.py b/tests/components/rainbird/test_calendar.py index 1bc692e3930474..860cebfa075cd6 100644 --- a/tests/components/rainbird/test_calendar.py +++ b/tests/components/rainbird/test_calendar.py @@ -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 diff --git a/tests/components/rest_command/conftest.py b/tests/components/rest_command/conftest.py index ec1cfb16ee64b4..68d14844ea709d 100644 --- a/tests/components/rest_command/conftest.py +++ b/tests/components/rest_command/conftest.py @@ -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 = { diff --git a/tests/components/rtsp_to_webrtc/conftest.py b/tests/components/rtsp_to_webrtc/conftest.py index 067e4580c947a0..f80aedb28086fd 100644 --- a/tests/components/rtsp_to_webrtc/conftest.py +++ b/tests/components/rtsp_to_webrtc/conftest.py @@ -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] diff --git a/tests/components/trend/conftest.py b/tests/components/trend/conftest.py index 5263b86d268cae..ca27094565abb3 100644 --- a/tests/components/trend/conftest.py +++ b/tests/components/trend/conftest.py @@ -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") diff --git a/tests/components/twinkly/conftest.py b/tests/components/twinkly/conftest.py index 6705d570205011..19361af2003e04 100644 --- a/tests/components/twinkly/conftest.py +++ b/tests/components/twinkly/conftest.py @@ -13,7 +13,7 @@ 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 680f82365c0446..5cb9fc1fe9ea1c 100644 --- a/tests/components/twinkly/test_diagnostics.py +++ b/tests/components/twinkly/test_diagnostics.py @@ -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" diff --git a/tests/components/twitch/conftest.py b/tests/components/twitch/conftest.py index 1cebc0688318a7..e950bb16c5e742 100644 --- a/tests/components/twitch/conftest.py +++ b/tests/components/twitch/conftest.py @@ -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" diff --git a/tests/components/vera/common.py b/tests/components/vera/common.py index af21bf5d3a3bd9..5e0fac6c84a3dc 100644 --- a/tests/components/vera/common.py +++ b/tests/components/vera/common.py @@ -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): diff --git a/tests/components/youtube/conftest.py b/tests/components/youtube/conftest.py index a90dbba8aaa308..0673efd42b5d20 100644 --- a/tests/components/youtube/conftest.py +++ b/tests/components/youtube/conftest.py @@ -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" diff --git a/tests/conftest.py b/tests/conftest.py index 3bcfcfa40f62ef..c8309ec6b500d7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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, diff --git a/tests/typing.py b/tests/typing.py index 3938383d37f4e9..7b61949a9c4aae 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]]