Update typing (5) [tests] (#63926)

This commit is contained in:
Marc Mueller 2022-01-11 21:28:13 +01:00 committed by GitHub
parent fa7e787415
commit ef7316d8d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 29 deletions

View File

@ -1,4 +1,5 @@
"""Provides device automations for Philips Hue events."""
from __future__ import annotations
from typing import TYPE_CHECKING
@ -47,7 +48,7 @@ async def async_validate_trigger_config(hass: "HomeAssistant", config: ConfigTyp
for conf_entry_id in device_entry.config_entries:
if conf_entry_id not in hass.data[DOMAIN]:
continue
bridge: "HueBridge" = hass.data[DOMAIN][conf_entry_id]
bridge: HueBridge = hass.data[DOMAIN][conf_entry_id]
if bridge.api_version == 1:
return await async_validate_trigger_config_v1(bridge, device_entry, config)
return await async_validate_trigger_config_v2(bridge, device_entry, config)
@ -70,7 +71,7 @@ async def async_attach_trigger(
for conf_entry_id in device_entry.config_entries:
if conf_entry_id not in hass.data[DOMAIN]:
continue
bridge: "HueBridge" = hass.data[DOMAIN][conf_entry_id]
bridge: HueBridge = hass.data[DOMAIN][conf_entry_id]
if bridge.api_version == 1:
return await async_attach_trigger_v1(
bridge, device_entry, config, action, automation_info
@ -98,7 +99,7 @@ async def async_get_triggers(hass: "HomeAssistant", device_id: str):
for conf_entry_id in device_entry.config_entries:
if conf_entry_id not in hass.data[DOMAIN]:
continue
bridge: "HueBridge" = hass.data[DOMAIN][conf_entry_id]
bridge: HueBridge = hass.data[DOMAIN][conf_entry_id]
if bridge.api_version == 1:
return await async_get_triggers_v1(bridge, device_entry)

View File

@ -1,5 +1,5 @@
"""Test the Amber Electric Sensors."""
from typing import AsyncGenerator, List
from typing import AsyncGenerator
from unittest.mock import Mock, patch
from amberelectric.model.current_interval import CurrentInterval
@ -121,7 +121,7 @@ async def test_general_price_sensor(hass: HomeAssistant, setup_general: Mock) ->
assert attributes.get("range_min") is None
assert attributes.get("range_max") is None
with_range: List[CurrentInterval] = GENERAL_CHANNEL
with_range: list[CurrentInterval] = GENERAL_CHANNEL
with_range[0].range = Range(7.8, 12.4)
setup_general.get_current_price.return_value = with_range
@ -208,7 +208,7 @@ async def test_general_forecast_sensor(
assert first_forecast.get("range_min") is None
assert first_forecast.get("range_max") is None
with_range: List[CurrentInterval] = GENERAL_CHANNEL
with_range: list[CurrentInterval] = GENERAL_CHANNEL
with_range[1].range = Range(7.8, 12.4)
setup_general.get_current_price.return_value = with_range

View File

@ -1,5 +1,5 @@
"""Common fixtures for testing greeneye_monitor."""
from typing import Any, Dict
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
@ -20,7 +20,7 @@ def assert_sensor_state(
hass: HomeAssistant,
entity_id: str,
expected_state: str,
attributes: Dict[str, Any] = {},
attributes: dict[str, Any] = {},
) -> None:
"""Assert that the given entity has the expected state and at least the provided attributes."""
state = hass.states.get(entity_id)

View File

@ -1,6 +1,6 @@
"""Test the Nina binary sensor."""
import json
from typing import Any, Dict
from typing import Any
from unittest.mock import patch
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
@ -19,13 +19,13 @@ from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry, load_fixture
ENTRY_DATA: Dict[str, Any] = {
ENTRY_DATA: dict[str, Any] = {
"slots": 5,
"corona_filter": True,
"regions": {"083350000000": "Aach, Stadt"},
}
ENTRY_DATA_NO_CORONA: Dict[str, Any] = {
ENTRY_DATA_NO_CORONA: dict[str, Any] = {
"slots": 5,
"corona_filter": False,
"regions": {"083350000000": "Aach, Stadt"},
@ -35,7 +35,7 @@ ENTRY_DATA_NO_CORONA: Dict[str, Any] = {
async def test_sensors(hass: HomeAssistant) -> None:
"""Test the creation and values of the NINA sensors."""
dummy_response: Dict[str, Any] = json.loads(
dummy_response: dict[str, Any] = json.loads(
load_fixture("sample_warnings.json", "nina")
)
@ -125,7 +125,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
async def test_sensors_without_corona_filter(hass: HomeAssistant) -> None:
"""Test the creation and values of the NINA sensors without the corona filter."""
dummy_response: Dict[str, Any] = json.loads(
dummy_response: dict[str, Any] = json.loads(
load_fixture("nina/sample_warnings.json")
)

View File

@ -1,6 +1,6 @@
"""Test the Nina init file."""
import json
from typing import Any, Dict
from typing import Any
from unittest.mock import patch
from pynina import ApiError
@ -12,7 +12,7 @@ from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry, load_fixture
ENTRY_DATA: Dict[str, Any] = {
ENTRY_DATA: dict[str, Any] = {
"slots": 5,
"corona_filter": True,
"regions": {"083350000000": "Aach, Stadt"},
@ -22,7 +22,7 @@ ENTRY_DATA: Dict[str, Any] = {
async def init_integration(hass) -> MockConfigEntry:
"""Set up the NINA integration in Home Assistant."""
dummy_response: Dict[str, Any] = json.loads(
dummy_response: dict[str, Any] = json.loads(
load_fixture("sample_warnings.json", "nina")
)

View File

@ -1,7 +1,6 @@
"""The tests for the Picnic sensor platform."""
import copy
from datetime import timedelta
from typing import Dict
import unittest
from unittest.mock import patch
@ -324,7 +323,7 @@ class TestPicnicSensor(unittest.IsolatedAsyncioTestCase):
await self._setup_platform(use_default_responses=True)
# Set non-datetime strings as eta
eta_dates: Dict[str, str] = {
eta_dates: dict[str, str] = {
"start": "wrong-time",
"end": "other-malformed-datetime",
}

View File

@ -1,6 +1,6 @@
"""Tests for light platform."""
from __future__ import annotations
from typing import Optional
from unittest.mock import PropertyMock
import pytest
@ -48,7 +48,7 @@ async def test_light_unique_id(hass: HomeAssistant) -> None:
@pytest.mark.parametrize("transition", [2.0, None])
async def test_color_light(hass: HomeAssistant, transition: Optional[float]) -> None:
async def test_color_light(hass: HomeAssistant, transition: float | None) -> None:
"""Test a color light and that all transitions are correctly passed."""
already_migrated_config_entry = MockConfigEntry(
domain=DOMAIN, data={}, unique_id=MAC_ADDRESS

View File

@ -1,5 +1,7 @@
"""Configuration for SSDP tests."""
from typing import Optional, Sequence
from __future__ import annotations
from typing import Sequence
from unittest.mock import AsyncMock, MagicMock, patch
from urllib.parse import urlparse
@ -148,26 +150,26 @@ class MockIgdDevice:
"""Get the device type of this device."""
return self.profile_device.device_type
async def async_get_total_bytes_received(self) -> Optional[int]:
async def async_get_total_bytes_received(self) -> int | None:
"""Get total bytes received."""
self.traffic_times_polled += 1
return self.traffic_data[BYTES_RECEIVED]
async def async_get_total_bytes_sent(self) -> Optional[int]:
async def async_get_total_bytes_sent(self) -> int | None:
"""Get total bytes sent."""
return self.traffic_data[BYTES_SENT]
async def async_get_total_packets_received(self) -> Optional[int]:
async def async_get_total_packets_received(self) -> int | None:
"""Get total packets received."""
return self.traffic_data[PACKETS_RECEIVED]
async def async_get_total_packets_sent(self) -> Optional[int]:
async def async_get_total_packets_sent(self) -> int | None:
"""Get total packets sent."""
return self.traffic_data[PACKETS_SENT]
async def async_get_external_ip_address(
self, services: Optional[Sequence[str]] = None
) -> Optional[str]:
self, services: Sequence[str] | None = None
) -> str | None:
"""
Get the external IP address.
@ -176,8 +178,8 @@ class MockIgdDevice:
return self.status_data[ROUTER_IP]
async def async_get_status_info(
self, services: Optional[Sequence[str]] = None
) -> Optional[StatusInfo]:
self, services: Sequence[str] | None = None
) -> StatusInfo | None:
"""
Get status info.