mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Improve type hints in ambient_station tests (#119230)
This commit is contained in:
parent
c03f9d264e
commit
06c1c435d1
@ -1,24 +1,31 @@
|
||||
"""Define test fixtures for Ambient PWS."""
|
||||
|
||||
import json
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
from typing_extensions import Generator
|
||||
|
||||
from homeassistant.components.ambient_station.const import CONF_APP_KEY, DOMAIN
|
||||
from homeassistant.const import CONF_API_KEY
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util.json import JsonArrayType, JsonObjectType
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
from tests.common import (
|
||||
MockConfigEntry,
|
||||
load_json_array_fixture,
|
||||
load_json_object_fixture,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(name="api")
|
||||
def api_fixture(hass, data_devices):
|
||||
def api_fixture(data_devices: JsonArrayType) -> Mock:
|
||||
"""Define a mock API object."""
|
||||
return Mock(get_devices=AsyncMock(return_value=data_devices))
|
||||
|
||||
|
||||
@pytest.fixture(name="config")
|
||||
def config_fixture(hass):
|
||||
def config_fixture() -> dict[str, Any]:
|
||||
"""Define a config entry data fixture."""
|
||||
return {
|
||||
CONF_API_KEY: "12345abcde12345abcde",
|
||||
@ -27,7 +34,9 @@ def config_fixture(hass):
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry")
|
||||
def config_entry_fixture(hass, config):
|
||||
def config_entry_fixture(
|
||||
hass: HomeAssistant, config: dict[str, Any]
|
||||
) -> MockConfigEntry:
|
||||
"""Define a config entry fixture."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
@ -39,19 +48,19 @@ def config_entry_fixture(hass, config):
|
||||
|
||||
|
||||
@pytest.fixture(name="data_devices", scope="package")
|
||||
def data_devices_fixture():
|
||||
def data_devices_fixture() -> JsonArrayType:
|
||||
"""Define devices data."""
|
||||
return json.loads(load_fixture("devices.json", "ambient_station"))
|
||||
return load_json_array_fixture("devices.json", "ambient_station")
|
||||
|
||||
|
||||
@pytest.fixture(name="data_station", scope="package")
|
||||
def data_station_fixture():
|
||||
def data_station_fixture() -> JsonObjectType:
|
||||
"""Define station data."""
|
||||
return json.loads(load_fixture("station_data.json", "ambient_station"))
|
||||
return load_json_object_fixture("station_data.json", "ambient_station")
|
||||
|
||||
|
||||
@pytest.fixture(name="mock_aioambient")
|
||||
async def mock_aioambient_fixture(api):
|
||||
def mock_aioambient_fixture(api: Mock) -> Generator[None]:
|
||||
"""Define a fixture to patch aioambient."""
|
||||
with (
|
||||
patch(
|
||||
@ -64,7 +73,9 @@ async def mock_aioambient_fixture(api):
|
||||
|
||||
|
||||
@pytest.fixture(name="setup_config_entry")
|
||||
async def setup_config_entry_fixture(hass, config_entry, mock_aioambient):
|
||||
async def setup_config_entry_fixture(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, mock_aioambient: None
|
||||
) -> None:
|
||||
"""Define a fixture to set up ambient_station."""
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
Loading…
x
Reference in New Issue
Block a user