From 1f6744847d512c70ca20dbe76a9eb617b094e1ee Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 2 Jul 2024 12:29:21 +0200 Subject: [PATCH] Use service_calls fixture in zone tests (#120995) --- tests/components/zone/test_trigger.py | 56 ++++++++++++++------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/tests/components/zone/test_trigger.py b/tests/components/zone/test_trigger.py index 6ec5e2fd894..e80cee82eee 100644 --- a/tests/components/zone/test_trigger.py +++ b/tests/components/zone/test_trigger.py @@ -8,7 +8,7 @@ from homeassistant.core import Context, HomeAssistant, ServiceCall from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component -from tests.common import async_mock_service, mock_component +from tests.common import mock_component @pytest.fixture(autouse=True, name="stub_blueprint_populate") @@ -16,12 +16,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture -def calls(hass: HomeAssistant) -> list[ServiceCall]: - """Track calls to a mock service.""" - return async_mock_service(hass, "test", "automation") - - @pytest.fixture(autouse=True) def setup_comp(hass): """Initialize components.""" @@ -43,7 +37,7 @@ def setup_comp(hass): async def test_if_fires_on_zone_enter( - hass: HomeAssistant, calls: list[ServiceCall] + hass: HomeAssistant, service_calls: list[ServiceCall] ) -> None: """Test for firing on zone enter.""" context = Context() @@ -88,9 +82,11 @@ async def test_if_fires_on_zone_enter( ) await hass.async_block_till_done() - assert len(calls) == 1 - assert calls[0].context.parent_id == context.id - assert calls[0].data["some"] == "zone - test.entity - hello - hello - test - 0" + assert len(service_calls) == 1 + assert service_calls[0].context.parent_id == context.id + assert ( + service_calls[0].data["some"] == "zone - test.entity - hello - hello - test - 0" + ) # Set out of zone again so we can trigger call hass.states.async_set( @@ -104,17 +100,20 @@ async def test_if_fires_on_zone_enter( {ATTR_ENTITY_ID: ENTITY_MATCH_ALL}, blocking=True, ) + assert len(service_calls) == 2 hass.states.async_set( "test.entity", "hello", {"latitude": 32.880586, "longitude": -117.237564} ) await hass.async_block_till_done() - assert len(calls) == 1 + assert len(service_calls) == 2 async def test_if_fires_on_zone_enter_uuid( - hass: HomeAssistant, entity_registry: er.EntityRegistry, calls: list[ServiceCall] + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + service_calls: list[ServiceCall], ) -> None: """Test for firing on zone enter when device is specified by entity registry id.""" context = Context() @@ -165,9 +164,11 @@ async def test_if_fires_on_zone_enter_uuid( ) await hass.async_block_till_done() - assert len(calls) == 1 - assert calls[0].context.parent_id == context.id - assert calls[0].data["some"] == "zone - test.entity - hello - hello - test - 0" + assert len(service_calls) == 1 + assert service_calls[0].context.parent_id == context.id + assert ( + service_calls[0].data["some"] == "zone - test.entity - hello - hello - test - 0" + ) # Set out of zone again so we can trigger call hass.states.async_set( @@ -181,17 +182,18 @@ async def test_if_fires_on_zone_enter_uuid( {ATTR_ENTITY_ID: ENTITY_MATCH_ALL}, blocking=True, ) + assert len(service_calls) == 2 hass.states.async_set( "test.entity", "hello", {"latitude": 32.880586, "longitude": -117.237564} ) await hass.async_block_till_done() - assert len(calls) == 1 + assert len(service_calls) == 2 async def test_if_not_fires_for_enter_on_zone_leave( - hass: HomeAssistant, calls: list[ServiceCall] + hass: HomeAssistant, service_calls: list[ServiceCall] ) -> None: """Test for not firing on zone leave.""" hass.states.async_set( @@ -220,11 +222,11 @@ async def test_if_not_fires_for_enter_on_zone_leave( ) await hass.async_block_till_done() - assert len(calls) == 0 + assert len(service_calls) == 0 async def test_if_fires_on_zone_leave( - hass: HomeAssistant, calls: list[ServiceCall] + hass: HomeAssistant, service_calls: list[ServiceCall] ) -> None: """Test for firing on zone leave.""" hass.states.async_set( @@ -253,11 +255,11 @@ async def test_if_fires_on_zone_leave( ) await hass.async_block_till_done() - assert len(calls) == 1 + assert len(service_calls) == 1 async def test_if_not_fires_for_leave_on_zone_enter( - hass: HomeAssistant, calls: list[ServiceCall] + hass: HomeAssistant, service_calls: list[ServiceCall] ) -> None: """Test for not firing on zone enter.""" hass.states.async_set( @@ -286,10 +288,12 @@ async def test_if_not_fires_for_leave_on_zone_enter( ) await hass.async_block_till_done() - assert len(calls) == 0 + assert len(service_calls) == 0 -async def test_zone_condition(hass: HomeAssistant, calls: list[ServiceCall]) -> None: +async def test_zone_condition( + hass: HomeAssistant, service_calls: list[ServiceCall] +) -> None: """Test for zone condition.""" hass.states.async_set( "test.entity", "hello", {"latitude": 32.880586, "longitude": -117.237564} @@ -314,11 +318,11 @@ async def test_zone_condition(hass: HomeAssistant, calls: list[ServiceCall]) -> hass.bus.async_fire("test_event") await hass.async_block_till_done() - assert len(calls) == 1 + assert len(service_calls) == 1 async def test_unknown_zone( - hass: HomeAssistant, calls: list[ServiceCall], caplog: pytest.LogCaptureFixture + hass: HomeAssistant, caplog: pytest.LogCaptureFixture ) -> None: """Test for firing on zone enter.""" context = Context()