From 650cf13bcaea194f58763c282159c3eeb61608ca Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 10 Jun 2024 20:31:19 +0200 Subject: [PATCH] Improve type hints in aiohttp_client helper tests (#119300) --- tests/helpers/test_aiohttp_client.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/helpers/test_aiohttp_client.py b/tests/helpers/test_aiohttp_client.py index 69015c80305..7dd34fd2c64 100644 --- a/tests/helpers/test_aiohttp_client.py +++ b/tests/helpers/test_aiohttp_client.py @@ -3,9 +3,10 @@ from unittest.mock import Mock, patch import aiohttp +from aiohttp.test_utils import TestClient import pytest -from homeassistant.components.mjpeg.const import ( +from homeassistant.components.mjpeg import ( CONF_MJPEG_URL, CONF_STILL_IMAGE_URL, DOMAIN as MJPEG_DOMAIN, @@ -28,10 +29,13 @@ from tests.common import ( mock_integration, ) from tests.test_util.aiohttp import AiohttpClientMocker +from tests.typing import ClientSessionGenerator @pytest.fixture(name="camera_client") -def camera_client_fixture(hass, hass_client): +async def camera_client_fixture( + hass: HomeAssistant, hass_client: ClientSessionGenerator +) -> TestClient: """Fixture to fetch camera streams.""" mock_config_entry = MockConfigEntry( title="MJPEG Camera", @@ -46,12 +50,10 @@ def camera_client_fixture(hass, hass_client): }, ) mock_config_entry.add_to_hass(hass) - hass.loop.run_until_complete( - hass.config_entries.async_setup(mock_config_entry.entry_id) - ) - hass.loop.run_until_complete(hass.async_block_till_done()) + await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() - return hass.loop.run_until_complete(hass_client()) + return await hass_client() async def test_get_clientsession_with_ssl(hass: HomeAssistant) -> None: @@ -253,7 +255,7 @@ async def test_warning_close_session_custom( async def test_async_aiohttp_proxy_stream( - aioclient_mock: AiohttpClientMocker, camera_client + aioclient_mock: AiohttpClientMocker, camera_client: TestClient ) -> None: """Test that it fetches the given url.""" aioclient_mock.get("http://example.com/mjpeg_stream", content=b"Frame1Frame2Frame3") @@ -267,7 +269,7 @@ async def test_async_aiohttp_proxy_stream( async def test_async_aiohttp_proxy_stream_timeout( - aioclient_mock: AiohttpClientMocker, camera_client + aioclient_mock: AiohttpClientMocker, camera_client: TestClient ) -> None: """Test that it fetches the given url.""" aioclient_mock.get("http://example.com/mjpeg_stream", exc=TimeoutError()) @@ -277,7 +279,7 @@ async def test_async_aiohttp_proxy_stream_timeout( async def test_async_aiohttp_proxy_stream_client_err( - aioclient_mock: AiohttpClientMocker, camera_client + aioclient_mock: AiohttpClientMocker, camera_client: TestClient ) -> None: """Test that it fetches the given url.""" aioclient_mock.get("http://example.com/mjpeg_stream", exc=aiohttp.ClientError())