Improve type hints in zamg tests (#119042)

This commit is contained in:
epenet 2024-06-07 10:25:11 +02:00 committed by GitHub
parent 539b9d76fc
commit d5a68ad311
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 44 deletions

View File

@ -37,7 +37,7 @@ def mock_setup_entry() -> Generator[None]:
@pytest.fixture
def mock_zamg_config_flow(request: pytest.FixtureRequest) -> Generator[MagicMock]:
def mock_zamg_config_flow() -> Generator[MagicMock]:
"""Return a mocked Zamg client."""
with patch(
"homeassistant.components.zamg.sensor.ZamgData", autospec=True
@ -51,7 +51,7 @@ def mock_zamg_config_flow(request: pytest.FixtureRequest) -> Generator[MagicMock
@pytest.fixture
def mock_zamg(request: pytest.FixtureRequest) -> Generator[MagicMock]:
def mock_zamg() -> Generator[MagicMock]:
"""Return a mocked Zamg client."""
with patch(
@ -70,7 +70,7 @@ def mock_zamg(request: pytest.FixtureRequest) -> Generator[MagicMock]:
@pytest.fixture
def mock_zamg_coordinator(request: pytest.FixtureRequest) -> Generator[MagicMock]:
def mock_zamg_coordinator() -> Generator[MagicMock]:
"""Return a mocked Zamg client."""
with patch(
@ -89,22 +89,7 @@ def mock_zamg_coordinator(request: pytest.FixtureRequest) -> Generator[MagicMock
@pytest.fixture
def mock_zamg_stations(request: pytest.FixtureRequest) -> Generator[MagicMock]:
"""Return a mocked Zamg client."""
with patch(
"homeassistant.components.zamg.config_flow.ZamgData.zamg_stations"
) as zamg_mock:
zamg_mock.return_value = {
"11240": (46.99305556, 15.43916667, "GRAZ-FLUGHAFEN"),
"11244": (46.87222222, 15.90361111, "BAD GLEICHENBERG"),
}
yield zamg_mock
@pytest.fixture
async def init_integration(
hass: HomeAssistant,
) -> MockConfigEntry:
async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
"""Set up the Zamg integration for testing."""
mock_config_entry.add_to_hass(hass)

View File

@ -2,6 +2,7 @@
from unittest.mock import MagicMock
import pytest
from zamg.exceptions import ZamgApiError
from homeassistant.components.zamg.const import CONF_STATION_ID, DOMAIN, LOGGER
@ -12,11 +13,8 @@ from homeassistant.data_entry_flow import FlowResultType
from .conftest import TEST_STATION_ID
async def test_full_user_flow_implementation(
hass: HomeAssistant,
mock_zamg: MagicMock,
mock_setup_entry: None,
) -> None:
@pytest.mark.usefixtures("mock_zamg", "mock_setup_entry")
async def test_full_user_flow_implementation(hass: HomeAssistant) -> None:
"""Test the full manual user flow from start to finish."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
@ -37,11 +35,8 @@ async def test_full_user_flow_implementation(
assert result["result"].unique_id == TEST_STATION_ID
async def test_error_closest_station(
hass: HomeAssistant,
mock_zamg: MagicMock,
mock_setup_entry: None,
) -> None:
@pytest.mark.usefixtures("mock_setup_entry")
async def test_error_closest_station(hass: HomeAssistant, mock_zamg: MagicMock) -> None:
"""Test with error of reading from Zamg."""
mock_zamg.closest_station.side_effect = ZamgApiError
result = await hass.config_entries.flow.async_init(
@ -52,11 +47,8 @@ async def test_error_closest_station(
assert result.get("reason") == "cannot_connect"
async def test_error_update(
hass: HomeAssistant,
mock_zamg: MagicMock,
mock_setup_entry: None,
) -> None:
@pytest.mark.usefixtures("mock_setup_entry")
async def test_error_update(hass: HomeAssistant, mock_zamg: MagicMock) -> None:
"""Test with error of reading from Zamg."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
@ -75,11 +67,8 @@ async def test_error_update(
assert result.get("reason") == "cannot_connect"
async def test_user_flow_duplicate(
hass: HomeAssistant,
mock_zamg: MagicMock,
mock_setup_entry: None,
) -> None:
@pytest.mark.usefixtures("mock_zamg", "mock_setup_entry")
async def test_user_flow_duplicate(hass: HomeAssistant) -> None:
"""Test the full manual user flow from start to finish."""
result = await hass.config_entries.flow.async_init(
DOMAIN,

View File

@ -1,7 +1,5 @@
"""Test Zamg component init."""
from unittest.mock import MagicMock
import pytest
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
@ -62,10 +60,10 @@ from tests.common import MockConfigEntry
),
],
)
@pytest.mark.usefixtures("mock_zamg_coordinator")
async def test_migrate_unique_ids(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_zamg_coordinator: MagicMock,
entitydata: dict,
old_unique_id: str,
new_unique_id: str,
@ -108,10 +106,10 @@ async def test_migrate_unique_ids(
),
],
)
@pytest.mark.usefixtures("mock_zamg_coordinator")
async def test_dont_migrate_unique_ids(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_zamg_coordinator: MagicMock,
entitydata: dict,
old_unique_id: str,
new_unique_id: str,
@ -167,10 +165,10 @@ async def test_dont_migrate_unique_ids(
),
],
)
@pytest.mark.usefixtures("mock_zamg_coordinator")
async def test_unload_entry(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_zamg_coordinator: MagicMock,
entitydata: dict,
unique_id: str,
) -> None: