Replace assert_lists_same with pytest_unordered in integrations t-z (#94903)

This commit is contained in:
Erik Montnemery 2023-06-20 20:23:49 +02:00 committed by GitHub
parent eba04824a4
commit 6183a36fce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 47 additions and 49 deletions

View file

@ -5,6 +5,7 @@ from unittest.mock import Mock, patch
from hatasmota.switch import TasmotaSwitchTriggerConfig from hatasmota.switch import TasmotaSwitchTriggerConfig
import pytest import pytest
from pytest_unordered import unordered
import homeassistant.components.automation as automation import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType 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 .test_common import DEFAULT_CONFIG, remove_device
from tests.common import ( from tests.common import (
assert_lists_same,
async_fire_mqtt_message, async_fire_mqtt_message,
async_get_device_automations, async_get_device_automations,
) )
@ -74,7 +74,7 @@ async def test_get_triggers_btn(
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id
) )
assert_lists_same(triggers, expected_triggers) assert triggers == unordered(expected_triggers)
async def test_get_triggers_swc( async def test_get_triggers_swc(
@ -109,7 +109,7 @@ async def test_get_triggers_swc(
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id
) )
assert_lists_same(triggers, expected_triggers) assert triggers == unordered(expected_triggers)
async def test_get_unknown_triggers( async def test_get_unknown_triggers(
@ -158,7 +158,7 @@ async def test_get_unknown_triggers(
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id
) )
assert_lists_same(triggers, []) assert triggers == []
async def test_get_non_existing_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( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id
) )
assert_lists_same(triggers, []) assert triggers == []
@pytest.mark.no_fail_on_log_exception @pytest.mark.no_fail_on_log_exception
@ -215,7 +215,7 @@ async def test_discover_bad_triggers(
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id
) )
assert_lists_same(triggers, []) assert triggers == []
# Trigger an exception when the entity is discovered # Trigger an exception when the entity is discovered
class FakeTrigger(TasmotaSwitchTriggerConfig): class FakeTrigger(TasmotaSwitchTriggerConfig):
@ -251,7 +251,7 @@ async def test_discover_bad_triggers(
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id
) )
assert_lists_same(triggers, []) assert triggers == []
# Rediscover without exception # Rediscover without exception
async_fire_mqtt_message(hass, f"{DEFAULT_PREFIX}/{mac}/config", json.dumps(config)) 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( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id
) )
assert_lists_same(triggers, expected_triggers) assert triggers == unordered(expected_triggers)
async def test_update_remove_triggers( async def test_update_remove_triggers(

View file

@ -1,5 +1,6 @@
"""The tests for Text device actions.""" """The tests for Text device actions."""
import pytest import pytest
from pytest_unordered import unordered
import voluptuous_serialize import voluptuous_serialize
import homeassistant.components.automation as automation import homeassistant.components.automation as automation
@ -17,7 +18,6 @@ from homeassistant.setup import async_setup_component
from tests.common import ( from tests.common import (
MockConfigEntry, MockConfigEntry,
assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
) )
@ -56,7 +56,7 @@ async def test_get_actions(
actions = await async_get_device_automations( actions = await async_get_device_automations(
hass, DeviceAutomationType.ACTION, device_entry.id hass, DeviceAutomationType.ACTION, device_entry.id
) )
assert_lists_same(actions, expected_actions) assert actions == unordered(expected_actions)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -104,7 +104,7 @@ async def test_get_actions_hidden_auxiliary(
actions = await async_get_device_automations( actions = await async_get_device_automations(
hass, DeviceAutomationType.ACTION, device_entry.id hass, DeviceAutomationType.ACTION, device_entry.id
) )
assert_lists_same(actions, expected_actions) assert actions == unordered(expected_actions)
async def test_get_action_no_state( async def test_get_action_no_state(
@ -134,7 +134,7 @@ async def test_get_action_no_state(
actions = await async_get_device_automations( actions = await async_get_device_automations(
hass, DeviceAutomationType.ACTION, device_entry.id hass, DeviceAutomationType.ACTION, device_entry.id
) )
assert_lists_same(actions, expected_actions) assert actions == unordered(expected_actions)
async def test_action(hass: HomeAssistant) -> None: async def test_action(hass: HomeAssistant) -> None:

View file

@ -6,6 +6,7 @@ from typing import Any
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
from pytest_unordered import unordered
from homeassistant.bootstrap import async_setup_component from homeassistant.bootstrap import async_setup_component
from homeassistant.components.trace.const import DEFAULT_STORED_TRACES 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.helpers.typing import UNDEFINED
from homeassistant.util.uuid import random_uuid_hex 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 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"}) await client.send_json({"id": next_id(), "type": "trace/debug/breakpoint/list"})
response = await client.receive_json() response = await client.receive_json()
assert response["success"] assert response["success"]
assert_lists_same( assert response["result"] == unordered(
response["result"],
[ [
{"node": f"{prefix}/1", "run_id": "*", "domain": domain, "item_id": "sun"}, {"node": f"{prefix}/1", "run_id": "*", "domain": domain, "item_id": "sun"},
{"node": f"{prefix}/5", "run_id": "*", "domain": domain, "item_id": "sun"}, {"node": f"{prefix}/5", "run_id": "*", "domain": domain, "item_id": "sun"},

View file

@ -2,6 +2,7 @@
from datetime import timedelta from datetime import timedelta
import pytest import pytest
from pytest_unordered import unordered
import homeassistant.components.automation as automation import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
@ -14,7 +15,6 @@ import homeassistant.util.dt as dt_util
from tests.common import ( from tests.common import (
MockConfigEntry, MockConfigEntry,
assert_lists_same,
async_fire_time_changed, async_fire_time_changed,
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
@ -62,7 +62,7 @@ async def test_get_triggers(
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id
) )
assert_lists_same(triggers, expected_triggers) assert triggers == unordered(expected_triggers)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -110,7 +110,7 @@ async def test_get_triggers_hidden_auxiliary(
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id
) )
assert_lists_same(triggers, expected_triggers) assert triggers == unordered(expected_triggers)
async def test_get_trigger_capabilities( async def test_get_trigger_capabilities(

View file

@ -1,5 +1,6 @@
"""The tests for Vacuum device actions.""" """The tests for Vacuum device actions."""
import pytest import pytest
from pytest_unordered import unordered
import homeassistant.components.automation as automation import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
@ -12,7 +13,6 @@ from homeassistant.setup import async_setup_component
from tests.common import ( from tests.common import (
MockConfigEntry, MockConfigEntry,
assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
) )
@ -52,7 +52,7 @@ async def test_get_actions(
actions = await async_get_device_automations( actions = await async_get_device_automations(
hass, DeviceAutomationType.ACTION, device_entry.id hass, DeviceAutomationType.ACTION, device_entry.id
) )
assert_lists_same(actions, expected_actions) assert actions == unordered(expected_actions)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -100,7 +100,7 @@ async def test_get_actions_hidden_auxiliary(
actions = await async_get_device_automations( actions = await async_get_device_automations(
hass, DeviceAutomationType.ACTION, device_entry.id hass, DeviceAutomationType.ACTION, device_entry.id
) )
assert_lists_same(actions, expected_actions) assert actions == unordered(expected_actions)
async def test_action(hass: HomeAssistant) -> None: async def test_action(hass: HomeAssistant) -> None:

View file

@ -1,5 +1,6 @@
"""The tests for Vacuum device conditions.""" """The tests for Vacuum device conditions."""
import pytest import pytest
from pytest_unordered import unordered
import homeassistant.components.automation as automation import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
@ -17,7 +18,6 @@ from homeassistant.setup import async_setup_component
from tests.common import ( from tests.common import (
MockConfigEntry, MockConfigEntry,
assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
) )
@ -63,7 +63,7 @@ async def test_get_conditions(
conditions = await async_get_device_automations( conditions = await async_get_device_automations(
hass, DeviceAutomationType.CONDITION, device_entry.id hass, DeviceAutomationType.CONDITION, device_entry.id
) )
assert_lists_same(conditions, expected_conditions) assert conditions == unordered(expected_conditions)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -111,7 +111,7 @@ async def test_get_conditions_hidden_auxiliary(
conditions = await async_get_device_automations( conditions = await async_get_device_automations(
hass, DeviceAutomationType.CONDITION, device_entry.id 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: async def test_if_state(hass: HomeAssistant, calls) -> None:

View file

@ -2,6 +2,7 @@
from datetime import timedelta from datetime import timedelta
import pytest import pytest
from pytest_unordered import unordered
import homeassistant.components.automation as automation import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
@ -15,7 +16,6 @@ import homeassistant.util.dt as dt_util
from tests.common import ( from tests.common import (
MockConfigEntry, MockConfigEntry,
assert_lists_same,
async_fire_time_changed, async_fire_time_changed,
async_get_device_automation_capabilities, async_get_device_automation_capabilities,
async_get_device_automations, async_get_device_automations,
@ -63,7 +63,7 @@ async def test_get_triggers(
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id
) )
assert_lists_same(triggers, expected_triggers) assert triggers == unordered(expected_triggers)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -111,7 +111,7 @@ async def test_get_triggers_hidden_auxiliary(
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id
) )
assert_lists_same(triggers, expected_triggers) assert triggers == unordered(expected_triggers)
async def test_get_trigger_capabilities( async def test_get_trigger_capabilities(

View file

@ -1,5 +1,6 @@
"""The tests for Water Heater device actions.""" """The tests for Water Heater device actions."""
import pytest import pytest
from pytest_unordered import unordered
import homeassistant.components.automation as automation import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
@ -12,7 +13,6 @@ from homeassistant.setup import async_setup_component
from tests.common import ( from tests.common import (
MockConfigEntry, MockConfigEntry,
assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
) )
@ -52,7 +52,7 @@ async def test_get_actions(
actions = await async_get_device_automations( actions = await async_get_device_automations(
hass, DeviceAutomationType.ACTION, device_entry.id hass, DeviceAutomationType.ACTION, device_entry.id
) )
assert_lists_same(actions, expected_actions) assert actions == unordered(expected_actions)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -100,7 +100,7 @@ async def test_get_actions_hidden_auxiliary(
actions = await async_get_device_automations( actions = await async_get_device_automations(
hass, DeviceAutomationType.ACTION, device_entry.id hass, DeviceAutomationType.ACTION, device_entry.id
) )
assert_lists_same(actions, expected_actions) assert actions == unordered(expected_actions)
async def test_action(hass: HomeAssistant) -> None: async def test_action(hass: HomeAssistant) -> None:

View file

@ -1,5 +1,6 @@
"""Verify that WeMo device triggers work as expected.""" """Verify that WeMo device triggers work as expected."""
import pytest import pytest
from pytest_unordered import unordered
from pywemo.subscribe import EVENT_TYPE_LONG_PRESS from pywemo.subscribe import EVENT_TYPE_LONG_PRESS
from homeassistant.components.automation import DOMAIN as AUTOMATION_DOMAIN 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 homeassistant.setup import async_setup_component
from tests.common import ( from tests.common import (
assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
) )
@ -96,7 +96,7 @@ async def test_get_triggers(hass: HomeAssistant, wemo_entity) -> None:
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, wemo_entity.device_id 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: async def test_fires_on_long_press(hass: HomeAssistant) -> None:

View file

@ -1,5 +1,6 @@
"""The tests for YoLink device triggers.""" """The tests for YoLink device triggers."""
import pytest import pytest
from pytest_unordered import unordered
from yolink.const import ATTR_DEVICE_DIMMER, ATTR_DEVICE_SMART_REMOTER from yolink.const import ATTR_DEVICE_DIMMER, ATTR_DEVICE_SMART_REMOTER
from homeassistant.components import automation from homeassistant.components import automation
@ -11,7 +12,6 @@ from homeassistant.setup import async_setup_component
from tests.common import ( from tests.common import (
MockConfigEntry, MockConfigEntry,
assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
) )
@ -96,7 +96,7 @@ async def test_get_triggers(
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id hass, DeviceAutomationType.TRIGGER, device_entry.id
) )
assert_lists_same(triggers, expected_triggers) assert triggers == unordered(expected_triggers)
async def test_get_triggers_exception( async def test_get_triggers_exception(
@ -115,7 +115,7 @@ async def test_get_triggers_exception(
triggers = await async_get_device_automations( triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entity.id hass, DeviceAutomationType.TRIGGER, device_entity.id
) )
assert_lists_same(triggers, expected_triggers) assert triggers == unordered(expected_triggers)
async def test_if_fires_on_event( async def test_if_fires_on_event(

View file

@ -2,6 +2,7 @@
from unittest.mock import call, patch from unittest.mock import call, patch
import pytest import pytest
from pytest_unordered import unordered
from zhaquirks.inovelli.VZM31SN import InovelliVZM31SNv11 from zhaquirks.inovelli.VZM31SN import InovelliVZM31SNv11
import zigpy.profiles.zha import zigpy.profiles.zha
import zigpy.zcl.clusters.general as general 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 .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE
from tests.common import ( from tests.common import (
assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
mock_coro, 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: 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: async def test_action(hass: HomeAssistant, device_ias, device_inovelli) -> None:

View file

@ -2,6 +2,7 @@
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
from pytest_unordered import unordered
import voluptuous_serialize import voluptuous_serialize
from zwave_js_server.const import CommandClass from zwave_js_server.const import CommandClass
from zwave_js_server.event import Event 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 homeassistant.setup import async_setup_component
from tests.common import ( from tests.common import (
assert_lists_same,
async_get_device_automations, async_get_device_automations,
async_mock_service, async_mock_service,
) )
@ -193,16 +193,15 @@ async def test_get_trigger_capabilities_notification_notification(
) )
assert capabilities and "extra_fields" in capabilities assert capabilities and "extra_fields" in capabilities
assert_lists_same( assert voluptuous_serialize.convert(
voluptuous_serialize.convert( capabilities["extra_fields"], custom_serializer=cv.custom_serializer
capabilities["extra_fields"], custom_serializer=cv.custom_serializer ) == unordered(
),
[ [
{"name": "type.", "optional": True, "type": "string"}, {"name": "type.", "optional": True, "type": "string"},
{"name": "label", "optional": True, "type": "string"}, {"name": "label", "optional": True, "type": "string"},
{"name": "event", "optional": True, "type": "string"}, {"name": "event", "optional": True, "type": "string"},
{"name": "event_label", "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 capabilities and "extra_fields" in capabilities
assert_lists_same( assert voluptuous_serialize.convert(
voluptuous_serialize.convert( capabilities["extra_fields"], custom_serializer=cv.custom_serializer
capabilities["extra_fields"], custom_serializer=cv.custom_serializer ) == unordered(
),
[ [
{"name": "event_type", "optional": True, "type": "string"}, {"name": "event_type", "optional": True, "type": "string"},
{"name": "data_type", "optional": True, "type": "string"}, {"name": "data_type", "optional": True, "type": "string"},
], ]
) )