Improve type hints in kitchen_sink tests (#121509)

pull/121516/head^2
epenet 2024-07-08 12:54:43 +02:00 committed by GitHub
parent c4c623ea99
commit 148803460b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 13 deletions

View File

@ -7,7 +7,7 @@ from unittest.mock import ANY
import pytest import pytest
from homeassistant.components.kitchen_sink import DOMAIN from homeassistant.components.kitchen_sink import DOMAIN
from homeassistant.components.recorder import Recorder, get_instance from homeassistant.components.recorder import get_instance
from homeassistant.components.recorder.statistics import ( from homeassistant.components.recorder.statistics import (
async_add_external_statistics, async_add_external_statistics,
get_last_statistics, get_last_statistics,
@ -24,14 +24,13 @@ from tests.typing import ClientSessionGenerator, WebSocketGenerator
@pytest.fixture @pytest.fixture
def mock_history(hass): def mock_history(hass: HomeAssistant) -> None:
"""Mock history component loaded.""" """Mock history component loaded."""
hass.config.components.add("history") hass.config.components.add("history")
async def test_demo_statistics( @pytest.mark.usefixtures("recorder_mock", "mock_history")
recorder_mock: Recorder, mock_history, hass: HomeAssistant async def test_demo_statistics(hass: HomeAssistant) -> None:
) -> None:
"""Test that the kitchen sink component makes some statistics available.""" """Test that the kitchen sink component makes some statistics available."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}}) assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
await hass.async_block_till_done() await hass.async_block_till_done()
@ -63,9 +62,8 @@ async def test_demo_statistics(
} in statistic_ids } in statistic_ids
async def test_demo_statistics_growth( @pytest.mark.usefixtures("recorder_mock", "mock_history")
recorder_mock: Recorder, mock_history, hass: HomeAssistant async def test_demo_statistics_growth(hass: HomeAssistant) -> None:
) -> None:
"""Test that the kitchen sink sum statistics adds to the previous state.""" """Test that the kitchen sink sum statistics adds to the previous state."""
hass.config.units = US_CUSTOMARY_SYSTEM hass.config.units = US_CUSTOMARY_SYSTEM
@ -104,8 +102,8 @@ async def test_demo_statistics_growth(
@pytest.mark.freeze_time("2023-10-21") @pytest.mark.freeze_time("2023-10-21")
@pytest.mark.usefixtures("mock_history")
async def test_issues_created( async def test_issues_created(
mock_history,
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,

View File

@ -1,5 +1,6 @@
"""The tests for the demo switch component.""" """The tests for the demo switch component."""
from collections.abc import Generator
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
@ -20,7 +21,7 @@ SWITCH_ENTITY_IDS = ["switch.outlet_1", "switch.outlet_2"]
@pytest.fixture @pytest.fixture
async def switch_only() -> None: def switch_only() -> Generator[None]:
"""Enable only the switch platform.""" """Enable only the switch platform."""
with patch( with patch(
"homeassistant.components.kitchen_sink.COMPONENTS_WITH_DEMO_PLATFORM", "homeassistant.components.kitchen_sink.COMPONENTS_WITH_DEMO_PLATFORM",
@ -30,7 +31,7 @@ async def switch_only() -> None:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def setup_comp(hass, switch_only): async def setup_comp(hass: HomeAssistant, switch_only: None) -> None:
"""Set up demo component.""" """Set up demo component."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}}) assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
await hass.async_block_till_done() await hass.async_block_till_done()
@ -55,7 +56,7 @@ async def test_state(
@pytest.mark.parametrize("switch_entity_id", SWITCH_ENTITY_IDS) @pytest.mark.parametrize("switch_entity_id", SWITCH_ENTITY_IDS)
async def test_turn_on(hass: HomeAssistant, switch_entity_id) -> None: async def test_turn_on(hass: HomeAssistant, switch_entity_id: str) -> None:
"""Test switch turn on method.""" """Test switch turn on method."""
await hass.services.async_call( await hass.services.async_call(
SWITCH_DOMAIN, SWITCH_DOMAIN,
@ -79,7 +80,7 @@ async def test_turn_on(hass: HomeAssistant, switch_entity_id) -> None:
@pytest.mark.parametrize("switch_entity_id", SWITCH_ENTITY_IDS) @pytest.mark.parametrize("switch_entity_id", SWITCH_ENTITY_IDS)
async def test_turn_off(hass: HomeAssistant, switch_entity_id) -> None: async def test_turn_off(hass: HomeAssistant, switch_entity_id: str) -> None:
"""Test switch turn off method.""" """Test switch turn off method."""
await hass.services.async_call( await hass.services.async_call(
SWITCH_DOMAIN, SWITCH_DOMAIN,