mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Improve type hints in aiohttp_client helper tests (#119300)
This commit is contained in:
parent
612743077a
commit
650cf13bca
@ -3,9 +3,10 @@
|
|||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
from aiohttp.test_utils import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.mjpeg.const import (
|
from homeassistant.components.mjpeg import (
|
||||||
CONF_MJPEG_URL,
|
CONF_MJPEG_URL,
|
||||||
CONF_STILL_IMAGE_URL,
|
CONF_STILL_IMAGE_URL,
|
||||||
DOMAIN as MJPEG_DOMAIN,
|
DOMAIN as MJPEG_DOMAIN,
|
||||||
@ -28,10 +29,13 @@ from tests.common import (
|
|||||||
mock_integration,
|
mock_integration,
|
||||||
)
|
)
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="camera_client")
|
@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."""
|
"""Fixture to fetch camera streams."""
|
||||||
mock_config_entry = MockConfigEntry(
|
mock_config_entry = MockConfigEntry(
|
||||||
title="MJPEG Camera",
|
title="MJPEG Camera",
|
||||||
@ -46,12 +50,10 @@ def camera_client_fixture(hass, hass_client):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
mock_config_entry.add_to_hass(hass)
|
mock_config_entry.add_to_hass(hass)
|
||||||
hass.loop.run_until_complete(
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
hass.config_entries.async_setup(mock_config_entry.entry_id)
|
await hass.async_block_till_done()
|
||||||
)
|
|
||||||
hass.loop.run_until_complete(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:
|
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(
|
async def test_async_aiohttp_proxy_stream(
|
||||||
aioclient_mock: AiohttpClientMocker, camera_client
|
aioclient_mock: AiohttpClientMocker, camera_client: TestClient
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that it fetches the given url."""
|
"""Test that it fetches the given url."""
|
||||||
aioclient_mock.get("http://example.com/mjpeg_stream", content=b"Frame1Frame2Frame3")
|
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(
|
async def test_async_aiohttp_proxy_stream_timeout(
|
||||||
aioclient_mock: AiohttpClientMocker, camera_client
|
aioclient_mock: AiohttpClientMocker, camera_client: TestClient
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that it fetches the given url."""
|
"""Test that it fetches the given url."""
|
||||||
aioclient_mock.get("http://example.com/mjpeg_stream", exc=TimeoutError())
|
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(
|
async def test_async_aiohttp_proxy_stream_client_err(
|
||||||
aioclient_mock: AiohttpClientMocker, camera_client
|
aioclient_mock: AiohttpClientMocker, camera_client: TestClient
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that it fetches the given url."""
|
"""Test that it fetches the given url."""
|
||||||
aioclient_mock.get("http://example.com/mjpeg_stream", exc=aiohttp.ClientError())
|
aioclient_mock.get("http://example.com/mjpeg_stream", exc=aiohttp.ClientError())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user