Use PEP 695 type alias in tests (#117797)

pull/117808/head^2
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/test_util/**
- tests/testing_config/**
- tests/typing.py
- tests/util/**
other: &other

View File

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

View File

@ -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")

View File

@ -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:

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(

View File

@ -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)

View File

@ -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]

View File

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

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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")

View File

@ -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")

View File

@ -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(

View File

@ -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

View File

@ -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]:

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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 = {

View File

@ -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]

View File

@ -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")

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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):

View File

@ -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"

View File

@ -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,

View File

@ -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]]