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.""" """Provides device automations for Philips Hue events."""
from __future__ import annotations
from typing import TYPE_CHECKING 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: for conf_entry_id in device_entry.config_entries:
if conf_entry_id not in hass.data[DOMAIN]: if conf_entry_id not in hass.data[DOMAIN]:
continue continue
bridge: "HueBridge" = hass.data[DOMAIN][conf_entry_id] bridge: HueBridge = hass.data[DOMAIN][conf_entry_id]
if bridge.api_version == 1: if bridge.api_version == 1:
return await async_validate_trigger_config_v1(bridge, device_entry, config) return await async_validate_trigger_config_v1(bridge, device_entry, config)
return await async_validate_trigger_config_v2(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: for conf_entry_id in device_entry.config_entries:
if conf_entry_id not in hass.data[DOMAIN]: if conf_entry_id not in hass.data[DOMAIN]:
continue continue
bridge: "HueBridge" = hass.data[DOMAIN][conf_entry_id] bridge: HueBridge = hass.data[DOMAIN][conf_entry_id]
if bridge.api_version == 1: if bridge.api_version == 1:
return await async_attach_trigger_v1( return await async_attach_trigger_v1(
bridge, device_entry, config, action, automation_info 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: for conf_entry_id in device_entry.config_entries:
if conf_entry_id not in hass.data[DOMAIN]: if conf_entry_id not in hass.data[DOMAIN]:
continue continue
bridge: "HueBridge" = hass.data[DOMAIN][conf_entry_id] bridge: HueBridge = hass.data[DOMAIN][conf_entry_id]
if bridge.api_version == 1: if bridge.api_version == 1:
return await async_get_triggers_v1(bridge, device_entry) return await async_get_triggers_v1(bridge, device_entry)

View file

@ -1,5 +1,5 @@
"""Test the Amber Electric Sensors.""" """Test the Amber Electric Sensors."""
from typing import AsyncGenerator, List from typing import AsyncGenerator
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
from amberelectric.model.current_interval import CurrentInterval 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_min") is None
assert attributes.get("range_max") 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) with_range[0].range = Range(7.8, 12.4)
setup_general.get_current_price.return_value = with_range 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_min") is None
assert first_forecast.get("range_max") 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) with_range[1].range = Range(7.8, 12.4)
setup_general.get_current_price.return_value = with_range setup_general.get_current_price.return_value = with_range

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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