Improve type hints in home_connect tests (#121014)

This commit is contained in:
epenet 2024-07-02 22:19:33 +02:00 committed by GitHub
parent bdc6805771
commit 476efb1d36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 22 deletions

View File

@ -94,7 +94,7 @@ async def bypass_throttle(hass: HomeAssistant, config_entry: MockConfigEntry):
@pytest.fixture(name="bypass_throttle") @pytest.fixture(name="bypass_throttle")
def mock_bypass_throttle(): def mock_bypass_throttle() -> Generator[None]:
"""Fixture to bypass the throttle decorator in __init__.""" """Fixture to bypass the throttle decorator in __init__."""
with patch( with patch(
"homeassistant.components.home_connect.update_all_devices", "homeassistant.components.home_connect.update_all_devices",
@ -122,7 +122,7 @@ async def mock_integration_setup(
@pytest.fixture(name="get_appliances") @pytest.fixture(name="get_appliances")
def mock_get_appliances() -> Generator[None, Any, None]: def mock_get_appliances() -> Generator[MagicMock]:
"""Mock ConfigEntryAuth parent (HomeAssistantAPI) method.""" """Mock ConfigEntryAuth parent (HomeAssistantAPI) method."""
with patch( with patch(
"homeassistant.components.home_connect.api.ConfigEntryAuth.get_appliances", "homeassistant.components.home_connect.api.ConfigEntryAuth.get_appliances",

View File

@ -1,7 +1,6 @@
"""Tests for home_connect binary_sensor entities.""" """Tests for home_connect binary_sensor entities."""
from collections.abc import Awaitable, Callable, Generator from collections.abc import Awaitable, Callable
from typing import Any
from unittest.mock import MagicMock, Mock from unittest.mock import MagicMock, Mock
import pytest import pytest
@ -26,9 +25,8 @@ def platforms() -> list[str]:
return [Platform.BINARY_SENSOR] return [Platform.BINARY_SENSOR]
@pytest.mark.usefixtures("bypass_throttle")
async def test_binary_sensors( async def test_binary_sensors(
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]], integration_setup: Callable[[], Awaitable[bool]],
setup_credentials: None, setup_credentials: None,
@ -51,10 +49,10 @@ async def test_binary_sensors(
("", "unavailable"), ("", "unavailable"),
], ],
) )
@pytest.mark.usefixtures("bypass_throttle")
async def test_binary_sensors_door_states( async def test_binary_sensors_door_states(
expected: str, expected: str,
state: str, state: str,
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant, hass: HomeAssistant,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]], integration_setup: Callable[[], Awaitable[bool]],

View File

@ -1,6 +1,6 @@
"""Test the integration init functionality.""" """Test the integration init functionality."""
from collections.abc import Awaitable, Callable, Generator from collections.abc import Awaitable, Callable
from typing import Any from typing import Any
from unittest.mock import MagicMock, Mock from unittest.mock import MagicMock, Mock
@ -117,8 +117,8 @@ SERVICE_APPLIANCE_METHOD_MAPPING = {
} }
@pytest.mark.usefixtures("bypass_throttle")
async def test_api_setup( async def test_api_setup(
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant, hass: HomeAssistant,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]], integration_setup: Callable[[], Awaitable[bool]],
@ -137,9 +137,8 @@ async def test_api_setup(
assert config_entry.state == ConfigEntryState.NOT_LOADED assert config_entry.state == ConfigEntryState.NOT_LOADED
@pytest.mark.usefixtures("bypass_throttle")
async def test_exception_handling( async def test_exception_handling(
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant,
integration_setup: Callable[[], Awaitable[bool]], integration_setup: Callable[[], Awaitable[bool]],
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
setup_credentials: None, setup_credentials: None,
@ -154,8 +153,8 @@ async def test_exception_handling(
@pytest.mark.parametrize("token_expiration_time", [12345]) @pytest.mark.parametrize("token_expiration_time", [12345])
@pytest.mark.usefixtures("bypass_throttle")
async def test_token_refresh_success( async def test_token_refresh_success(
bypass_throttle: Generator[None, Any, None],
integration_setup: Callable[[], Awaitable[bool]], integration_setup: Callable[[], Awaitable[bool]],
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
aioclient_mock: AiohttpClientMocker, aioclient_mock: AiohttpClientMocker,
@ -227,9 +226,8 @@ async def test_update_throttle(
assert get_appliances.call_count == 0 assert get_appliances.call_count == 0
@pytest.mark.usefixtures("bypass_throttle")
async def test_http_error( async def test_http_error(
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]], integration_setup: Callable[[], Awaitable[bool]],
setup_credentials: None, setup_credentials: None,
@ -247,9 +245,9 @@ async def test_http_error(
"service_call", "service_call",
SERVICE_KV_CALL_PARAMS + SERVICE_COMMAND_CALL_PARAMS + SERVICE_PROGRAM_CALL_PARAMS, SERVICE_KV_CALL_PARAMS + SERVICE_COMMAND_CALL_PARAMS + SERVICE_PROGRAM_CALL_PARAMS,
) )
@pytest.mark.usefixtures("bypass_throttle")
async def test_services( async def test_services(
service_call: list[dict[str, Any]], service_call: list[dict[str, Any]],
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
@ -279,8 +277,8 @@ async def test_services(
) )
@pytest.mark.usefixtures("bypass_throttle")
async def test_services_exception( async def test_services_exception(
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant, hass: HomeAssistant,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]], integration_setup: Callable[[], Awaitable[bool]],

View File

@ -1,7 +1,6 @@
"""Tests for home_connect sensor entities.""" """Tests for home_connect sensor entities."""
from collections.abc import Awaitable, Callable, Generator from collections.abc import Awaitable, Callable
from typing import Any
from unittest.mock import MagicMock, Mock from unittest.mock import MagicMock, Mock
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
@ -69,9 +68,8 @@ def platforms() -> list[str]:
return [Platform.SENSOR] return [Platform.SENSOR]
@pytest.mark.usefixtures("bypass_throttle")
async def test_sensors( async def test_sensors(
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]], integration_setup: Callable[[], Awaitable[bool]],
setup_credentials: None, setup_credentials: None,
@ -131,12 +129,12 @@ ENTITY_ID_STATES = {
) )
), ),
) )
@pytest.mark.usefixtures("bypass_throttle")
async def test_event_sensors( async def test_event_sensors(
appliance: Mock, appliance: Mock,
states: tuple, states: tuple,
event_run: dict, event_run: dict,
freezer: FrozenDateTimeFactory, freezer: FrozenDateTimeFactory,
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant, hass: HomeAssistant,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]], integration_setup: Callable[[], Awaitable[bool]],
@ -180,10 +178,10 @@ ENTITY_ID_EDGE_CASE_STATES = [
@pytest.mark.parametrize("appliance", [TEST_HC_APP], indirect=True) @pytest.mark.parametrize("appliance", [TEST_HC_APP], indirect=True)
@pytest.mark.usefixtures("bypass_throttle")
async def test_remaining_prog_time_edge_cases( async def test_remaining_prog_time_edge_cases(
appliance: Mock, appliance: Mock,
freezer: FrozenDateTimeFactory, freezer: FrozenDateTimeFactory,
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant, hass: HomeAssistant,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]], integration_setup: Callable[[], Awaitable[bool]],