diff --git a/tests/components/google_travel_time/conftest.py b/tests/components/google_travel_time/conftest.py index 141b40eff29..7d1e4791eee 100644 --- a/tests/components/google_travel_time/conftest.py +++ b/tests/components/google_travel_time/conftest.py @@ -1,17 +1,22 @@ """Fixtures for Google Time Travel tests.""" -from unittest.mock import patch +from collections.abc import Generator +from typing import Any +from unittest.mock import MagicMock, patch from googlemaps.exceptions import ApiError, Timeout, TransportError import pytest from homeassistant.components.google_travel_time.const import DOMAIN +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @pytest.fixture(name="mock_config") -async def mock_config_fixture(hass, data, options): +async def mock_config_fixture( + hass: HomeAssistant, data: dict[str, Any], options: dict[str, Any] +) -> MockConfigEntry: """Mock a Google Travel Time config entry.""" config_entry = MockConfigEntry( domain=DOMAIN, @@ -26,7 +31,7 @@ async def mock_config_fixture(hass, data, options): @pytest.fixture(name="bypass_setup") -def bypass_setup_fixture(): +def bypass_setup_fixture() -> Generator[None]: """Bypass entry setup.""" with patch( "homeassistant.components.google_travel_time.async_setup_entry", @@ -36,7 +41,7 @@ def bypass_setup_fixture(): @pytest.fixture(name="bypass_platform_setup") -def bypass_platform_setup_fixture(): +def bypass_platform_setup_fixture() -> Generator[None]: """Bypass platform setup.""" with patch( "homeassistant.components.google_travel_time.sensor.async_setup_entry", @@ -46,7 +51,7 @@ def bypass_platform_setup_fixture(): @pytest.fixture(name="validate_config_entry") -def validate_config_entry_fixture(): +def validate_config_entry_fixture() -> Generator[MagicMock]: """Return valid config entry.""" with ( patch("homeassistant.components.google_travel_time.helpers.Client"), @@ -59,24 +64,24 @@ def validate_config_entry_fixture(): @pytest.fixture(name="invalidate_config_entry") -def invalidate_config_entry_fixture(validate_config_entry): +def invalidate_config_entry_fixture(validate_config_entry: MagicMock) -> None: """Return invalid config entry.""" validate_config_entry.side_effect = ApiError("test") @pytest.fixture(name="invalid_api_key") -def invalid_api_key_fixture(validate_config_entry): +def invalid_api_key_fixture(validate_config_entry: MagicMock) -> None: """Throw a REQUEST_DENIED ApiError.""" validate_config_entry.side_effect = ApiError("REQUEST_DENIED", "Invalid API key.") @pytest.fixture(name="timeout") -def timeout_fixture(validate_config_entry): +def timeout_fixture(validate_config_entry: MagicMock) -> None: """Throw a Timeout exception.""" validate_config_entry.side_effect = Timeout() @pytest.fixture(name="transport_error") -def transport_error_fixture(validate_config_entry): +def transport_error_fixture(validate_config_entry: MagicMock) -> None: """Throw a TransportError exception.""" validate_config_entry.side_effect = TransportError("Unknown.") diff --git a/tests/components/google_travel_time/test_config_flow.py b/tests/components/google_travel_time/test_config_flow.py index 270b82272d8..d16d1c1ffc9 100644 --- a/tests/components/google_travel_time/test_config_flow.py +++ b/tests/components/google_travel_time/test_config_flow.py @@ -29,6 +29,8 @@ from homeassistant.data_entry_flow import FlowResultType from .const import MOCK_CONFIG, RECONFIGURE_CONFIG +from tests.common import MockConfigEntry + async def assert_common_reconfigure_steps( hass: HomeAssistant, reconfigure_result: config_entries.ConfigFlowResult @@ -194,7 +196,7 @@ async def test_malformed_api_key(hass: HomeAssistant) -> None: ], ) @pytest.mark.usefixtures("validate_config_entry", "bypass_setup") -async def test_reconfigure(hass: HomeAssistant, mock_config) -> None: +async def test_reconfigure(hass: HomeAssistant, mock_config: MockConfigEntry) -> None: """Test reconfigure flow.""" reconfigure_result = await hass.config_entries.flow.async_init( DOMAIN, @@ -223,7 +225,7 @@ async def test_reconfigure(hass: HomeAssistant, mock_config) -> None: ) @pytest.mark.usefixtures("invalidate_config_entry") async def test_reconfigure_invalid_config_entry( - hass: HomeAssistant, mock_config + hass: HomeAssistant, mock_config: MockConfigEntry ) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( @@ -259,7 +261,9 @@ async def test_reconfigure_invalid_config_entry( ], ) @pytest.mark.usefixtures("invalid_api_key") -async def test_reconfigure_invalid_api_key(hass: HomeAssistant, mock_config) -> None: +async def test_reconfigure_invalid_api_key( + hass: HomeAssistant, mock_config: MockConfigEntry +) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( DOMAIN, @@ -293,7 +297,9 @@ async def test_reconfigure_invalid_api_key(hass: HomeAssistant, mock_config) -> ], ) @pytest.mark.usefixtures("transport_error") -async def test_reconfigure_transport_error(hass: HomeAssistant, mock_config) -> None: +async def test_reconfigure_transport_error( + hass: HomeAssistant, mock_config: MockConfigEntry +) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( DOMAIN, @@ -327,7 +333,9 @@ async def test_reconfigure_transport_error(hass: HomeAssistant, mock_config) -> ], ) @pytest.mark.usefixtures("timeout") -async def test_reconfigure_timeout(hass: HomeAssistant, mock_config) -> None: +async def test_reconfigure_timeout( + hass: HomeAssistant, mock_config: MockConfigEntry +) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( DOMAIN, @@ -361,7 +369,7 @@ async def test_reconfigure_timeout(hass: HomeAssistant, mock_config) -> None: ], ) @pytest.mark.usefixtures("validate_config_entry") -async def test_options_flow(hass: HomeAssistant, mock_config) -> None: +async def test_options_flow(hass: HomeAssistant, mock_config: MockConfigEntry) -> None: """Test options flow.""" result = await hass.config_entries.options.async_init( mock_config.entry_id, data=None @@ -422,7 +430,9 @@ async def test_options_flow(hass: HomeAssistant, mock_config) -> None: ], ) @pytest.mark.usefixtures("validate_config_entry") -async def test_options_flow_departure_time(hass: HomeAssistant, mock_config) -> None: +async def test_options_flow_departure_time( + hass: HomeAssistant, mock_config: MockConfigEntry +) -> None: """Test options flow with departure time.""" result = await hass.config_entries.options.async_init( mock_config.entry_id, data=None @@ -492,7 +502,9 @@ async def test_options_flow_departure_time(hass: HomeAssistant, mock_config) -> ], ) @pytest.mark.usefixtures("validate_config_entry") -async def test_reset_departure_time(hass: HomeAssistant, mock_config) -> None: +async def test_reset_departure_time( + hass: HomeAssistant, mock_config: MockConfigEntry +) -> None: """Test resetting departure time.""" result = await hass.config_entries.options.async_init( mock_config.entry_id, data=None @@ -538,7 +550,9 @@ async def test_reset_departure_time(hass: HomeAssistant, mock_config) -> None: ], ) @pytest.mark.usefixtures("validate_config_entry") -async def test_reset_arrival_time(hass: HomeAssistant, mock_config) -> None: +async def test_reset_arrival_time( + hass: HomeAssistant, mock_config: MockConfigEntry +) -> None: """Test resetting arrival time.""" result = await hass.config_entries.options.async_init( mock_config.entry_id, data=None @@ -582,7 +596,9 @@ async def test_reset_arrival_time(hass: HomeAssistant, mock_config) -> None: ], ) @pytest.mark.usefixtures("validate_config_entry") -async def test_reset_options_flow_fields(hass: HomeAssistant, mock_config) -> None: +async def test_reset_options_flow_fields( + hass: HomeAssistant, mock_config: MockConfigEntry +) -> None: """Test resetting options flow fields that are not time related to None.""" result = await hass.config_entries.options.async_init( mock_config.entry_id, data=None diff --git a/tests/components/google_travel_time/test_sensor.py b/tests/components/google_travel_time/test_sensor.py index 57f3d7a0b98..5ac9ecad482 100644 --- a/tests/components/google_travel_time/test_sensor.py +++ b/tests/components/google_travel_time/test_sensor.py @@ -1,6 +1,7 @@ """Test the Google Maps Travel Time sensors.""" -from unittest.mock import patch +from collections.abc import Generator +from unittest.mock import MagicMock, patch import pytest @@ -25,7 +26,7 @@ from tests.common import MockConfigEntry @pytest.fixture(name="mock_update") -def mock_update_fixture(): +def mock_update_fixture() -> Generator[MagicMock]: """Mock an update to the sensor.""" with ( patch("homeassistant.components.google_travel_time.sensor.Client"), @@ -56,7 +57,7 @@ def mock_update_fixture(): @pytest.fixture(name="mock_update_duration") -def mock_update_duration_fixture(mock_update): +def mock_update_duration_fixture(mock_update: MagicMock) -> MagicMock: """Mock an update to the sensor returning no duration_in_traffic.""" mock_update.return_value = { "rows": [ @@ -77,7 +78,7 @@ def mock_update_duration_fixture(mock_update): @pytest.fixture(name="mock_update_empty") -def mock_update_empty_fixture(mock_update): +def mock_update_empty_fixture(mock_update: MagicMock) -> MagicMock: """Mock an update to the sensor with an empty response.""" mock_update.return_value = None return mock_update