Improve typing for calls fixture in tests (a-l) (#118349)

* Improve typing for `calls` fixture in tests (a-l)

* More

* More
This commit is contained in:
epenet
2024-05-29 09:06:48 +02:00
committed by GitHub
parent 89ae425ac2
commit 7e62061b9a
43 changed files with 546 additions and 338 deletions

View File

@@ -4,14 +4,14 @@ import pytest
from homeassistant.components import automation
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL, SERVICE_TURN_OFF
from homeassistant.core import Context, HomeAssistant
from homeassistant.core import Context, HomeAssistant, ServiceCall
from homeassistant.setup import async_setup_component
from tests.common import async_mock_service, mock_component
@pytest.fixture
def calls(hass):
def calls(hass: HomeAssistant) -> list[ServiceCall]:
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation")
@@ -28,7 +28,7 @@ def setup_comp(hass):
mock_component(hass, "group")
async def test_if_fires_on_event(hass: HomeAssistant, calls) -> None:
async def test_if_fires_on_event(hass: HomeAssistant, calls: list[ServiceCall]) -> None:
"""Test the firing of events."""
context = Context()
@@ -64,7 +64,9 @@ async def test_if_fires_on_event(hass: HomeAssistant, calls) -> None:
assert calls[0].data["id"] == 0
async def test_if_fires_on_templated_event(hass: HomeAssistant, calls) -> None:
async def test_if_fires_on_templated_event(
hass: HomeAssistant, calls: list[ServiceCall]
) -> None:
"""Test the firing of events."""
context = Context()
@@ -97,7 +99,9 @@ async def test_if_fires_on_templated_event(hass: HomeAssistant, calls) -> None:
assert len(calls) == 1
async def test_if_fires_on_multiple_events(hass: HomeAssistant, calls) -> None:
async def test_if_fires_on_multiple_events(
hass: HomeAssistant, calls: list[ServiceCall]
) -> None:
"""Test the firing of events."""
context = Context()
@@ -125,7 +129,7 @@ async def test_if_fires_on_multiple_events(hass: HomeAssistant, calls) -> None:
async def test_if_fires_on_event_extra_data(
hass: HomeAssistant, calls, context_with_user
hass: HomeAssistant, calls: list[ServiceCall], context_with_user: Context
) -> None:
"""Test the firing of events still matches with event data and context."""
assert await async_setup_component(
@@ -157,7 +161,7 @@ async def test_if_fires_on_event_extra_data(
async def test_if_fires_on_event_with_data_and_context(
hass: HomeAssistant, calls, context_with_user
hass: HomeAssistant, calls: list[ServiceCall], context_with_user: Context
) -> None:
"""Test the firing of events with data and context."""
assert await async_setup_component(
@@ -204,7 +208,7 @@ async def test_if_fires_on_event_with_data_and_context(
async def test_if_fires_on_event_with_templated_data_and_context(
hass: HomeAssistant, calls, context_with_user
hass: HomeAssistant, calls: list[ServiceCall], context_with_user: Context
) -> None:
"""Test the firing of events with templated data and context."""
assert await async_setup_component(
@@ -256,7 +260,7 @@ async def test_if_fires_on_event_with_templated_data_and_context(
async def test_if_fires_on_event_with_empty_data_and_context_config(
hass: HomeAssistant, calls, context_with_user
hass: HomeAssistant, calls: list[ServiceCall], context_with_user: Context
) -> None:
"""Test the firing of events with empty data and context config.
@@ -288,7 +292,9 @@ async def test_if_fires_on_event_with_empty_data_and_context_config(
assert len(calls) == 1
async def test_if_fires_on_event_with_nested_data(hass: HomeAssistant, calls) -> None:
async def test_if_fires_on_event_with_nested_data(
hass: HomeAssistant, calls: list[ServiceCall]
) -> None:
"""Test the firing of events with nested data.
This test exercises the slow path of using vol.Schema to validate
@@ -316,7 +322,9 @@ async def test_if_fires_on_event_with_nested_data(hass: HomeAssistant, calls) ->
assert len(calls) == 1
async def test_if_fires_on_event_with_empty_data(hass: HomeAssistant, calls) -> None:
async def test_if_fires_on_event_with_empty_data(
hass: HomeAssistant, calls: list[ServiceCall]
) -> None:
"""Test the firing of events with empty data.
This test exercises the fast path to validate matching event data.
@@ -340,7 +348,9 @@ async def test_if_fires_on_event_with_empty_data(hass: HomeAssistant, calls) ->
assert len(calls) == 1
async def test_if_fires_on_sample_zha_event(hass: HomeAssistant, calls) -> None:
async def test_if_fires_on_sample_zha_event(
hass: HomeAssistant, calls: list[ServiceCall]
) -> None:
"""Test the firing of events with a sample zha event.
This test exercises the fast path to validate matching event data.
@@ -398,7 +408,7 @@ async def test_if_fires_on_sample_zha_event(hass: HomeAssistant, calls) -> None:
async def test_if_not_fires_if_event_data_not_matches(
hass: HomeAssistant, calls
hass: HomeAssistant, calls: list[ServiceCall]
) -> None:
"""Test firing of event if no data match."""
assert await async_setup_component(
@@ -422,7 +432,7 @@ async def test_if_not_fires_if_event_data_not_matches(
async def test_if_not_fires_if_event_context_not_matches(
hass: HomeAssistant, calls, context_with_user
hass: HomeAssistant, calls: list[ServiceCall], context_with_user: Context
) -> None:
"""Test firing of event if no context match."""
assert await async_setup_component(
@@ -446,7 +456,7 @@ async def test_if_not_fires_if_event_context_not_matches(
async def test_if_fires_on_multiple_user_ids(
hass: HomeAssistant, calls, context_with_user
hass: HomeAssistant, calls: list[ServiceCall], context_with_user: Context
) -> None:
"""Test the firing of event when the trigger has multiple user ids.
@@ -474,7 +484,9 @@ async def test_if_fires_on_multiple_user_ids(
assert len(calls) == 1
async def test_event_data_with_list(hass: HomeAssistant, calls) -> None:
async def test_event_data_with_list(
hass: HomeAssistant, calls: list[ServiceCall]
) -> None:
"""Test the (non)firing of event when the data schema has lists."""
assert await async_setup_component(
hass,
@@ -511,7 +523,10 @@ async def test_event_data_with_list(hass: HomeAssistant, calls) -> None:
"event_type", ["state_reported", ["test_event", "state_reported"]]
)
async def test_state_reported_event(
hass: HomeAssistant, calls, caplog, event_type: list[str]
hass: HomeAssistant,
calls: list[ServiceCall],
caplog: pytest.LogCaptureFixture,
event_type: str | list[str],
) -> None:
"""Test triggering on state reported event."""
context = Context()
@@ -541,7 +556,7 @@ async def test_state_reported_event(
async def test_templated_state_reported_event(
hass: HomeAssistant, calls, caplog
hass: HomeAssistant, calls: list[ServiceCall], caplog: pytest.LogCaptureFixture
) -> None:
"""Test triggering on state reported event."""
context = Context()