mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Improve type hints in tests (i-p) (#118380)
This commit is contained in:
parent
092cdcfe91
commit
242ee04642
@ -1,6 +1,7 @@
|
||||
"""The tests for the input_boolean component."""
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@ -30,7 +31,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def storage_setup(hass, hass_storage):
|
||||
def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
|
||||
"""Storage setup."""
|
||||
|
||||
async def _storage(items=None, config=None):
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""The tests for the input_test component."""
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@ -27,7 +28,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def storage_setup(hass, hass_storage):
|
||||
def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
|
||||
"""Storage setup."""
|
||||
|
||||
async def _storage(items=None, config=None):
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""Tests for the Input slider component."""
|
||||
|
||||
import datetime
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@ -45,7 +46,7 @@ INITIAL_DATETIME = f"{INITIAL_DATE} {INITIAL_TIME}"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def storage_setup(hass, hass_storage):
|
||||
def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
|
||||
"""Storage setup."""
|
||||
|
||||
async def _storage(items=None, config=None):
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""The tests for the Input number component."""
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@ -29,7 +30,7 @@ from tests.typing import WebSocketGenerator
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def storage_setup(hass, hass_storage):
|
||||
def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
|
||||
"""Storage setup."""
|
||||
|
||||
async def _storage(items=None, config=None):
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""The tests for the Input select component."""
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@ -36,7 +37,7 @@ from tests.typing import WebSocketGenerator
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def storage_setup(hass, hass_storage):
|
||||
def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
|
||||
"""Storage setup."""
|
||||
|
||||
async def _storage(items=None, config=None, minor_version=STORAGE_VERSION_MINOR):
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""The tests for the Input text component."""
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@ -36,7 +37,7 @@ TEST_VAL_MAX = 22
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def storage_setup(hass, hass_storage):
|
||||
def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]):
|
||||
"""Storage setup."""
|
||||
|
||||
async def _storage(items=None, config=None):
|
||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
from typing import Any
|
||||
from unittest.mock import DEFAULT, AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
@ -273,7 +274,7 @@ async def knx(request, hass, mock_config_entry: MockConfigEntry):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def load_knxproj(hass_storage):
|
||||
def load_knxproj(hass_storage: dict[str, Any]) -> None:
|
||||
"""Mock KNX project data."""
|
||||
hass_storage[KNX_PROJECT_STORAGE_KEY] = {
|
||||
"version": 1,
|
||||
|
@ -61,7 +61,7 @@ EMPTY_CONFIG = logbook.CONFIG_SCHEMA({logbook.DOMAIN: {}})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def hass_(recorder_mock, hass):
|
||||
async def hass_(recorder_mock: Recorder, hass: HomeAssistant) -> HomeAssistant:
|
||||
"""Set up things to be run when tests are started."""
|
||||
assert await async_setup_component(hass, logbook.DOMAIN, EMPTY_CONFIG)
|
||||
return hass
|
||||
|
@ -30,7 +30,9 @@ def mock_onboarding_done() -> Generator[MagicMock, None, None]:
|
||||
|
||||
|
||||
async def test_lovelace_from_storage(
|
||||
hass: HomeAssistant, hass_ws_client, hass_storage: dict[str, Any]
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_storage: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test we load lovelace config from storage."""
|
||||
assert await async_setup_component(hass, "lovelace", {})
|
||||
@ -83,7 +85,9 @@ async def test_lovelace_from_storage(
|
||||
|
||||
|
||||
async def test_lovelace_from_storage_save_before_load(
|
||||
hass: HomeAssistant, hass_ws_client, hass_storage: dict[str, Any]
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_storage: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test we can load lovelace config from storage."""
|
||||
assert await async_setup_component(hass, "lovelace", {})
|
||||
@ -101,7 +105,9 @@ async def test_lovelace_from_storage_save_before_load(
|
||||
|
||||
|
||||
async def test_lovelace_from_storage_delete(
|
||||
hass: HomeAssistant, hass_ws_client, hass_storage: dict[str, Any]
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_storage: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test we delete lovelace config from storage."""
|
||||
assert await async_setup_component(hass, "lovelace", {})
|
||||
@ -352,7 +358,9 @@ async def test_wrong_key_dashboard_from_yaml(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
async def test_storage_dashboards(
|
||||
hass: HomeAssistant, hass_ws_client, hass_storage: dict[str, Any]
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_storage: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test we load lovelace config from storage."""
|
||||
assert await async_setup_component(hass, "lovelace", {})
|
||||
|
@ -56,7 +56,9 @@ async def test_yaml_resources_backwards(
|
||||
|
||||
|
||||
async def test_storage_resources(
|
||||
hass: HomeAssistant, hass_ws_client, hass_storage: dict[str, Any]
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_storage: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test defining resources in storage config."""
|
||||
resource_config = [{**item, "id": uuid.uuid4().hex} for item in RESOURCE_EXAMPLES]
|
||||
@ -77,7 +79,9 @@ async def test_storage_resources(
|
||||
|
||||
|
||||
async def test_storage_resources_import(
|
||||
hass: HomeAssistant, hass_ws_client, hass_storage: dict[str, Any]
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_storage: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test importing resources from storage config."""
|
||||
assert await async_setup_component(hass, "lovelace", {})
|
||||
@ -165,7 +169,9 @@ async def test_storage_resources_import(
|
||||
|
||||
|
||||
async def test_storage_resources_import_invalid(
|
||||
hass: HomeAssistant, hass_ws_client, hass_storage: dict[str, Any]
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_storage: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test importing resources from storage config."""
|
||||
assert await async_setup_component(hass, "lovelace", {})
|
||||
@ -189,7 +195,9 @@ async def test_storage_resources_import_invalid(
|
||||
|
||||
|
||||
async def test_storage_resources_safe_mode(
|
||||
hass: HomeAssistant, hass_ws_client, hass_storage: dict[str, Any]
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_storage: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test defining resources in storage config."""
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import re
|
||||
import tempfile
|
||||
from unittest.mock import patch
|
||||
@ -304,7 +305,7 @@ def command_events(hass: HomeAssistant):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def image_path(tmp_path):
|
||||
def image_path(tmp_path: Path):
|
||||
"""Provide the Path to a mock image."""
|
||||
image = Image.new("RGBA", size=(50, 50), color=(256, 0, 0))
|
||||
image_file = tempfile.NamedTemporaryFile(dir=tmp_path)
|
||||
|
@ -10,6 +10,8 @@ from maxcube.windowshutter import MaxWindowShutter
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.maxcube import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import now
|
||||
|
||||
@ -99,7 +101,14 @@ def hass_config():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def cube(hass, hass_config, room, thermostat, wallthermostat, windowshutter):
|
||||
async def cube(
|
||||
hass: HomeAssistant,
|
||||
hass_config: ConfigType,
|
||||
room,
|
||||
thermostat,
|
||||
wallthermostat,
|
||||
windowshutter,
|
||||
):
|
||||
"""Build and setup a cube mock with a single room and some devices."""
|
||||
with patch("homeassistant.components.maxcube.MaxCube") as mock:
|
||||
cube = mock.return_value
|
||||
|
@ -110,7 +110,9 @@ async def setup_push_receiver(
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def setup_websocket_channel_only_push(hass, hass_admin_user):
|
||||
async def setup_websocket_channel_only_push(
|
||||
hass: HomeAssistant, hass_admin_user: MockUser
|
||||
) -> None:
|
||||
"""Set up local push."""
|
||||
entry = MockConfigEntry(
|
||||
data={
|
||||
|
@ -20,6 +20,8 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.typing import WebSocketGenerator
|
||||
|
||||
_NO_LOOPBACK_IPADDR = "192.168.1.5"
|
||||
_LOOPBACK_IPADDR = "127.0.0.1"
|
||||
|
||||
@ -409,7 +411,9 @@ async def test_interfaces_configured_from_storage(
|
||||
|
||||
|
||||
async def test_interfaces_configured_from_storage_websocket_update(
|
||||
hass: HomeAssistant, hass_ws_client, hass_storage: dict[str, Any]
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_storage: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test settings from storage can be updated via websocket api."""
|
||||
hass_storage[STORAGE_KEY] = {
|
||||
|
@ -18,11 +18,13 @@ from . import (
|
||||
)
|
||||
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
from tests.typing import WebSocketGenerator
|
||||
from tests.typing import MockHAClientWebSocket, WebSocketGenerator
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def websocket_client(hass, hass_ws_client):
|
||||
async def websocket_client(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||
) -> MockHAClientWebSocket:
|
||||
"""Create a websocket client."""
|
||||
return await hass_ws_client(hass)
|
||||
|
||||
|
@ -6,12 +6,13 @@ from unittest.mock import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import owntracks
|
||||
from homeassistant.components.device_tracker.legacy import Device
|
||||
from homeassistant.const import STATE_NOT_HOME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_mqtt_message
|
||||
from tests.typing import ClientSessionGenerator
|
||||
from tests.typing import ClientSessionGenerator, MqttMockHAClient
|
||||
|
||||
USER = "greg"
|
||||
DEVICE = "phone"
|
||||
@ -284,7 +285,9 @@ BAD_JSON_SUFFIX = "** and it ends here ^^"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def setup_comp(hass, mock_device_tracker_conf, mqtt_mock):
|
||||
def setup_comp(
|
||||
hass, mock_device_tracker_conf: list[Device], mqtt_mock: MqttMockHAClient
|
||||
):
|
||||
"""Initialize components."""
|
||||
hass.loop.run_until_complete(async_setup_component(hass, "device_tracker", {}))
|
||||
|
||||
|
@ -1,14 +1,18 @@
|
||||
"""The tests for the person component."""
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import person
|
||||
from homeassistant.components.person import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import collection
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockUser
|
||||
|
||||
DEVICE_TRACKER = "device_tracker.test_tracker"
|
||||
DEVICE_TRACKER_2 = "device_tracker.test_tracker_2"
|
||||
|
||||
@ -27,7 +31,9 @@ def storage_collection(hass):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def storage_setup(hass, hass_storage, hass_admin_user):
|
||||
def storage_setup(
|
||||
hass: HomeAssistant, hass_storage: dict[str, Any], hass_admin_user: MockUser
|
||||
) -> None:
|
||||
"""Storage setup."""
|
||||
hass_storage[DOMAIN] = {
|
||||
"key": DOMAIN,
|
||||
|
@ -4,6 +4,7 @@ from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
import requests_mock
|
||||
|
||||
from homeassistant.components.plex.const import DOMAIN, PLEX_SERVER_CONFIG, SERVERS
|
||||
from homeassistant.const import CONF_URL
|
||||
@ -436,7 +437,7 @@ def mock_websocket():
|
||||
@pytest.fixture
|
||||
def mock_plex_calls(
|
||||
entry,
|
||||
requests_mock,
|
||||
requests_mock: requests_mock.Mocker,
|
||||
children_20,
|
||||
children_30,
|
||||
children_200,
|
||||
@ -550,7 +551,7 @@ def setup_plex_server(
|
||||
livetv_sessions,
|
||||
mock_websocket,
|
||||
mock_plex_calls,
|
||||
requests_mock,
|
||||
requests_mock: requests_mock.Mocker,
|
||||
empty_payload,
|
||||
session_default,
|
||||
session_live_tv,
|
||||
|
Loading…
x
Reference in New Issue
Block a user