From 6183a36fcea68c787d4e11e7a689c8e6d20207ee Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 20 Jun 2023 20:23:49 +0200 Subject: [PATCH] Replace assert_lists_same with pytest_unordered in integrations t-z (#94903) --- .../components/tasmota/test_device_trigger.py | 16 +++++++-------- tests/components/text/test_device_action.py | 8 ++++---- tests/components/trace/test_websocket_api.py | 6 +++--- .../components/update/test_device_trigger.py | 6 +++--- tests/components/vacuum/test_device_action.py | 6 +++--- .../vacuum/test_device_condition.py | 6 +++--- .../components/vacuum/test_device_trigger.py | 6 +++--- .../water_heater/test_device_action.py | 6 +++--- tests/components/wemo/test_device_trigger.py | 4 ++-- .../components/yolink/test_device_trigger.py | 6 +++--- tests/components/zha/test_device_action.py | 6 +++--- .../zwave_js/test_device_trigger.py | 20 +++++++++---------- 12 files changed, 47 insertions(+), 49 deletions(-) diff --git a/tests/components/tasmota/test_device_trigger.py b/tests/components/tasmota/test_device_trigger.py index fe3240790dd..880f4ed0e75 100644 --- a/tests/components/tasmota/test_device_trigger.py +++ b/tests/components/tasmota/test_device_trigger.py @@ -5,6 +5,7 @@ from unittest.mock import Mock, patch from hatasmota.switch import TasmotaSwitchTriggerConfig import pytest +from pytest_unordered import unordered import homeassistant.components.automation as automation from homeassistant.components.device_automation import DeviceAutomationType @@ -18,7 +19,6 @@ from homeassistant.setup import async_setup_component from .test_common import DEFAULT_CONFIG, remove_device from tests.common import ( - assert_lists_same, async_fire_mqtt_message, async_get_device_automations, ) @@ -74,7 +74,7 @@ async def test_get_triggers_btn( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entry.id ) - assert_lists_same(triggers, expected_triggers) + assert triggers == unordered(expected_triggers) async def test_get_triggers_swc( @@ -109,7 +109,7 @@ async def test_get_triggers_swc( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entry.id ) - assert_lists_same(triggers, expected_triggers) + assert triggers == unordered(expected_triggers) async def test_get_unknown_triggers( @@ -158,7 +158,7 @@ async def test_get_unknown_triggers( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entry.id ) - assert_lists_same(triggers, []) + assert triggers == [] async def test_get_non_existing_triggers( @@ -183,7 +183,7 @@ async def test_get_non_existing_triggers( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entry.id ) - assert_lists_same(triggers, []) + assert triggers == [] @pytest.mark.no_fail_on_log_exception @@ -215,7 +215,7 @@ async def test_discover_bad_triggers( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entry.id ) - assert_lists_same(triggers, []) + assert triggers == [] # Trigger an exception when the entity is discovered class FakeTrigger(TasmotaSwitchTriggerConfig): @@ -251,7 +251,7 @@ async def test_discover_bad_triggers( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entry.id ) - assert_lists_same(triggers, []) + assert triggers == [] # Rediscover without exception async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{mac}/config", json.dumps(config)) @@ -271,7 +271,7 @@ async def test_discover_bad_triggers( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entry.id ) - assert_lists_same(triggers, expected_triggers) + assert triggers == unordered(expected_triggers) async def test_update_remove_triggers( diff --git a/tests/components/text/test_device_action.py b/tests/components/text/test_device_action.py index 523a39c5640..09a1a3176f5 100644 --- a/tests/components/text/test_device_action.py +++ b/tests/components/text/test_device_action.py @@ -1,5 +1,6 @@ """The tests for Text device actions.""" import pytest +from pytest_unordered import unordered import voluptuous_serialize import homeassistant.components.automation as automation @@ -17,7 +18,6 @@ from homeassistant.setup import async_setup_component from tests.common import ( MockConfigEntry, - assert_lists_same, async_get_device_automations, async_mock_service, ) @@ -56,7 +56,7 @@ async def test_get_actions( actions = await async_get_device_automations( hass, DeviceAutomationType.ACTION, device_entry.id ) - assert_lists_same(actions, expected_actions) + assert actions == unordered(expected_actions) @pytest.mark.parametrize( @@ -104,7 +104,7 @@ async def test_get_actions_hidden_auxiliary( actions = await async_get_device_automations( hass, DeviceAutomationType.ACTION, device_entry.id ) - assert_lists_same(actions, expected_actions) + assert actions == unordered(expected_actions) async def test_get_action_no_state( @@ -134,7 +134,7 @@ async def test_get_action_no_state( actions = await async_get_device_automations( hass, DeviceAutomationType.ACTION, device_entry.id ) - assert_lists_same(actions, expected_actions) + assert actions == unordered(expected_actions) async def test_action(hass: HomeAssistant) -> None: diff --git a/tests/components/trace/test_websocket_api.py b/tests/components/trace/test_websocket_api.py index 8b3bca86565..1041208fa61 100644 --- a/tests/components/trace/test_websocket_api.py +++ b/tests/components/trace/test_websocket_api.py @@ -6,6 +6,7 @@ from typing import Any from unittest.mock import patch import pytest +from pytest_unordered import unordered from homeassistant.bootstrap import async_setup_component from homeassistant.components.trace.const import DEFAULT_STORED_TRACES @@ -14,7 +15,7 @@ from homeassistant.core import Context, CoreState, HomeAssistant, callback from homeassistant.helpers.typing import UNDEFINED from homeassistant.util.uuid import random_uuid_hex -from tests.common import assert_lists_same, load_fixture +from tests.common import load_fixture from tests.typing import WebSocketGenerator @@ -1086,8 +1087,7 @@ async def test_breakpoints( await client.send_json({"id": next_id(), "type": "trace/debug/breakpoint/list"}) response = await client.receive_json() assert response["success"] - assert_lists_same( - response["result"], + assert response["result"] == unordered( [ {"node": f"{prefix}/1", "run_id": "*", "domain": domain, "item_id": "sun"}, {"node": f"{prefix}/5", "run_id": "*", "domain": domain, "item_id": "sun"}, diff --git a/tests/components/update/test_device_trigger.py b/tests/components/update/test_device_trigger.py index bddcefa07c5..a9abed935fb 100644 --- a/tests/components/update/test_device_trigger.py +++ b/tests/components/update/test_device_trigger.py @@ -2,6 +2,7 @@ from datetime import timedelta import pytest +from pytest_unordered import unordered import homeassistant.components.automation as automation from homeassistant.components.device_automation import DeviceAutomationType @@ -14,7 +15,6 @@ import homeassistant.util.dt as dt_util from tests.common import ( MockConfigEntry, - assert_lists_same, async_fire_time_changed, async_get_device_automation_capabilities, async_get_device_automations, @@ -62,7 +62,7 @@ async def test_get_triggers( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entry.id ) - assert_lists_same(triggers, expected_triggers) + assert triggers == unordered(expected_triggers) @pytest.mark.parametrize( @@ -110,7 +110,7 @@ async def test_get_triggers_hidden_auxiliary( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entry.id ) - assert_lists_same(triggers, expected_triggers) + assert triggers == unordered(expected_triggers) async def test_get_trigger_capabilities( diff --git a/tests/components/vacuum/test_device_action.py b/tests/components/vacuum/test_device_action.py index 643d9ad0130..1a4aa1455a7 100644 --- a/tests/components/vacuum/test_device_action.py +++ b/tests/components/vacuum/test_device_action.py @@ -1,5 +1,6 @@ """The tests for Vacuum device actions.""" import pytest +from pytest_unordered import unordered import homeassistant.components.automation as automation from homeassistant.components.device_automation import DeviceAutomationType @@ -12,7 +13,6 @@ from homeassistant.setup import async_setup_component from tests.common import ( MockConfigEntry, - assert_lists_same, async_get_device_automations, async_mock_service, ) @@ -52,7 +52,7 @@ async def test_get_actions( actions = await async_get_device_automations( hass, DeviceAutomationType.ACTION, device_entry.id ) - assert_lists_same(actions, expected_actions) + assert actions == unordered(expected_actions) @pytest.mark.parametrize( @@ -100,7 +100,7 @@ async def test_get_actions_hidden_auxiliary( actions = await async_get_device_automations( hass, DeviceAutomationType.ACTION, device_entry.id ) - assert_lists_same(actions, expected_actions) + assert actions == unordered(expected_actions) async def test_action(hass: HomeAssistant) -> None: diff --git a/tests/components/vacuum/test_device_condition.py b/tests/components/vacuum/test_device_condition.py index b1ed65d689f..6d1f0e5ad75 100644 --- a/tests/components/vacuum/test_device_condition.py +++ b/tests/components/vacuum/test_device_condition.py @@ -1,5 +1,6 @@ """The tests for Vacuum device conditions.""" import pytest +from pytest_unordered import unordered import homeassistant.components.automation as automation from homeassistant.components.device_automation import DeviceAutomationType @@ -17,7 +18,6 @@ from homeassistant.setup import async_setup_component from tests.common import ( MockConfigEntry, - assert_lists_same, async_get_device_automations, async_mock_service, ) @@ -63,7 +63,7 @@ async def test_get_conditions( conditions = await async_get_device_automations( hass, DeviceAutomationType.CONDITION, device_entry.id ) - assert_lists_same(conditions, expected_conditions) + assert conditions == unordered(expected_conditions) @pytest.mark.parametrize( @@ -111,7 +111,7 @@ async def test_get_conditions_hidden_auxiliary( conditions = await async_get_device_automations( hass, DeviceAutomationType.CONDITION, device_entry.id ) - assert_lists_same(conditions, expected_conditions) + assert conditions == unordered(expected_conditions) async def test_if_state(hass: HomeAssistant, calls) -> None: diff --git a/tests/components/vacuum/test_device_trigger.py b/tests/components/vacuum/test_device_trigger.py index 84519a80545..2ab0c80af14 100644 --- a/tests/components/vacuum/test_device_trigger.py +++ b/tests/components/vacuum/test_device_trigger.py @@ -2,6 +2,7 @@ from datetime import timedelta import pytest +from pytest_unordered import unordered import homeassistant.components.automation as automation from homeassistant.components.device_automation import DeviceAutomationType @@ -15,7 +16,6 @@ import homeassistant.util.dt as dt_util from tests.common import ( MockConfigEntry, - assert_lists_same, async_fire_time_changed, async_get_device_automation_capabilities, async_get_device_automations, @@ -63,7 +63,7 @@ async def test_get_triggers( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entry.id ) - assert_lists_same(triggers, expected_triggers) + assert triggers == unordered(expected_triggers) @pytest.mark.parametrize( @@ -111,7 +111,7 @@ async def test_get_triggers_hidden_auxiliary( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entry.id ) - assert_lists_same(triggers, expected_triggers) + assert triggers == unordered(expected_triggers) async def test_get_trigger_capabilities( diff --git a/tests/components/water_heater/test_device_action.py b/tests/components/water_heater/test_device_action.py index b1e12dcab94..35b78a3d926 100644 --- a/tests/components/water_heater/test_device_action.py +++ b/tests/components/water_heater/test_device_action.py @@ -1,5 +1,6 @@ """The tests for Water Heater device actions.""" import pytest +from pytest_unordered import unordered import homeassistant.components.automation as automation from homeassistant.components.device_automation import DeviceAutomationType @@ -12,7 +13,6 @@ from homeassistant.setup import async_setup_component from tests.common import ( MockConfigEntry, - assert_lists_same, async_get_device_automations, async_mock_service, ) @@ -52,7 +52,7 @@ async def test_get_actions( actions = await async_get_device_automations( hass, DeviceAutomationType.ACTION, device_entry.id ) - assert_lists_same(actions, expected_actions) + assert actions == unordered(expected_actions) @pytest.mark.parametrize( @@ -100,7 +100,7 @@ async def test_get_actions_hidden_auxiliary( actions = await async_get_device_automations( hass, DeviceAutomationType.ACTION, device_entry.id ) - assert_lists_same(actions, expected_actions) + assert actions == unordered(expected_actions) async def test_action(hass: HomeAssistant) -> None: diff --git a/tests/components/wemo/test_device_trigger.py b/tests/components/wemo/test_device_trigger.py index ad649fb3a24..e7a1c11e6c8 100644 --- a/tests/components/wemo/test_device_trigger.py +++ b/tests/components/wemo/test_device_trigger.py @@ -1,5 +1,6 @@ """Verify that WeMo device triggers work as expected.""" import pytest +from pytest_unordered import unordered from pywemo.subscribe import EVENT_TYPE_LONG_PRESS from homeassistant.components.automation import DOMAIN as AUTOMATION_DOMAIN @@ -17,7 +18,6 @@ from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from tests.common import ( - assert_lists_same, async_get_device_automations, async_mock_service, ) @@ -96,7 +96,7 @@ async def test_get_triggers(hass: HomeAssistant, wemo_entity) -> None: triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, wemo_entity.device_id ) - assert_lists_same(triggers, expected_triggers) + assert triggers == unordered(expected_triggers) async def test_fires_on_long_press(hass: HomeAssistant) -> None: diff --git a/tests/components/yolink/test_device_trigger.py b/tests/components/yolink/test_device_trigger.py index f5679ca19c9..e0ef37c1b75 100644 --- a/tests/components/yolink/test_device_trigger.py +++ b/tests/components/yolink/test_device_trigger.py @@ -1,5 +1,6 @@ """The tests for YoLink device triggers.""" import pytest +from pytest_unordered import unordered from yolink.const import ATTR_DEVICE_DIMMER, ATTR_DEVICE_SMART_REMOTER from homeassistant.components import automation @@ -11,7 +12,6 @@ from homeassistant.setup import async_setup_component from tests.common import ( MockConfigEntry, - assert_lists_same, async_get_device_automations, async_mock_service, ) @@ -96,7 +96,7 @@ async def test_get_triggers( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entry.id ) - assert_lists_same(triggers, expected_triggers) + assert triggers == unordered(expected_triggers) async def test_get_triggers_exception( @@ -115,7 +115,7 @@ async def test_get_triggers_exception( triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device_entity.id ) - assert_lists_same(triggers, expected_triggers) + assert triggers == unordered(expected_triggers) async def test_if_fires_on_event( diff --git a/tests/components/zha/test_device_action.py b/tests/components/zha/test_device_action.py index 0dda0b56e23..5b6d7c94539 100644 --- a/tests/components/zha/test_device_action.py +++ b/tests/components/zha/test_device_action.py @@ -2,6 +2,7 @@ from unittest.mock import call, patch import pytest +from pytest_unordered import unordered from zhaquirks.inovelli.VZM31SN import InovelliVZM31SNv11 import zigpy.profiles.zha import zigpy.zcl.clusters.general as general @@ -19,7 +20,6 @@ from homeassistant.setup import async_setup_component from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE from tests.common import ( - assert_lists_same, async_get_device_automations, async_mock_service, mock_coro, @@ -153,7 +153,7 @@ async def test_get_actions(hass: HomeAssistant, device_ias) -> None: ] ) - assert_lists_same(actions, expected_actions) + assert actions == unordered(expected_actions) async def test_get_inovelli_actions(hass: HomeAssistant, device_inovelli) -> None: @@ -233,7 +233,7 @@ async def test_get_inovelli_actions(hass: HomeAssistant, device_inovelli) -> Non }, ] - assert_lists_same(actions, expected_actions) + assert actions == unordered(expected_actions) async def test_action(hass: HomeAssistant, device_ias, device_inovelli) -> None: diff --git a/tests/components/zwave_js/test_device_trigger.py b/tests/components/zwave_js/test_device_trigger.py index a8f5ff98fdf..8209564579c 100644 --- a/tests/components/zwave_js/test_device_trigger.py +++ b/tests/components/zwave_js/test_device_trigger.py @@ -2,6 +2,7 @@ from unittest.mock import patch import pytest +from pytest_unordered import unordered import voluptuous_serialize from zwave_js_server.const import CommandClass from zwave_js_server.event import Event @@ -25,7 +26,6 @@ from homeassistant.helpers.entity_registry import async_get as async_get_ent_reg from homeassistant.setup import async_setup_component from tests.common import ( - assert_lists_same, async_get_device_automations, async_mock_service, ) @@ -193,16 +193,15 @@ async def test_get_trigger_capabilities_notification_notification( ) assert capabilities and "extra_fields" in capabilities - assert_lists_same( - voluptuous_serialize.convert( - capabilities["extra_fields"], custom_serializer=cv.custom_serializer - ), + assert voluptuous_serialize.convert( + capabilities["extra_fields"], custom_serializer=cv.custom_serializer + ) == unordered( [ {"name": "type.", "optional": True, "type": "string"}, {"name": "label", "optional": True, "type": "string"}, {"name": "event", "optional": True, "type": "string"}, {"name": "event_label", "optional": True, "type": "string"}, - ], + ] ) @@ -323,14 +322,13 @@ async def test_get_trigger_capabilities_entry_control_notification( ) assert capabilities and "extra_fields" in capabilities - assert_lists_same( - voluptuous_serialize.convert( - capabilities["extra_fields"], custom_serializer=cv.custom_serializer - ), + assert voluptuous_serialize.convert( + capabilities["extra_fields"], custom_serializer=cv.custom_serializer + ) == unordered( [ {"name": "event_type", "optional": True, "type": "string"}, {"name": "data_type", "optional": True, "type": "string"}, - ], + ] )