Fix tests typing helper (#86956)

This commit is contained in:
epenet 2023-01-31 08:48:35 +01:00 committed by GitHub
parent 33ede351f0
commit 7db166b515
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 16 deletions

View File

@ -17,7 +17,6 @@ from aioairzone.const import (
RAW_HVAC, RAW_HVAC,
RAW_WEBSERVER, RAW_WEBSERVER,
) )
from aiohttp import ClientSession
from homeassistant.components.airzone.const import DOMAIN from homeassistant.components.airzone.const import DOMAIN
from homeassistant.components.diagnostics import REDACTED from homeassistant.components.diagnostics import REDACTED
@ -27,10 +26,11 @@ from homeassistant.core import HomeAssistant
from .util import CONFIG, HVAC_MOCK, HVAC_WEBSERVER_MOCK, async_init_integration from .util import CONFIG, HVAC_MOCK, HVAC_WEBSERVER_MOCK, async_init_integration
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
async def test_config_entry_diagnostics( async def test_config_entry_diagnostics(
hass: HomeAssistant, hass_client: ClientSession hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None: ) -> None:
"""Test config entry diagnostics.""" """Test config entry diagnostics."""
await async_init_integration(hass) await async_init_integration(hass)

View File

@ -7,7 +7,6 @@ import logging
from typing import Any from typing import Any
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
from aiohttp import ClientWebSocketResponse
import pytest import pytest
from homeassistant import config_entries, data_entry_flow from homeassistant import config_entries, data_entry_flow
@ -31,6 +30,7 @@ from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry, mock_platform from tests.common import MockConfigEntry, mock_platform
from tests.typing import WebSocketGenerator
CLIENT_ID = "some-client-id" CLIENT_ID = "some-client-id"
CLIENT_SECRET = "some-client-secret" CLIENT_SECRET = "some-client-secret"
@ -211,9 +211,7 @@ ClientFixture = Callable[[], Client]
@pytest.fixture @pytest.fixture
async def ws_client( async def ws_client(hass_ws_client: WebSocketGenerator) -> ClientFixture:
hass_ws_client: Callable[[...], ClientWebSocketResponse]
) -> ClientFixture:
"""Fixture for creating the test websocket client.""" """Fixture for creating the test websocket client."""
async def create_client() -> Client: async def create_client() -> Client:

View File

@ -54,7 +54,7 @@ from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util, location from homeassistant.util import dt as dt_util, location
from .ignore_uncaught_exceptions import IGNORE_UNCAUGHT_EXCEPTIONS from .ignore_uncaught_exceptions import IGNORE_UNCAUGHT_EXCEPTIONS
from .typing import TestClientGenerator, TestWebSocketGenerator from .typing import ClientSessionGenerator, WebSocketGenerator
pytest.register_assert_rewrite("tests.common") pytest.register_assert_rewrite("tests.common")
@ -332,7 +332,7 @@ def aiohttp_client_cls():
@pytest.fixture @pytest.fixture
def aiohttp_client( def aiohttp_client(
event_loop: asyncio.AbstractEventLoop, event_loop: asyncio.AbstractEventLoop,
) -> Generator[TestClientGenerator, None, None]: ) -> Generator[ClientSessionGenerator, None, None]:
"""Override the default aiohttp_client since 3.x does not support aiohttp_client_cls. """Override the default aiohttp_client since 3.x does not support aiohttp_client_cls.
Remove this when upgrading to 4.x as aiohttp_client_cls Remove this when upgrading to 4.x as aiohttp_client_cls
@ -609,10 +609,10 @@ def local_auth(hass):
@pytest.fixture @pytest.fixture
def hass_client( def hass_client(
hass: HomeAssistant, hass: HomeAssistant,
aiohttp_client: TestClientGenerator, aiohttp_client: ClientSessionGenerator,
hass_access_token: str, hass_access_token: str,
socket_enabled: None, socket_enabled: None,
) -> TestClientGenerator: ) -> ClientSessionGenerator:
"""Return an authenticated HTTP client.""" """Return an authenticated HTTP client."""
async def auth_client() -> TestClient: async def auth_client() -> TestClient:
@ -627,9 +627,9 @@ def hass_client(
@pytest.fixture @pytest.fixture
def hass_client_no_auth( def hass_client_no_auth(
hass: HomeAssistant, hass: HomeAssistant,
aiohttp_client: TestClientGenerator, aiohttp_client: ClientSessionGenerator,
socket_enabled: None, socket_enabled: None,
) -> TestClientGenerator: ) -> ClientSessionGenerator:
"""Return an unauthenticated HTTP client.""" """Return an unauthenticated HTTP client."""
async def client() -> TestClient: async def client() -> TestClient:
@ -665,11 +665,11 @@ def current_request_with_host(current_request):
@pytest.fixture @pytest.fixture
def hass_ws_client( def hass_ws_client(
aiohttp_client: TestClientGenerator, aiohttp_client: ClientSessionGenerator,
hass_access_token: str | None, hass_access_token: str | None,
hass: HomeAssistant, hass: HomeAssistant,
socket_enabled: None, socket_enabled: None,
) -> TestWebSocketGenerator: ) -> WebSocketGenerator:
"""Websocket client fixture connected to websocket server.""" """Websocket client fixture connected to websocket server."""
async def create_client( async def create_client(

View File

@ -7,5 +7,5 @@ from typing import Any
from aiohttp import ClientWebSocketResponse from aiohttp import ClientWebSocketResponse
from aiohttp.test_utils import TestClient from aiohttp.test_utils import TestClient
TestClientGenerator = Callable[..., Coroutine[Any, Any, TestClient]] ClientSessionGenerator = Callable[..., Coroutine[Any, Any, TestClient]]
TestWebSocketGenerator = Callable[..., Coroutine[Any, Any, ClientWebSocketResponse]] WebSocketGenerator = Callable[..., Coroutine[Any, Any, ClientWebSocketResponse]]