mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Improve YieldFixture typing (#117686)
This commit is contained in:
parent
26a599ad11
commit
3cd1717437
@ -2,11 +2,11 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable, Generator
|
||||
from collections.abc import AsyncGenerator, Awaitable, Callable, Generator
|
||||
import datetime
|
||||
import http
|
||||
import time
|
||||
from typing import Any, TypeVar
|
||||
from typing import Any
|
||||
from unittest.mock import Mock, mock_open, patch
|
||||
|
||||
from aiohttp.client_exceptions import ClientError
|
||||
@ -29,8 +29,7 @@ from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
ApiResult = Callable[[dict[str, Any]], None]
|
||||
ComponentSetup = Callable[[], Awaitable[bool]]
|
||||
_T = TypeVar("_T")
|
||||
YieldFixture = Generator[_T, None, None]
|
||||
type AsyncYieldFixture[_T] = AsyncGenerator[_T, None]
|
||||
|
||||
|
||||
CALENDAR_ID = "qwertyuiopasdfghjklzxcvbnm@import.calendar.google.com"
|
||||
|
@ -37,7 +37,7 @@ from homeassistant.helpers import config_entry_oauth2_flow
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from .conftest import CLIENT_ID, CLIENT_SECRET, EMAIL_ADDRESS, YieldFixture
|
||||
from .conftest import CLIENT_ID, CLIENT_SECRET, EMAIL_ADDRESS, AsyncYieldFixture
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
@ -70,7 +70,7 @@ async def code_expiration_delta() -> datetime.timedelta:
|
||||
@pytest.fixture
|
||||
async def mock_code_flow(
|
||||
code_expiration_delta: datetime.timedelta,
|
||||
) -> YieldFixture[Mock]:
|
||||
) -> AsyncYieldFixture[Mock]:
|
||||
"""Fixture for initiating OAuth flow."""
|
||||
with patch(
|
||||
"homeassistant.components.google.api.OAuth2WebServerFlow.step1_get_device_and_user_codes",
|
||||
@ -88,7 +88,7 @@ async def mock_code_flow(
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mock_exchange(creds: OAuth2Credentials) -> YieldFixture[Mock]:
|
||||
async def mock_exchange(creds: OAuth2Credentials) -> AsyncYieldFixture[Mock]:
|
||||
"""Fixture for mocking out the exchange for credentials."""
|
||||
with patch(
|
||||
"homeassistant.components.google.api.OAuth2WebServerFlow.step2_exchange",
|
||||
|
@ -6,7 +6,7 @@ from collections.abc import Awaitable, Callable, Generator
|
||||
import copy
|
||||
from dataclasses import dataclass, field
|
||||
import time
|
||||
from typing import Any, TypeVar
|
||||
from typing import Any
|
||||
|
||||
from google_nest_sdm.auth import AbstractAuth
|
||||
from google_nest_sdm.device import Device
|
||||
@ -20,8 +20,7 @@ from homeassistant.components.nest import DOMAIN
|
||||
|
||||
# Typing helpers
|
||||
PlatformSetup = Callable[[], Awaitable[None]]
|
||||
_T = TypeVar("_T")
|
||||
YieldFixture = Generator[_T, None, None]
|
||||
type YieldFixture[_T] = Generator[_T, None, None]
|
||||
|
||||
WEB_AUTH_DOMAIN = DOMAIN
|
||||
APP_AUTH_DOMAIN = f"{DOMAIN}.installed"
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import AsyncGenerator, Awaitable, Callable, Generator
|
||||
from typing import Any, TypeVar
|
||||
from collections.abc import AsyncGenerator, Awaitable, Callable
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@ -24,8 +24,7 @@ CONFIG_ENTRY_DATA = {"server_url": SERVER_URL}
|
||||
|
||||
# Typing helpers
|
||||
ComponentSetup = Callable[[], Awaitable[None]]
|
||||
_T = TypeVar("_T")
|
||||
YieldFixture = Generator[_T, None, None]
|
||||
type AsyncYieldFixture[_T] = AsyncGenerator[_T, None]
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@ -91,7 +90,7 @@ async def rtsp_to_webrtc_client() -> None:
|
||||
@pytest.fixture
|
||||
async def setup_integration(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> YieldFixture[ComponentSetup]:
|
||||
) -> AsyncYieldFixture[ComponentSetup]:
|
||||
"""Fixture for setting up the component."""
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user