mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Improve type hints in tests (a-h) (#118379)
This commit is contained in:
parent
4893faa671
commit
092cdcfe91
@ -849,12 +849,12 @@ async def test_rtsp_to_web_rtc_offer(
|
|||||||
|
|
||||||
|
|
||||||
async def test_unsupported_rtsp_to_web_rtc_stream_type(
|
async def test_unsupported_rtsp_to_web_rtc_stream_type(
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
hass_ws_client,
|
hass_ws_client: WebSocketGenerator,
|
||||||
mock_camera,
|
mock_camera,
|
||||||
mock_hls_stream_source, # Not an RTSP stream source
|
mock_hls_stream_source, # Not an RTSP stream source
|
||||||
mock_rtsp_to_web_rtc,
|
mock_rtsp_to_web_rtc,
|
||||||
):
|
) -> None:
|
||||||
"""Test rtsp-to-webrtc is not registered for non-RTSP streams."""
|
"""Test rtsp-to-webrtc is not registered for non-RTSP streams."""
|
||||||
client = await hass_ws_client(hass)
|
client = await hass_ws_client(hass)
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
|
@ -13,19 +13,23 @@ from tests.typing import WebSocketGenerator
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
async def setup_config(hass, local_auth):
|
async def setup_config(
|
||||||
|
hass: HomeAssistant, local_auth: prov_ha.HassAuthProvider
|
||||||
|
) -> None:
|
||||||
"""Fixture that sets up the auth provider ."""
|
"""Fixture that sets up the auth provider ."""
|
||||||
auth_ha.async_setup(hass)
|
auth_ha.async_setup(hass)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def auth_provider(local_auth):
|
async def auth_provider(
|
||||||
|
local_auth: prov_ha.HassAuthProvider,
|
||||||
|
) -> prov_ha.HassAuthProvider:
|
||||||
"""Hass auth provider."""
|
"""Hass auth provider."""
|
||||||
return local_auth
|
return local_auth
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def owner_access_token(hass, hass_owner_user):
|
async def owner_access_token(hass: HomeAssistant, hass_owner_user: MockUser) -> str:
|
||||||
"""Access token for owner user."""
|
"""Access token for owner user."""
|
||||||
refresh_token = await hass.auth.async_create_refresh_token(
|
refresh_token = await hass.auth.async_create_refresh_token(
|
||||||
hass_owner_user, CLIENT_ID
|
hass_owner_user, CLIENT_ID
|
||||||
|
@ -25,10 +25,10 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def setup_automation(
|
async def setup_automation(
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
automation_config,
|
automation_config,
|
||||||
stub_blueprint_populate,
|
stub_blueprint_populate: None,
|
||||||
):
|
) -> None:
|
||||||
"""Set up automation integration."""
|
"""Set up automation integration."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, "automation", {"automation": automation_config}
|
hass, "automation", {"automation": automation_config}
|
||||||
|
@ -19,11 +19,17 @@ from homeassistant.util import dt as dt_util, location
|
|||||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||||
|
|
||||||
from tests.common import MockUser
|
from tests.common import MockUser
|
||||||
from tests.typing import ClientSessionGenerator, WebSocketGenerator
|
from tests.typing import (
|
||||||
|
ClientSessionGenerator,
|
||||||
|
MockHAClientWebSocket,
|
||||||
|
WebSocketGenerator,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def client(hass, hass_ws_client):
|
async def client(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> MockHAClientWebSocket:
|
||||||
"""Fixture that can interact with the config manager API."""
|
"""Fixture that can interact with the config manager API."""
|
||||||
with patch.object(config, "SECTIONS", [core]):
|
with patch.object(config, "SECTIONS", [core]):
|
||||||
assert await async_setup_component(hass, "config", {})
|
assert await async_setup_component(hass, "config", {})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""The tests for the counter component."""
|
"""The tests for the counter component."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def storage_setup(hass, hass_storage):
|
def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
|
||||||
"""Storage setup."""
|
"""Storage setup."""
|
||||||
|
|
||||||
async def _storage(items=None, config=None):
|
async def _storage(items=None, config=None):
|
||||||
|
@ -5,11 +5,15 @@ from unittest.mock import patch
|
|||||||
from homeassistant.components import dynalite
|
from homeassistant.components import dynalite
|
||||||
from homeassistant.components.cover import DEVICE_CLASSES
|
from homeassistant.components.cover import DEVICE_CLASSES
|
||||||
from homeassistant.const import CONF_PORT
|
from homeassistant.const import CONF_PORT
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
from tests.typing import WebSocketGenerator
|
||||||
|
|
||||||
|
|
||||||
async def test_get_config(hass, hass_ws_client):
|
async def test_get_config(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> None:
|
||||||
"""Get the config via websocket."""
|
"""Get the config via websocket."""
|
||||||
host = "1.2.3.4"
|
host = "1.2.3.4"
|
||||||
port = 765
|
port = 765
|
||||||
@ -49,7 +53,9 @@ async def test_get_config(hass, hass_ws_client):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_save_config(hass, hass_ws_client):
|
async def test_save_config(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> None:
|
||||||
"""Save the config via websocket."""
|
"""Save the config via websocket."""
|
||||||
host1 = "1.2.3.4"
|
host1 = "1.2.3.4"
|
||||||
port1 = 765
|
port1 = 765
|
||||||
@ -103,7 +109,9 @@ async def test_save_config(hass, hass_ws_client):
|
|||||||
assert modified_entry.data[CONF_PORT] == port3
|
assert modified_entry.data[CONF_PORT] == port3
|
||||||
|
|
||||||
|
|
||||||
async def test_save_config_invalid_entry(hass, hass_ws_client):
|
async def test_save_config_invalid_entry(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> None:
|
||||||
"""Try to update nonexistent entry."""
|
"""Try to update nonexistent entry."""
|
||||||
host1 = "1.2.3.4"
|
host1 = "1.2.3.4"
|
||||||
port1 = 765
|
port1 = 765
|
||||||
|
@ -7,6 +7,7 @@ from typing import Any
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.energy import data
|
from homeassistant.components.energy import data
|
||||||
|
from homeassistant.components.recorder.core import Recorder
|
||||||
from homeassistant.components.recorder.util import session_scope
|
from homeassistant.components.recorder.util import session_scope
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
ATTR_LAST_RESET,
|
ATTR_LAST_RESET,
|
||||||
@ -35,7 +36,7 @@ TEST_TIME_ADVANCE_INTERVAL = timedelta(milliseconds=10)
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def setup_integration(recorder_mock):
|
async def setup_integration(recorder_mock: Recorder):
|
||||||
"""Set up the integration."""
|
"""Set up the integration."""
|
||||||
|
|
||||||
async def setup_integration(hass):
|
async def setup_integration(hass):
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Test ESPHome dashboard features."""
|
"""Test ESPHome dashboard features."""
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from aioesphomeapi import DeviceInfo, InvalidAuthAPIError
|
from aioesphomeapi import DeviceInfo, InvalidAuthAPIError
|
||||||
@ -15,7 +16,7 @@ from tests.common import MockConfigEntry
|
|||||||
|
|
||||||
|
|
||||||
async def test_dashboard_storage(
|
async def test_dashboard_storage(
|
||||||
hass: HomeAssistant, init_integration, mock_dashboard, hass_storage
|
hass: HomeAssistant, init_integration, mock_dashboard, hass_storage: dict[str, Any]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test dashboard storage."""
|
"""Test dashboard storage."""
|
||||||
assert hass_storage[dashboard.STORAGE_KEY]["data"] == {
|
assert hass_storage[dashboard.STORAGE_KEY]["data"] == {
|
||||||
@ -28,8 +29,10 @@ async def test_dashboard_storage(
|
|||||||
|
|
||||||
|
|
||||||
async def test_restore_dashboard_storage(
|
async def test_restore_dashboard_storage(
|
||||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, hass_storage
|
hass: HomeAssistant,
|
||||||
) -> MockConfigEntry:
|
mock_config_entry: MockConfigEntry,
|
||||||
|
hass_storage: dict[str, Any],
|
||||||
|
) -> None:
|
||||||
"""Restore dashboard url and slug from storage."""
|
"""Restore dashboard url and slug from storage."""
|
||||||
hass_storage[dashboard.STORAGE_KEY] = {
|
hass_storage[dashboard.STORAGE_KEY] = {
|
||||||
"version": dashboard.STORAGE_VERSION,
|
"version": dashboard.STORAGE_VERSION,
|
||||||
@ -46,8 +49,10 @@ async def test_restore_dashboard_storage(
|
|||||||
|
|
||||||
|
|
||||||
async def test_restore_dashboard_storage_end_to_end(
|
async def test_restore_dashboard_storage_end_to_end(
|
||||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, hass_storage
|
hass: HomeAssistant,
|
||||||
) -> MockConfigEntry:
|
mock_config_entry: MockConfigEntry,
|
||||||
|
hass_storage: dict[str, Any],
|
||||||
|
) -> None:
|
||||||
"""Restore dashboard url and slug from storage."""
|
"""Restore dashboard url and slug from storage."""
|
||||||
hass_storage[dashboard.STORAGE_KEY] = {
|
hass_storage[dashboard.STORAGE_KEY] = {
|
||||||
"version": dashboard.STORAGE_VERSION,
|
"version": dashboard.STORAGE_VERSION,
|
||||||
@ -65,8 +70,10 @@ async def test_restore_dashboard_storage_end_to_end(
|
|||||||
|
|
||||||
|
|
||||||
async def test_setup_dashboard_fails(
|
async def test_setup_dashboard_fails(
|
||||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, hass_storage
|
hass: HomeAssistant,
|
||||||
) -> MockConfigEntry:
|
mock_config_entry: MockConfigEntry,
|
||||||
|
hass_storage: dict[str, Any],
|
||||||
|
) -> None:
|
||||||
"""Test that nothing is stored on failed dashboard setup when there was no dashboard before."""
|
"""Test that nothing is stored on failed dashboard setup when there was no dashboard before."""
|
||||||
with patch.object(
|
with patch.object(
|
||||||
coordinator.ESPHomeDashboardAPI, "get_devices", side_effect=TimeoutError
|
coordinator.ESPHomeDashboardAPI, "get_devices", side_effect=TimeoutError
|
||||||
@ -83,8 +90,10 @@ async def test_setup_dashboard_fails(
|
|||||||
|
|
||||||
|
|
||||||
async def test_setup_dashboard_fails_when_already_setup(
|
async def test_setup_dashboard_fails_when_already_setup(
|
||||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, hass_storage
|
hass: HomeAssistant,
|
||||||
) -> MockConfigEntry:
|
mock_config_entry: MockConfigEntry,
|
||||||
|
hass_storage: dict[str, Any],
|
||||||
|
) -> None:
|
||||||
"""Test failed dashboard setup still reloads entries if one existed before."""
|
"""Test failed dashboard setup still reloads entries if one existed before."""
|
||||||
with patch.object(
|
with patch.object(
|
||||||
coordinator.ESPHomeDashboardAPI, "get_devices"
|
coordinator.ESPHomeDashboardAPI, "get_devices"
|
||||||
|
@ -109,14 +109,16 @@ async def mock_http_client(
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def themes_ws_client(
|
async def themes_ws_client(
|
||||||
hass: HomeAssistant, hass_ws_client: ClientSessionGenerator, frontend_themes
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, frontend_themes
|
||||||
) -> TestClient:
|
) -> MockHAClientWebSocket:
|
||||||
"""Start the Home Assistant HTTP component."""
|
"""Start the Home Assistant HTTP component."""
|
||||||
return await hass_ws_client(hass)
|
return await hass_ws_client(hass)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def ws_client(hass, hass_ws_client, frontend):
|
async def ws_client(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, frontend
|
||||||
|
) -> MockHAClientWebSocket:
|
||||||
"""Start the Home Assistant HTTP component."""
|
"""Start the Home Assistant HTTP component."""
|
||||||
return await hass_ws_client(hass)
|
return await hass_ws_client(hass)
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ ACCESS_TOKEN = "superdoublesecret"
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def auth_header(hass_access_token):
|
def auth_header(hass_access_token: str) -> dict[str, str]:
|
||||||
"""Generate an HTTP header with bearer token authorization."""
|
"""Generate an HTTP header with bearer token authorization."""
|
||||||
return {AUTHORIZATION: f"Bearer {hass_access_token}"}
|
return {AUTHORIZATION: f"Bearer {hass_access_token}"}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ from unittest.mock import patch
|
|||||||
from aiohttp import StreamReader
|
from aiohttp import StreamReader
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from tests.common import MockUser
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ def mock_not_onboarded():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hassio_user_client(hassio_client, hass_admin_user):
|
def hassio_user_client(hassio_client, hass_admin_user: MockUser):
|
||||||
"""Return a Hass.io HTTP client tied to a non-admin user."""
|
"""Return a Hass.io HTTP client tied to a non-admin user."""
|
||||||
hass_admin_user.groups = []
|
hass_admin_user.groups = []
|
||||||
return hassio_client
|
return hassio_client
|
||||||
|
@ -580,13 +580,13 @@ async def test_no_alerts(
|
|||||||
)
|
)
|
||||||
async def test_alerts_change(
|
async def test_alerts_change(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_ws_client,
|
hass_ws_client: WebSocketGenerator,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
ha_version: str,
|
ha_version: str,
|
||||||
fixture_1: str,
|
fixture_1: str,
|
||||||
expected_alerts_1: list[tuple(str, str)],
|
expected_alerts_1: list[tuple[str, str]],
|
||||||
fixture_2: str,
|
fixture_2: str,
|
||||||
expected_alerts_2: list[tuple(str, str)],
|
expected_alerts_2: list[tuple[str, str]],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test creating issues based on alerts."""
|
"""Test creating issues based on alerts."""
|
||||||
fixture_1_content = load_fixture(fixture_1, "homeassistant_alerts")
|
fixture_1_content = load_fixture(fixture_1, "homeassistant_alerts")
|
||||||
|
@ -134,7 +134,7 @@ async def test_connection_errors(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def login_requests_mock(requests_mock):
|
def login_requests_mock(requests_mock: requests_mock.Mocker) -> requests_mock.Mocker:
|
||||||
"""Set up a requests_mock with base mocks for login tests."""
|
"""Set up a requests_mock with base mocks for login tests."""
|
||||||
https_url = urlunparse(
|
https_url = urlunparse(
|
||||||
urlparse(FIXTURE_USER_INPUT[CONF_URL])._replace(scheme="https")
|
urlparse(FIXTURE_USER_INPUT[CONF_URL])._replace(scheme="https")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user