Use PEP 695 type alias in tests (#117797)

This commit is contained in:
Marc Mueller 2024-05-20 19:03:04 +02:00 committed by GitHub
parent e8aa4b069a
commit 1ad8151bd1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 38 additions and 37 deletions

View file

@ -137,6 +137,7 @@ tests: &tests
- tests/syrupy.py - tests/syrupy.py
- tests/test_util/** - tests/test_util/**
- tests/testing_config/** - tests/testing_config/**
- tests/typing.py
- tests/util/** - tests/util/**
other: &other other: &other

View file

@ -213,7 +213,7 @@ class Client:
return resp.get("result") return resp.get("result")
ClientFixture = Callable[[], Client] type ClientFixture = Callable[[], Client]
@pytest.fixture @pytest.fixture

View file

@ -30,7 +30,7 @@ from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
MockFixture = Generator[MagicMock | AsyncMock, None, None] type MockFixture = Generator[MagicMock | AsyncMock, None, None]
@pytest.fixture(name="crownstone_setup") @pytest.fixture(name="crownstone_setup")

View file

@ -41,7 +41,7 @@ CONF_DHCP_FLOW_NEW_IP = dhcp.DhcpServiceInfo(
hostname="dsp-w215", hostname="dsp-w215",
) )
ComponentSetup = Callable[[], Awaitable[None]] type ComponentSetup = Callable[[], Awaitable[None]]
def create_entry(hass: HomeAssistant, unique_id: str | None = None) -> MockConfigEntry: def create_entry(hass: HomeAssistant, unique_id: str | None = None) -> MockConfigEntry:

View file

@ -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( async def async_resolve_media(

View file

@ -23,8 +23,8 @@ CLIENT_ID = "1234"
CLIENT_SECRET = "5678" CLIENT_SECRET = "5678"
REDIRECT_URI = "https://example.com/auth/external/callback" REDIRECT_URI = "https://example.com/auth/external/callback"
YieldFixture = Generator[AsyncMock, None, None] type YieldFixture = Generator[AsyncMock, None, None]
ComponentSetup = Callable[[], Awaitable[bool]] type ComponentSetup = Callable[[], Awaitable[bool]]
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)

View file

@ -27,8 +27,8 @@ from homeassistant.util import dt as dt_util
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
ApiResult = Callable[[dict[str, Any]], None] type ApiResult = Callable[[dict[str, Any]], None]
ComponentSetup = Callable[[], Awaitable[bool]] type ComponentSetup = Callable[[], Awaitable[bool]]
type AsyncYieldFixture[_T] = AsyncGenerator[_T, None] type AsyncYieldFixture[_T] = AsyncGenerator[_T, None]

View file

@ -103,7 +103,7 @@ class Client:
return resp.get("result") return resp.get("result")
ClientFixture = Callable[[], Awaitable[Client]] type ClientFixture = Callable[[], Awaitable[Client]]
@pytest.fixture @pytest.fixture

View file

@ -39,7 +39,7 @@ from tests.test_util.aiohttp import AiohttpClientMocker
EXPIRED_TOKEN_TIMESTAMP = datetime.datetime(2022, 4, 8).timestamp() EXPIRED_TOKEN_TIMESTAMP = datetime.datetime(2022, 4, 8).timestamp()
# Typing helpers # Typing helpers
HassApi = Callable[[], Awaitable[dict[str, Any]]] type HassApi = Callable[[], Awaitable[dict[str, Any]]]
TEST_EVENT_SUMMARY = "Test Summary" TEST_EVENT_SUMMARY = "Test Summary"
TEST_EVENT_DESCRIPTION = "Test Description" TEST_EVENT_DESCRIPTION = "Test Description"

View file

@ -17,7 +17,7 @@ from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
ComponentSetup = Callable[[], Awaitable[None]] type ComponentSetup = Callable[[], Awaitable[None]]
CLIENT_ID = "1234" CLIENT_ID = "1234"
CLIENT_SECRET = "5678" CLIENT_SECRET = "5678"

View file

@ -19,7 +19,7 @@ from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry, load_fixture from tests.common import MockConfigEntry, load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
ComponentSetup = Callable[[], Awaitable[None]] type ComponentSetup = Callable[[], Awaitable[None]]
BUILD = "homeassistant.components.google_mail.api.build" BUILD = "homeassistant.components.google_mail.api.build"
CLIENT_ID = "1234" CLIENT_ID = "1234"

View file

@ -25,7 +25,7 @@ from tests.test_util.aiohttp import AiohttpClientMocker
TEST_SHEET_ID = "google-sheet-it" TEST_SHEET_ID = "google-sheet-it"
ComponentSetup = Callable[[], Awaitable[None]] type ComponentSetup = Callable[[], Awaitable[None]]
@pytest.fixture(name="scopes") @pytest.fixture(name="scopes")

View file

@ -20,7 +20,7 @@ from tests.components.lastfm import (
MockUser, MockUser,
) )
ComponentSetup = Callable[[MockConfigEntry, MockUser], Awaitable[None]] type ComponentSetup = Callable[[MockConfigEntry, MockUser], Awaitable[None]]
@pytest.fixture(name="config_entry") @pytest.fixture(name="config_entry")

View file

@ -32,7 +32,7 @@ MOCK_INPUT = {CONF_URL: URL, CONF_VERIFY_SSL: False}
CONF_DATA = MOCK_INPUT | {CONF_API_KEY: API_KEY} CONF_DATA = MOCK_INPUT | {CONF_API_KEY: API_KEY}
ComponentSetup = Callable[[], Awaitable[None]] type ComponentSetup = Callable[[], Awaitable[None]]
def mock_error( def mock_error(

View file

@ -108,7 +108,7 @@ async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry)
await hass.async_block_till_done() 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") @pytest.fixture(name="get_events")
@ -169,7 +169,7 @@ class Client:
return resp.get("result") return resp.get("result")
ClientFixture = Callable[[], Awaitable[Client]] type ClientFixture = Callable[[], Awaitable[Client]]
@pytest.fixture @pytest.fixture

View file

@ -65,9 +65,9 @@ _SENTINEL = object()
DISCOVERY_COUNT = len(MQTT) DISCOVERY_COUNT = len(MQTT)
_MqttMessageType = list[tuple[str, str]] type _MqttMessageType = list[tuple[str, str]]
_AttributesType = list[tuple[str, Any]] type _AttributesType = list[tuple[str, Any]]
_StateDataType = list[tuple[_MqttMessageType, str | None, _AttributesType | None]] type _StateDataType = list[tuple[_MqttMessageType, str | None, _AttributesType | None]]
def help_all_subscribe_calls(mqtt_client_mock: MqttMockPahoClient) -> list[Any]: def help_all_subscribe_calls(mqtt_client_mock: MqttMockPahoClient) -> list[Any]:

View file

@ -19,7 +19,7 @@ from homeassistant.components.application_credentials import ClientCredential
from homeassistant.components.nest import DOMAIN from homeassistant.components.nest import DOMAIN
# Typing helpers # Typing helpers
PlatformSetup = Callable[[], Awaitable[None]] type PlatformSetup = Callable[[], Awaitable[None]]
type YieldFixture[_T] = Generator[_T, None, None] type YieldFixture[_T] = Generator[_T, None, None]
WEB_AUTH_DOMAIN = DOMAIN WEB_AUTH_DOMAIN = DOMAIN

View file

@ -52,7 +52,7 @@ from .conftest import FakeAuth
from tests.components.climate import common 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" EVENT_ID = "some-event-id"

View file

@ -22,7 +22,7 @@ from tests.common import MockConfigEntry
from tests.test_util.aiohttp import AiohttpClientMockResponse from tests.test_util.aiohttp import AiohttpClientMockResponse
TEST_ENTITY = "calendar.rain_bird_controller" 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 = [ SCHEDULE_RESPONSES = [
# Current controller status # Current controller status

View file

@ -11,7 +11,7 @@ from homeassistant.setup import async_setup_component
from tests.common import assert_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_URL = "https://example.com/"
TEST_CONFIG = { TEST_CONFIG = {

View file

@ -23,7 +23,7 @@ SERVER_URL = "http://127.0.0.1:8083"
CONFIG_ENTRY_DATA = {"server_url": SERVER_URL} CONFIG_ENTRY_DATA = {"server_url": SERVER_URL}
# Typing helpers # Typing helpers
ComponentSetup = Callable[[], Awaitable[None]] type ComponentSetup = Callable[[], Awaitable[None]]
type AsyncYieldFixture[_T] = AsyncGenerator[_T, None] type AsyncYieldFixture[_T] = AsyncGenerator[_T, None]

View file

@ -10,7 +10,7 @@ from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry 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") @pytest.fixture(name="config_entry")

View file

@ -13,7 +13,7 @@ from . import TEST_MODEL, TEST_NAME, TEST_UID, ClientMock
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
ComponentSetup = Callable[[], Awaitable[ClientMock]] type ComponentSetup = Callable[[], Awaitable[ClientMock]]
DOMAIN = "twinkly" DOMAIN = "twinkly"
TITLE = "Twinkly" TITLE = "Twinkly"

View file

@ -11,7 +11,7 @@ from . import ClientMock
from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator from tests.typing import ClientSessionGenerator
ComponentSetup = Callable[[], Awaitable[ClientMock]] type ComponentSetup = Callable[[], Awaitable[ClientMock]]
DOMAIN = "twinkly" DOMAIN = "twinkly"

View file

@ -18,7 +18,7 @@ from tests.common import MockConfigEntry
from tests.components.twitch import TwitchMock from tests.components.twitch import TwitchMock
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
ComponentSetup = Callable[[TwitchMock | None], Awaitable[None]] type ComponentSetup = Callable[[TwitchMock | None], Awaitable[None]]
CLIENT_ID = "1234" CLIENT_ID = "1234"
CLIENT_SECRET = "5678" CLIENT_SECRET = "5678"

View file

@ -20,7 +20,7 @@ from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
SetupCallback = Callable[[pv.VeraController, dict], None] type SetupCallback = Callable[[pv.VeraController, dict], None]
class ControllerData(NamedTuple): class ControllerData(NamedTuple):

View file

@ -19,7 +19,7 @@ from tests.common import MockConfigEntry
from tests.components.youtube import MockYouTube from tests.components.youtube import MockYouTube
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
ComponentSetup = Callable[[], Awaitable[MockYouTube]] type ComponentSetup = Callable[[], Awaitable[MockYouTube]]
CLIENT_ID = "1234" CLIENT_ID = "1234"
CLIENT_SECRET = "5678" CLIENT_SECRET = "5678"

View file

@ -1034,7 +1034,7 @@ async def _mqtt_mock_entry(
nonlocal real_mqtt_instance nonlocal real_mqtt_instance
real_mqtt_instance = real_mqtt(*args, **kwargs) real_mqtt_instance = real_mqtt(*args, **kwargs)
spec = [*dir(real_mqtt_instance), "_mqttc"] spec = [*dir(real_mqtt_instance), "_mqttc"]
mock_mqtt_instance = MqttMockHAClient( mock_mqtt_instance = MagicMock(
return_value=real_mqtt_instance, return_value=real_mqtt_instance,
spec_set=spec, spec_set=spec,
wraps=real_mqtt_instance, wraps=real_mqtt_instance,

View file

@ -23,13 +23,13 @@ class MockHAClientWebSocket(ClientWebSocketResponse):
remove_device: Callable[[str, str], Coroutine[Any, Any, Any]] remove_device: Callable[[str, str], Coroutine[Any, Any, Any]]
ClientSessionGenerator = Callable[..., Coroutine[Any, Any, TestClient]] type ClientSessionGenerator = Callable[..., Coroutine[Any, Any, TestClient]]
MqttMockPahoClient = MagicMock type MqttMockPahoClient = MagicMock
"""MagicMock for `paho.mqtt.client.Client`""" """MagicMock for `paho.mqtt.client.Client`"""
MqttMockHAClient = MagicMock type MqttMockHAClient = MagicMock
"""MagicMock for `homeassistant.components.mqtt.MQTT`.""" """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`.""" """MagicMock generator for `homeassistant.components.mqtt.MQTT`."""
type RecorderInstanceGenerator = Callable[..., Coroutine[Any, Any, Recorder]] type RecorderInstanceGenerator = Callable[..., Coroutine[Any, Any, Recorder]]
"""Instance generator for `homeassistant.components.recorder.Recorder`.""" """Instance generator for `homeassistant.components.recorder.Recorder`."""
WebSocketGenerator = Callable[..., Coroutine[Any, Any, MockHAClientWebSocket]] type WebSocketGenerator = Callable[..., Coroutine[Any, Any, MockHAClientWebSocket]]