From 7db166b5158ec7599ea43899c2ea19ff6ddddfc4 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 31 Jan 2023 08:48:35 +0100 Subject: [PATCH] Fix tests typing helper (#86956) --- tests/components/airzone/test_diagnostics.py | 4 ++-- .../application_credentials/test_init.py | 6 ++---- tests/conftest.py | 16 ++++++++-------- tests/typing.py | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/components/airzone/test_diagnostics.py b/tests/components/airzone/test_diagnostics.py index f03257fd612..34a563b7af8 100644 --- a/tests/components/airzone/test_diagnostics.py +++ b/tests/components/airzone/test_diagnostics.py @@ -17,7 +17,6 @@ from aioairzone.const import ( RAW_HVAC, RAW_WEBSERVER, ) -from aiohttp import ClientSession from homeassistant.components.airzone.const import DOMAIN 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 tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.typing import ClientSessionGenerator async def test_config_entry_diagnostics( - hass: HomeAssistant, hass_client: ClientSession + hass: HomeAssistant, hass_client: ClientSessionGenerator ) -> None: """Test config entry diagnostics.""" await async_init_integration(hass) diff --git a/tests/components/application_credentials/test_init.py b/tests/components/application_credentials/test_init.py index 7685787d4d9..45e0959bf99 100644 --- a/tests/components/application_credentials/test_init.py +++ b/tests/components/application_credentials/test_init.py @@ -7,7 +7,6 @@ import logging from typing import Any from unittest.mock import AsyncMock, Mock, patch -from aiohttp import ClientWebSocketResponse import pytest 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 tests.common import MockConfigEntry, mock_platform +from tests.typing import WebSocketGenerator CLIENT_ID = "some-client-id" CLIENT_SECRET = "some-client-secret" @@ -211,9 +211,7 @@ ClientFixture = Callable[[], Client] @pytest.fixture -async def ws_client( - hass_ws_client: Callable[[...], ClientWebSocketResponse] -) -> ClientFixture: +async def ws_client(hass_ws_client: WebSocketGenerator) -> ClientFixture: """Fixture for creating the test websocket client.""" async def create_client() -> Client: diff --git a/tests/conftest.py b/tests/conftest.py index 6c0760b1bcb..f586faf5677 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -54,7 +54,7 @@ from homeassistant.setup import async_setup_component from homeassistant.util import dt as dt_util, location from .ignore_uncaught_exceptions import IGNORE_UNCAUGHT_EXCEPTIONS -from .typing import TestClientGenerator, TestWebSocketGenerator +from .typing import ClientSessionGenerator, WebSocketGenerator pytest.register_assert_rewrite("tests.common") @@ -332,7 +332,7 @@ def aiohttp_client_cls(): @pytest.fixture def aiohttp_client( 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. Remove this when upgrading to 4.x as aiohttp_client_cls @@ -609,10 +609,10 @@ def local_auth(hass): @pytest.fixture def hass_client( hass: HomeAssistant, - aiohttp_client: TestClientGenerator, + aiohttp_client: ClientSessionGenerator, hass_access_token: str, socket_enabled: None, -) -> TestClientGenerator: +) -> ClientSessionGenerator: """Return an authenticated HTTP client.""" async def auth_client() -> TestClient: @@ -627,9 +627,9 @@ def hass_client( @pytest.fixture def hass_client_no_auth( hass: HomeAssistant, - aiohttp_client: TestClientGenerator, + aiohttp_client: ClientSessionGenerator, socket_enabled: None, -) -> TestClientGenerator: +) -> ClientSessionGenerator: """Return an unauthenticated HTTP client.""" async def client() -> TestClient: @@ -665,11 +665,11 @@ def current_request_with_host(current_request): @pytest.fixture def hass_ws_client( - aiohttp_client: TestClientGenerator, + aiohttp_client: ClientSessionGenerator, hass_access_token: str | None, hass: HomeAssistant, socket_enabled: None, -) -> TestWebSocketGenerator: +) -> WebSocketGenerator: """Websocket client fixture connected to websocket server.""" async def create_client( diff --git a/tests/typing.py b/tests/typing.py index ec6577a9e87..22b937c6e24 100644 --- a/tests/typing.py +++ b/tests/typing.py @@ -7,5 +7,5 @@ from typing import Any from aiohttp import ClientWebSocketResponse from aiohttp.test_utils import TestClient -TestClientGenerator = Callable[..., Coroutine[Any, Any, TestClient]] -TestWebSocketGenerator = Callable[..., Coroutine[Any, Any, ClientWebSocketResponse]] +ClientSessionGenerator = Callable[..., Coroutine[Any, Any, TestClient]] +WebSocketGenerator = Callable[..., Coroutine[Any, Any, ClientWebSocketResponse]]