From 4589be2d11f02ee0af5ffdbe23a4970cd1ffe6ae Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:22:39 +0200 Subject: [PATCH] Improve type hints in group tests (#121174) --- tests/components/group/test_cover.py | 49 ++++++++++++++++++---------- tests/components/group/test_fan.py | 25 +++++++++----- 2 files changed, 48 insertions(+), 26 deletions(-) diff --git a/tests/components/group/test_cover.py b/tests/components/group/test_cover.py index 5b5d8fa873c..c687ca21e2d 100644 --- a/tests/components/group/test_cover.py +++ b/tests/components/group/test_cover.py @@ -2,6 +2,7 @@ import asyncio from datetime import timedelta +from typing import Any import pytest @@ -90,7 +91,9 @@ CONFIG_ATTRIBUTES = { @pytest.fixture -async def setup_comp(hass, config_count): +async def setup_comp( + hass: HomeAssistant, config_count: tuple[dict[str, Any], int] +) -> None: """Set up group cover component.""" config, count = config_count with assert_setup_component(count, DOMAIN): @@ -101,7 +104,8 @@ async def setup_comp(hass, config_count): @pytest.mark.parametrize("config_count", [(CONFIG_ATTRIBUTES, 1)]) -async def test_state(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_state(hass: HomeAssistant) -> None: """Test handling of state. The group state is unknown if all group members are unknown or unavailable. @@ -250,8 +254,9 @@ async def test_state(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_ATTRIBUTES, 1)]) +@pytest.mark.usefixtures("setup_comp") async def test_attributes( - hass: HomeAssistant, entity_registry: er.EntityRegistry, setup_comp + hass: HomeAssistant, entity_registry: er.EntityRegistry ) -> None: """Test handling of state attributes.""" state = hass.states.get(COVER_GROUP) @@ -416,9 +421,8 @@ async def test_attributes( @pytest.mark.parametrize("config_count", [(CONFIG_TILT_ONLY, 2)]) -async def test_cover_that_only_supports_tilt_removed( - hass: HomeAssistant, setup_comp -) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_cover_that_only_supports_tilt_removed(hass: HomeAssistant) -> None: """Test removing a cover that support tilt.""" hass.states.async_set( DEMO_COVER_TILT, @@ -446,7 +450,8 @@ async def test_cover_that_only_supports_tilt_removed( @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) -async def test_open_covers(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_open_covers(hass: HomeAssistant) -> None: """Test open cover function.""" await hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True @@ -467,7 +472,8 @@ async def test_open_covers(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) -async def test_close_covers(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_close_covers(hass: HomeAssistant) -> None: """Test close cover function.""" await hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True @@ -488,7 +494,8 @@ async def test_close_covers(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) -async def test_toggle_covers(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_toggle_covers(hass: HomeAssistant) -> None: """Test toggle cover function.""" # Start covers in open state await hass.services.async_call( @@ -538,7 +545,8 @@ async def test_toggle_covers(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) -async def test_stop_covers(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_stop_covers(hass: HomeAssistant) -> None: """Test stop cover function.""" await hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True @@ -564,7 +572,8 @@ async def test_stop_covers(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) -async def test_set_cover_position(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_set_cover_position(hass: HomeAssistant) -> None: """Test set cover position function.""" await hass.services.async_call( DOMAIN, @@ -587,7 +596,8 @@ async def test_set_cover_position(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) -async def test_open_tilts(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_open_tilts(hass: HomeAssistant) -> None: """Test open tilt function.""" await hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True @@ -607,7 +617,8 @@ async def test_open_tilts(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) -async def test_close_tilts(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_close_tilts(hass: HomeAssistant) -> None: """Test close tilt function.""" await hass.services.async_call( DOMAIN, SERVICE_CLOSE_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True @@ -625,7 +636,8 @@ async def test_close_tilts(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) -async def test_toggle_tilts(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_toggle_tilts(hass: HomeAssistant) -> None: """Test toggle tilt function.""" # Start tilted open await hass.services.async_call( @@ -678,7 +690,8 @@ async def test_toggle_tilts(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) -async def test_stop_tilts(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_stop_tilts(hass: HomeAssistant) -> None: """Test stop tilts function.""" await hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True @@ -702,7 +715,8 @@ async def test_stop_tilts(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) -async def test_set_tilt_positions(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_set_tilt_positions(hass: HomeAssistant) -> None: """Test set tilt position function.""" await hass.services.async_call( DOMAIN, @@ -723,7 +737,8 @@ async def test_set_tilt_positions(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_POS, 2)]) -async def test_is_opening_closing(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_is_opening_closing(hass: HomeAssistant) -> None: """Test is_opening property.""" await hass.services.async_call( DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True diff --git a/tests/components/group/test_fan.py b/tests/components/group/test_fan.py index 6aa6fc2933d..184693f7618 100644 --- a/tests/components/group/test_fan.py +++ b/tests/components/group/test_fan.py @@ -1,6 +1,7 @@ """The tests for the group fan platform.""" import asyncio +from typing import Any from unittest.mock import patch import pytest @@ -102,7 +103,9 @@ CONFIG_ATTRIBUTES = { @pytest.fixture -async def setup_comp(hass, config_count): +async def setup_comp( + hass: HomeAssistant, config_count: tuple[dict[str, Any], int] +) -> None: """Set up group fan component.""" config, count = config_count with assert_setup_component(count, DOMAIN): @@ -113,9 +116,8 @@ async def setup_comp(hass, config_count): @pytest.mark.parametrize("config_count", [(CONFIG_ATTRIBUTES, 1)]) -async def test_state( - hass: HomeAssistant, entity_registry: er.EntityRegistry, setup_comp -) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_state(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None: """Test handling of state. The group state is on if at least one group member is on. @@ -210,7 +212,8 @@ async def test_state( @pytest.mark.parametrize("config_count", [(CONFIG_ATTRIBUTES, 1)]) -async def test_attributes(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_attributes(hass: HomeAssistant) -> None: """Test handling of state attributes.""" state = hass.states.get(FAN_GROUP) assert state.state == STATE_UNAVAILABLE @@ -267,7 +270,8 @@ async def test_attributes(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_FULL_SUPPORT, 2)]) -async def test_direction_oscillating(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_direction_oscillating(hass: HomeAssistant) -> None: """Test handling of direction and oscillating attributes.""" hass.states.async_set( @@ -378,7 +382,8 @@ async def test_direction_oscillating(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_MISSING_FAN, 2)]) -async def test_state_missing_entity_id(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_state_missing_entity_id(hass: HomeAssistant) -> None: """Test we can still setup with a missing entity id.""" state = hass.states.get(FAN_GROUP) await hass.async_block_till_done() @@ -398,7 +403,8 @@ async def test_setup_before_started(hass: HomeAssistant) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_MISSING_FAN, 2)]) -async def test_reload(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_reload(hass: HomeAssistant) -> None: """Test the ability to reload fans.""" await hass.async_block_till_done() await hass.async_start() @@ -421,7 +427,8 @@ async def test_reload(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.parametrize("config_count", [(CONFIG_FULL_SUPPORT, 2)]) -async def test_service_calls(hass: HomeAssistant, setup_comp) -> None: +@pytest.mark.usefixtures("setup_comp") +async def test_service_calls(hass: HomeAssistant) -> None: """Test calling services.""" await hass.services.async_call( DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: FAN_GROUP}, blocking=True