Improve type hints in purpleair tests (#123874)
This commit is contained in:
parent
1af6528f4f
commit
5f1d7e5566
1 changed files with 16 additions and 7 deletions
|
@ -1,5 +1,7 @@
|
|||
"""Define fixtures for PurpleAir tests."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from aiopurpleair.endpoints.sensors import NearbySensorResult
|
||||
|
@ -7,6 +9,7 @@ from aiopurpleair.models.sensors import GetSensorsResponse
|
|||
import pytest
|
||||
|
||||
from homeassistant.components.purpleair import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
|
@ -16,7 +19,7 @@ TEST_SENSOR_INDEX2 = 567890
|
|||
|
||||
|
||||
@pytest.fixture(name="api")
|
||||
def api_fixture(get_sensors_response):
|
||||
def api_fixture(get_sensors_response: GetSensorsResponse) -> Mock:
|
||||
"""Define a fixture to return a mocked aiopurple API object."""
|
||||
return Mock(
|
||||
async_check_api_key=AsyncMock(),
|
||||
|
@ -34,7 +37,11 @@ def api_fixture(get_sensors_response):
|
|||
|
||||
|
||||
@pytest.fixture(name="config_entry")
|
||||
def config_entry_fixture(hass, config_entry_data, config_entry_options):
|
||||
def config_entry_fixture(
|
||||
hass: HomeAssistant,
|
||||
config_entry_data: dict[str, Any],
|
||||
config_entry_options: dict[str, Any],
|
||||
) -> MockConfigEntry:
|
||||
"""Define a config entry fixture."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
|
@ -48,7 +55,7 @@ def config_entry_fixture(hass, config_entry_data, config_entry_options):
|
|||
|
||||
|
||||
@pytest.fixture(name="config_entry_data")
|
||||
def config_entry_data_fixture():
|
||||
def config_entry_data_fixture() -> dict[str, Any]:
|
||||
"""Define a config entry data fixture."""
|
||||
return {
|
||||
"api_key": TEST_API_KEY,
|
||||
|
@ -56,7 +63,7 @@ def config_entry_data_fixture():
|
|||
|
||||
|
||||
@pytest.fixture(name="config_entry_options")
|
||||
def config_entry_options_fixture():
|
||||
def config_entry_options_fixture() -> dict[str, Any]:
|
||||
"""Define a config entry options fixture."""
|
||||
return {
|
||||
"sensor_indices": [TEST_SENSOR_INDEX1],
|
||||
|
@ -64,7 +71,7 @@ def config_entry_options_fixture():
|
|||
|
||||
|
||||
@pytest.fixture(name="get_sensors_response", scope="package")
|
||||
def get_sensors_response_fixture():
|
||||
def get_sensors_response_fixture() -> GetSensorsResponse:
|
||||
"""Define a fixture to mock an aiopurpleair GetSensorsResponse object."""
|
||||
return GetSensorsResponse.parse_raw(
|
||||
load_fixture("get_sensors_response.json", "purpleair")
|
||||
|
@ -72,7 +79,7 @@ def get_sensors_response_fixture():
|
|||
|
||||
|
||||
@pytest.fixture(name="mock_aiopurpleair")
|
||||
async def mock_aiopurpleair_fixture(api):
|
||||
def mock_aiopurpleair_fixture(api: Mock) -> Generator[Mock]:
|
||||
"""Define a fixture to patch aiopurpleair."""
|
||||
with (
|
||||
patch("homeassistant.components.purpleair.config_flow.API", return_value=api),
|
||||
|
@ -82,7 +89,9 @@ async def mock_aiopurpleair_fixture(api):
|
|||
|
||||
|
||||
@pytest.fixture(name="setup_config_entry")
|
||||
async def setup_config_entry_fixture(hass, config_entry, mock_aiopurpleair):
|
||||
async def setup_config_entry_fixture(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, mock_aiopurpleair: Mock
|
||||
) -> None:
|
||||
"""Define a fixture to set up purpleair."""
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue