Improve YieldFixture typing (#117686)
This commit is contained in:
parent
26a599ad11
commit
3cd1717437
4 changed files with 12 additions and 15 deletions
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Awaitable, Callable, Generator
|
from collections.abc import AsyncGenerator, Awaitable, Callable, Generator
|
||||||
import datetime
|
import datetime
|
||||||
import http
|
import http
|
||||||
import time
|
import time
|
||||||
from typing import Any, TypeVar
|
from typing import Any
|
||||||
from unittest.mock import Mock, mock_open, patch
|
from unittest.mock import Mock, mock_open, patch
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientError
|
from aiohttp.client_exceptions import ClientError
|
||||||
|
@ -29,8 +29,7 @@ from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
ApiResult = Callable[[dict[str, Any]], None]
|
ApiResult = Callable[[dict[str, Any]], None]
|
||||||
ComponentSetup = Callable[[], Awaitable[bool]]
|
ComponentSetup = Callable[[], Awaitable[bool]]
|
||||||
_T = TypeVar("_T")
|
type AsyncYieldFixture[_T] = AsyncGenerator[_T, None]
|
||||||
YieldFixture = Generator[_T, None, None]
|
|
||||||
|
|
||||||
|
|
||||||
CALENDAR_ID = "qwertyuiopasdfghjklzxcvbnm@import.calendar.google.com"
|
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.setup import async_setup_component
|
||||||
from homeassistant.util.dt import utcnow
|
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.common import MockConfigEntry, async_fire_time_changed
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
@ -70,7 +70,7 @@ async def code_expiration_delta() -> datetime.timedelta:
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def mock_code_flow(
|
async def mock_code_flow(
|
||||||
code_expiration_delta: datetime.timedelta,
|
code_expiration_delta: datetime.timedelta,
|
||||||
) -> YieldFixture[Mock]:
|
) -> AsyncYieldFixture[Mock]:
|
||||||
"""Fixture for initiating OAuth flow."""
|
"""Fixture for initiating OAuth flow."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.google.api.OAuth2WebServerFlow.step1_get_device_and_user_codes",
|
"homeassistant.components.google.api.OAuth2WebServerFlow.step1_get_device_and_user_codes",
|
||||||
|
@ -88,7 +88,7 @@ async def mock_code_flow(
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@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."""
|
"""Fixture for mocking out the exchange for credentials."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.google.api.OAuth2WebServerFlow.step2_exchange",
|
"homeassistant.components.google.api.OAuth2WebServerFlow.step2_exchange",
|
||||||
|
|
|
@ -6,7 +6,7 @@ from collections.abc import Awaitable, Callable, Generator
|
||||||
import copy
|
import copy
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
import time
|
import time
|
||||||
from typing import Any, TypeVar
|
from typing import Any
|
||||||
|
|
||||||
from google_nest_sdm.auth import AbstractAuth
|
from google_nest_sdm.auth import AbstractAuth
|
||||||
from google_nest_sdm.device import Device
|
from google_nest_sdm.device import Device
|
||||||
|
@ -20,8 +20,7 @@ from homeassistant.components.nest import DOMAIN
|
||||||
|
|
||||||
# Typing helpers
|
# Typing helpers
|
||||||
PlatformSetup = Callable[[], Awaitable[None]]
|
PlatformSetup = Callable[[], Awaitable[None]]
|
||||||
_T = TypeVar("_T")
|
type YieldFixture[_T] = Generator[_T, None, None]
|
||||||
YieldFixture = Generator[_T, None, None]
|
|
||||||
|
|
||||||
WEB_AUTH_DOMAIN = DOMAIN
|
WEB_AUTH_DOMAIN = DOMAIN
|
||||||
APP_AUTH_DOMAIN = f"{DOMAIN}.installed"
|
APP_AUTH_DOMAIN = f"{DOMAIN}.installed"
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import AsyncGenerator, Awaitable, Callable, Generator
|
from collections.abc import AsyncGenerator, Awaitable, Callable
|
||||||
from typing import Any, TypeVar
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -24,8 +24,7 @@ CONFIG_ENTRY_DATA = {"server_url": SERVER_URL}
|
||||||
|
|
||||||
# Typing helpers
|
# Typing helpers
|
||||||
ComponentSetup = Callable[[], Awaitable[None]]
|
ComponentSetup = Callable[[], Awaitable[None]]
|
||||||
_T = TypeVar("_T")
|
type AsyncYieldFixture[_T] = AsyncGenerator[_T, None]
|
||||||
YieldFixture = Generator[_T, None, None]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
|
@ -91,7 +90,7 @@ async def rtsp_to_webrtc_client() -> None:
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def setup_integration(
|
async def setup_integration(
|
||||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||||
) -> YieldFixture[ComponentSetup]:
|
) -> AsyncYieldFixture[ComponentSetup]:
|
||||||
"""Fixture for setting up the component."""
|
"""Fixture for setting up the component."""
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue