mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Improve type hints in watttime tests (#123921)
This commit is contained in:
parent
1227cd8693
commit
ff4dac8f3a
@ -1,6 +1,7 @@
|
||||
"""Define test fixtures for WattTime."""
|
||||
|
||||
import json
|
||||
from collections.abc import AsyncGenerator
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
@ -20,13 +21,17 @@ from homeassistant.const import (
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.json import JsonObjectType
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||
|
||||
|
||||
@pytest.fixture(name="client")
|
||||
def client_fixture(get_grid_region, data_realtime_emissions):
|
||||
def client_fixture(
|
||||
get_grid_region: AsyncMock, data_realtime_emissions: JsonObjectType
|
||||
) -> Mock:
|
||||
"""Define an aiowatttime client."""
|
||||
client = Mock()
|
||||
client.emissions.async_get_grid_region = get_grid_region
|
||||
@ -37,7 +42,7 @@ def client_fixture(get_grid_region, data_realtime_emissions):
|
||||
|
||||
|
||||
@pytest.fixture(name="config_auth")
|
||||
def config_auth_fixture(hass):
|
||||
def config_auth_fixture() -> dict[str, Any]:
|
||||
"""Define an auth config entry data fixture."""
|
||||
return {
|
||||
CONF_USERNAME: "user",
|
||||
@ -46,7 +51,7 @@ def config_auth_fixture(hass):
|
||||
|
||||
|
||||
@pytest.fixture(name="config_coordinates")
|
||||
def config_coordinates_fixture(hass):
|
||||
def config_coordinates_fixture() -> dict[str, Any]:
|
||||
"""Define a coordinates config entry data fixture."""
|
||||
return {
|
||||
CONF_LATITUDE: 32.87336,
|
||||
@ -55,7 +60,7 @@ def config_coordinates_fixture(hass):
|
||||
|
||||
|
||||
@pytest.fixture(name="config_location_type")
|
||||
def config_location_type_fixture(hass):
|
||||
def config_location_type_fixture() -> dict[str, Any]:
|
||||
"""Define a location type config entry data fixture."""
|
||||
return {
|
||||
CONF_LOCATION_TYPE: LOCATION_TYPE_COORDINATES,
|
||||
@ -63,7 +68,9 @@ def config_location_type_fixture(hass):
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry")
|
||||
def config_entry_fixture(hass, config_auth, config_coordinates):
|
||||
def config_entry_fixture(
|
||||
hass: HomeAssistant, config_auth: dict[str, Any], config_coordinates: dict[str, Any]
|
||||
) -> MockConfigEntry:
|
||||
"""Define a config entry fixture."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
@ -82,25 +89,30 @@ def config_entry_fixture(hass, config_auth, config_coordinates):
|
||||
|
||||
|
||||
@pytest.fixture(name="data_grid_region", scope="package")
|
||||
def data_grid_region_fixture():
|
||||
def data_grid_region_fixture() -> JsonObjectType:
|
||||
"""Define grid region data."""
|
||||
return json.loads(load_fixture("grid_region_data.json", "watttime"))
|
||||
return load_json_object_fixture("grid_region_data.json", "watttime")
|
||||
|
||||
|
||||
@pytest.fixture(name="data_realtime_emissions", scope="package")
|
||||
def data_realtime_emissions_fixture():
|
||||
def data_realtime_emissions_fixture() -> JsonObjectType:
|
||||
"""Define realtime emissions data."""
|
||||
return json.loads(load_fixture("realtime_emissions_data.json", "watttime"))
|
||||
return load_json_object_fixture("realtime_emissions_data.json", "watttime")
|
||||
|
||||
|
||||
@pytest.fixture(name="get_grid_region")
|
||||
def get_grid_region_fixture(data_grid_region):
|
||||
def get_grid_region_fixture(data_grid_region: JsonObjectType) -> AsyncMock:
|
||||
"""Define an aiowatttime method to get grid region data."""
|
||||
return AsyncMock(return_value=data_grid_region)
|
||||
|
||||
|
||||
@pytest.fixture(name="setup_watttime")
|
||||
async def setup_watttime_fixture(hass, client, config_auth, config_coordinates):
|
||||
async def setup_watttime_fixture(
|
||||
hass: HomeAssistant,
|
||||
client: Mock,
|
||||
config_auth: dict[str, Any],
|
||||
config_coordinates: dict[str, Any],
|
||||
) -> AsyncGenerator[None]:
|
||||
"""Define a fixture to set up WattTime."""
|
||||
with (
|
||||
patch(
|
||||
|
Loading…
x
Reference in New Issue
Block a user