From 10ee554f1f8b2bd8c399b6caa4373afdef75be0a Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 8 Jul 2024 13:30:29 +0200 Subject: [PATCH] Improve type hints in logi_circle tests (#121518) --- .../logi_circle/test_config_flow.py | 26 ++++++++++++------- tests/components/logi_circle/test_init.py | 10 +++---- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/components/logi_circle/test_config_flow.py b/tests/components/logi_circle/test_config_flow.py index 2525354598d..ab4bae02ad6 100644 --- a/tests/components/logi_circle/test_config_flow.py +++ b/tests/components/logi_circle/test_config_flow.py @@ -1,8 +1,10 @@ """Tests for Logi Circle config flow.""" import asyncio +from collections.abc import Generator from http import HTTPStatus -from unittest.mock import AsyncMock, Mock, patch +from typing import Any +from unittest.mock import AsyncMock, MagicMock, Mock, patch import pytest @@ -24,13 +26,13 @@ from tests.common import MockConfigEntry class MockRequest: """Mock request passed to HomeAssistantView.""" - def __init__(self, hass, query): + def __init__(self, hass: HomeAssistant, query: dict[str, Any]) -> None: """Init request object.""" self.app = {KEY_HASS: hass} self.query = query -def init_config_flow(hass): +def init_config_flow(hass: HomeAssistant) -> config_flow.LogiCircleFlowHandler: """Init a configuration flow.""" config_flow.register_flow_implementation( hass, @@ -48,7 +50,7 @@ def init_config_flow(hass): @pytest.fixture -def mock_logi_circle(): +def mock_logi_circle() -> Generator[MagicMock]: """Mock logi_circle.""" with patch( "homeassistant.components.logi_circle.config_flow.LogiCircle" @@ -63,7 +65,8 @@ def mock_logi_circle(): yield LogiCircle -async def test_step_import(hass: HomeAssistant, mock_logi_circle) -> None: +@pytest.mark.usefixtures("mock_logi_circle") +async def test_step_import(hass: HomeAssistant) -> None: """Test that we trigger import when configuring with client.""" flow = init_config_flow(hass) @@ -72,7 +75,8 @@ async def test_step_import(hass: HomeAssistant, mock_logi_circle) -> None: assert result["step_id"] == "auth" -async def test_full_flow_implementation(hass: HomeAssistant, mock_logi_circle) -> None: +@pytest.mark.usefixtures("mock_logi_circle") +async def test_full_flow_implementation(hass: HomeAssistant) -> None: """Test registering an implementation and finishing flow works.""" config_flow.register_flow_implementation( hass, @@ -154,7 +158,10 @@ async def test_abort_if_already_setup(hass: HomeAssistant) -> None: ], ) async def test_abort_if_authorize_fails( - hass: HomeAssistant, mock_logi_circle, side_effect, error + hass: HomeAssistant, + mock_logi_circle: MagicMock, + side_effect: type[Exception], + error: str, ) -> None: """Test we abort if authorizing fails.""" flow = init_config_flow(hass) @@ -177,7 +184,8 @@ async def test_not_pick_implementation_if_only_one(hass: HomeAssistant) -> None: assert result["step_id"] == "auth" -async def test_gen_auth_url(hass: HomeAssistant, mock_logi_circle) -> None: +@pytest.mark.usefixtures("mock_logi_circle") +async def test_gen_auth_url(hass: HomeAssistant) -> None: """Test generating authorize URL from Logi Circle API.""" config_flow.register_flow_implementation( hass, @@ -206,7 +214,7 @@ async def test_callback_view_rejects_missing_code(hass: HomeAssistant) -> None: async def test_callback_view_accepts_code( - hass: HomeAssistant, mock_logi_circle + hass: HomeAssistant, mock_logi_circle: MagicMock ) -> None: """Test the auth callback view handles requests with auth code.""" init_config_flow(hass) diff --git a/tests/components/logi_circle/test_init.py b/tests/components/logi_circle/test_init.py index f8bf8306609..d953acdf744 100644 --- a/tests/components/logi_circle/test_init.py +++ b/tests/components/logi_circle/test_init.py @@ -1,7 +1,8 @@ """Tests for the Logi Circle integration.""" import asyncio -from unittest.mock import AsyncMock, Mock, patch +from collections.abc import Generator +from unittest.mock import AsyncMock, MagicMock, Mock, patch import pytest @@ -14,14 +15,14 @@ from tests.common import MockConfigEntry @pytest.fixture(name="disable_platforms") -async def disable_platforms_fixture(hass): +def disable_platforms_fixture() -> Generator[None]: """Disable logi_circle platforms.""" with patch("homeassistant.components.logi_circle.PLATFORMS", []): yield @pytest.fixture -def mock_logi_circle(): +def mock_logi_circle() -> Generator[MagicMock]: """Mock logi_circle.""" auth_provider_mock = Mock() @@ -37,11 +38,10 @@ def mock_logi_circle(): yield LogiCircle +@pytest.mark.usefixtures("disable_platforms", "mock_logi_circle") async def test_repair_issue( hass: HomeAssistant, issue_registry: ir.IssueRegistry, - disable_platforms, - mock_logi_circle, ) -> None: """Test the LogiCircle configuration entry loading/unloading handles the repair.""" config_entry = MockConfigEntry(