From d0ce0d562e175b0afd599b645bb4668c9f0fe1a8 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 28 Jun 2024 13:34:26 +0200 Subject: [PATCH] Improve type hints in flo tests (#120730) --- tests/components/flo/conftest.py | 2 +- tests/components/flo/test_binary_sensor.py | 7 ++++++- tests/components/flo/test_config_flow.py | 5 ++++- tests/components/flo/test_device.py | 11 ++++++----- tests/components/flo/test_init.py | 9 ++++++--- tests/components/flo/test_sensor.py | 12 +++++++----- tests/components/flo/test_services.py | 5 +++-- tests/components/flo/test_switch.py | 7 ++++++- 8 files changed, 39 insertions(+), 19 deletions(-) diff --git a/tests/components/flo/conftest.py b/tests/components/flo/conftest.py index 33d467a2abf..66b56d1f10b 100644 --- a/tests/components/flo/conftest.py +++ b/tests/components/flo/conftest.py @@ -16,7 +16,7 @@ from tests.test_util.aiohttp import AiohttpClientMocker @pytest.fixture -def config_entry(hass): +def config_entry() -> MockConfigEntry: """Config entry version 1 fixture.""" return MockConfigEntry( domain=FLO_DOMAIN, diff --git a/tests/components/flo/test_binary_sensor.py b/tests/components/flo/test_binary_sensor.py index d3032cde1b5..23a84734b0d 100644 --- a/tests/components/flo/test_binary_sensor.py +++ b/tests/components/flo/test_binary_sensor.py @@ -1,5 +1,7 @@ """Test Flo by Moen binary sensor entities.""" +import pytest + from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN from homeassistant.const import ( ATTR_FRIENDLY_NAME, @@ -13,9 +15,12 @@ from homeassistant.setup import async_setup_component from .common import TEST_PASSWORD, TEST_USER_ID +from tests.common import MockConfigEntry + +@pytest.mark.usefixtures("aioclient_mock_fixture") async def test_binary_sensors( - hass: HomeAssistant, config_entry, aioclient_mock_fixture + hass: HomeAssistant, config_entry: MockConfigEntry ) -> None: """Test Flo by Moen sensors.""" config_entry.add_to_hass(hass) diff --git a/tests/components/flo/test_config_flow.py b/tests/components/flo/test_config_flow.py index 99f8f315fb2..f9237e979a6 100644 --- a/tests/components/flo/test_config_flow.py +++ b/tests/components/flo/test_config_flow.py @@ -5,6 +5,8 @@ import json import time from unittest.mock import patch +import pytest + from homeassistant import config_entries from homeassistant.components.flo.const import DOMAIN from homeassistant.const import CONTENT_TYPE_JSON @@ -16,7 +18,8 @@ from .common import TEST_EMAIL_ADDRESS, TEST_PASSWORD, TEST_TOKEN, TEST_USER_ID from tests.test_util.aiohttp import AiohttpClientMocker -async def test_form(hass: HomeAssistant, aioclient_mock_fixture) -> None: +@pytest.mark.usefixtures("aioclient_mock_fixture") +async def test_form(hass: HomeAssistant) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( diff --git a/tests/components/flo/test_device.py b/tests/components/flo/test_device.py index 6248bdcd8f9..c3e26e77370 100644 --- a/tests/components/flo/test_device.py +++ b/tests/components/flo/test_device.py @@ -5,6 +5,7 @@ from unittest.mock import patch from aioflo.errors import RequestError from freezegun.api import FrozenDateTimeFactory +import pytest from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN from homeassistant.components.flo.coordinator import FloDeviceDataUpdateCoordinator @@ -14,14 +15,14 @@ from homeassistant.setup import async_setup_component from .common import TEST_PASSWORD, TEST_USER_ID -from tests.common import async_fire_time_changed +from tests.common import MockConfigEntry, async_fire_time_changed from tests.test_util.aiohttp import AiohttpClientMocker +@pytest.mark.usefixtures("aioclient_mock_fixture") async def test_device( hass: HomeAssistant, - config_entry, - aioclient_mock_fixture, + config_entry: MockConfigEntry, aioclient_mock: AiohttpClientMocker, freezer: FrozenDateTimeFactory, ) -> None: @@ -90,10 +91,10 @@ async def test_device( assert aioclient_mock.call_count == call_count + 6 +@pytest.mark.usefixtures("aioclient_mock_fixture") async def test_device_failures( hass: HomeAssistant, - config_entry, - aioclient_mock_fixture, + config_entry: MockConfigEntry, aioclient_mock: AiohttpClientMocker, freezer: FrozenDateTimeFactory, ) -> None: diff --git a/tests/components/flo/test_init.py b/tests/components/flo/test_init.py index 599a91b80fb..805a6278395 100644 --- a/tests/components/flo/test_init.py +++ b/tests/components/flo/test_init.py @@ -1,5 +1,7 @@ """Test init.""" +import pytest + from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant @@ -7,10 +9,11 @@ from homeassistant.setup import async_setup_component from .common import TEST_PASSWORD, TEST_USER_ID +from tests.common import MockConfigEntry -async def test_setup_entry( - hass: HomeAssistant, config_entry, aioclient_mock_fixture -) -> None: + +@pytest.mark.usefixtures("aioclient_mock_fixture") +async def test_setup_entry(hass: HomeAssistant, config_entry: MockConfigEntry) -> None: """Test migration of config entry from v1.""" config_entry.add_to_hass(hass) assert await async_setup_component( diff --git a/tests/components/flo/test_sensor.py b/tests/components/flo/test_sensor.py index 5fe388c62e1..0c763927296 100644 --- a/tests/components/flo/test_sensor.py +++ b/tests/components/flo/test_sensor.py @@ -1,5 +1,7 @@ """Test Flo by Moen sensor entities.""" +import pytest + from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass from homeassistant.const import ATTR_ENTITY_ID, CONF_PASSWORD, CONF_USERNAME @@ -9,12 +11,12 @@ from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM from .common import TEST_PASSWORD, TEST_USER_ID +from tests.common import MockConfigEntry from tests.test_util.aiohttp import AiohttpClientMocker -async def test_sensors( - hass: HomeAssistant, config_entry, aioclient_mock_fixture -) -> None: +@pytest.mark.usefixtures("aioclient_mock_fixture") +async def test_sensors(hass: HomeAssistant, config_entry: MockConfigEntry) -> None: """Test Flo by Moen sensors.""" hass.config.units = US_CUSTOMARY_SYSTEM config_entry.add_to_hass(hass) @@ -85,10 +87,10 @@ async def test_sensors( ) +@pytest.mark.usefixtures("aioclient_mock_fixture") async def test_manual_update_entity( hass: HomeAssistant, - config_entry, - aioclient_mock_fixture, + config_entry: MockConfigEntry, aioclient_mock: AiohttpClientMocker, ) -> None: """Test manual update entity via service homeasasistant/update_entity.""" diff --git a/tests/components/flo/test_services.py b/tests/components/flo/test_services.py index d8837d9c6b6..565f39f69fe 100644 --- a/tests/components/flo/test_services.py +++ b/tests/components/flo/test_services.py @@ -19,15 +19,16 @@ from homeassistant.setup import async_setup_component from .common import TEST_PASSWORD, TEST_USER_ID +from tests.common import MockConfigEntry from tests.test_util.aiohttp import AiohttpClientMocker SWITCH_ENTITY_ID = "switch.smart_water_shutoff_shutoff_valve" +@pytest.mark.usefixtures("aioclient_mock_fixture") async def test_services( hass: HomeAssistant, - config_entry, - aioclient_mock_fixture, + config_entry: MockConfigEntry, aioclient_mock: AiohttpClientMocker, ) -> None: """Test Flo services.""" diff --git a/tests/components/flo/test_switch.py b/tests/components/flo/test_switch.py index 85f7ea0f317..02ab93f9e67 100644 --- a/tests/components/flo/test_switch.py +++ b/tests/components/flo/test_switch.py @@ -1,5 +1,7 @@ """Tests for the switch domain for Flo by Moen.""" +import pytest + from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN from homeassistant.components.switch import DOMAIN from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, STATE_OFF, STATE_ON @@ -8,9 +10,12 @@ from homeassistant.setup import async_setup_component from .common import TEST_PASSWORD, TEST_USER_ID +from tests.common import MockConfigEntry + +@pytest.mark.usefixtures("aioclient_mock_fixture") async def test_valve_switches( - hass: HomeAssistant, config_entry, aioclient_mock_fixture + hass: HomeAssistant, config_entry: MockConfigEntry ) -> None: """Test Flo by Moen valve switches.""" config_entry.add_to_hass(hass)