pull/120718/head^2
Joost Lekkerkerker 2024-06-28 10:46:02 +02:00 committed by GitHub
parent c98e70a6dc
commit 03c6e0c55f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 103 additions and 96 deletions

View File

@ -345,7 +345,7 @@ async def test_browse_media(
)
response = await client.receive_json()
assert response["success"]
assert {
assert response["result"] == {
"title": "Applications",
"media_class": "directory",
"media_content_type": "apps",
@ -377,7 +377,7 @@ async def test_browse_media(
"thumbnail": "",
},
],
} == response["result"]
}
async def test_media_player_connection_closed(

View File

@ -178,7 +178,7 @@ async def test_service_specify_entity_id(
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
assert ["hello.world"] == calls[0].data.get(ATTR_ENTITY_ID)
assert calls[0].data.get(ATTR_ENTITY_ID) == ["hello.world"]
async def test_service_specify_entity_id_list(
@ -202,7 +202,7 @@ async def test_service_specify_entity_id_list(
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
assert ["hello.world", "hello.world2"] == calls[0].data.get(ATTR_ENTITY_ID)
assert calls[0].data.get(ATTR_ENTITY_ID) == ["hello.world", "hello.world2"]
async def test_two_triggers(hass: HomeAssistant, calls: list[ServiceCall]) -> None:
@ -1641,7 +1641,7 @@ async def test_automation_not_trigger_on_bootstrap(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
assert len(calls) == 1
assert ["hello.world"] == calls[0].data.get(ATTR_ENTITY_ID)
assert calls[0].data.get(ATTR_ENTITY_ID) == ["hello.world"]
@pytest.mark.parametrize(

View File

@ -48,7 +48,7 @@ async def test_exclude_attributes(
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
assert ["hello.world"] == calls[0].data.get(ATTR_ENTITY_ID)
assert calls[0].data.get(ATTR_ENTITY_ID) == ["hello.world"]
await async_wait_recording_done(hass)
states = await hass.async_add_executor_job(

View File

@ -718,17 +718,18 @@ async def test_observed_entities(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test_binary")
assert ["sensor.test_monitored"] == state.attributes.get(
"occurred_observation_entities"
)
assert state.attributes.get("occurred_observation_entities") == [
"sensor.test_monitored"
]
hass.states.async_set("sensor.test_monitored1", "on")
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test_binary")
assert ["sensor.test_monitored", "sensor.test_monitored1"] == sorted(
state.attributes.get("occurred_observation_entities")
)
assert sorted(state.attributes.get("occurred_observation_entities")) == [
"sensor.test_monitored",
"sensor.test_monitored1",
]
async def test_state_attributes_are_serializable(hass: HomeAssistant) -> None:
@ -785,9 +786,10 @@ async def test_state_attributes_are_serializable(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test_binary")
assert ["sensor.test_monitored", "sensor.test_monitored1"] == sorted(
state.attributes.get("occurred_observation_entities")
)
assert sorted(state.attributes.get("occurred_observation_entities")) == [
"sensor.test_monitored",
"sensor.test_monitored1",
]
for attrs in state.attributes.values():
json.dumps(attrs)

View File

@ -81,6 +81,6 @@ async def test_calling_notify_from_script_loaded_from_yaml(
await hass.services.async_call("script", "test")
await hass.async_block_till_done()
assert len(events) == 1
assert {
assert events[0].data == {
"message": "Test 123 4",
} == events[0].data
}

View File

@ -195,7 +195,7 @@ async def test_hvac_mode(ecobee_fixture, thermostat) -> None:
async def test_hvac_modes(thermostat) -> None:
"""Test operation list property."""
assert ["heat_cool", "heat", "cool", "off"] == thermostat.hvac_modes
assert thermostat.hvac_modes == ["heat_cool", "heat", "cool", "off"]
async def test_hvac_mode2(ecobee_fixture, thermostat) -> None:
@ -208,51 +208,51 @@ async def test_hvac_mode2(ecobee_fixture, thermostat) -> None:
async def test_extra_state_attributes(ecobee_fixture, thermostat) -> None:
"""Test device state attributes property."""
ecobee_fixture["equipmentStatus"] = "heatPump2"
assert {
assert thermostat.extra_state_attributes == {
"fan": "off",
"climate_mode": "Climate1",
"fan_min_on_time": 10,
"equipment_running": "heatPump2",
} == thermostat.extra_state_attributes
}
ecobee_fixture["equipmentStatus"] = "auxHeat2"
assert {
assert thermostat.extra_state_attributes == {
"fan": "off",
"climate_mode": "Climate1",
"fan_min_on_time": 10,
"equipment_running": "auxHeat2",
} == thermostat.extra_state_attributes
}
ecobee_fixture["equipmentStatus"] = "compCool1"
assert {
assert thermostat.extra_state_attributes == {
"fan": "off",
"climate_mode": "Climate1",
"fan_min_on_time": 10,
"equipment_running": "compCool1",
} == thermostat.extra_state_attributes
}
ecobee_fixture["equipmentStatus"] = ""
assert {
assert thermostat.extra_state_attributes == {
"fan": "off",
"climate_mode": "Climate1",
"fan_min_on_time": 10,
"equipment_running": "",
} == thermostat.extra_state_attributes
}
ecobee_fixture["equipmentStatus"] = "Unknown"
assert {
assert thermostat.extra_state_attributes == {
"fan": "off",
"climate_mode": "Climate1",
"fan_min_on_time": 10,
"equipment_running": "Unknown",
} == thermostat.extra_state_attributes
}
ecobee_fixture["program"]["currentClimateRef"] = "c2"
assert {
assert thermostat.extra_state_attributes == {
"fan": "off",
"climate_mode": "Climate2",
"fan_min_on_time": 10,
"equipment_running": "Unknown",
} == thermostat.extra_state_attributes
}
async def test_is_aux_heat_on(hass: HomeAssistant) -> None:

View File

@ -467,7 +467,7 @@ def test_throttle(values: list[State]) -> None:
new_state = filt.filter_state(state)
if not filt.skip_processing:
filtered.append(new_state)
assert [20, 21] == [f.state for f in filtered]
assert [f.state for f in filtered] == [20, 21]
def test_time_throttle(values: list[State]) -> None:
@ -480,7 +480,7 @@ def test_time_throttle(values: list[State]) -> None:
new_state = filt.filter_state(state)
if not filt.skip_processing:
filtered.append(new_state)
assert [20, 18, 22] == [f.state for f in filtered]
assert [f.state for f in filtered] == [20, 18, 22]
def test_time_sma(values: list[State]) -> None:

View File

@ -405,13 +405,13 @@ async def test_expand_entity_ids_does_not_return_duplicates(
order=None,
)
assert ["light.bowl", "light.ceiling"] == sorted(
assert sorted(
group.expand_entity_ids(hass, [test_group.entity_id, "light.Ceiling"])
)
) == ["light.bowl", "light.ceiling"]
assert ["light.bowl", "light.ceiling"] == sorted(
assert sorted(
group.expand_entity_ids(hass, ["light.bowl", test_group.entity_id])
)
) == ["light.bowl", "light.ceiling"]
async def test_expand_entity_ids_recursive(hass: HomeAssistant) -> None:
@ -439,7 +439,7 @@ async def test_expand_entity_ids_recursive(hass: HomeAssistant) -> None:
async def test_expand_entity_ids_ignores_non_strings(hass: HomeAssistant) -> None:
"""Test that non string elements in lists are ignored."""
assert [] == group.expand_entity_ids(hass, [5, True])
assert group.expand_entity_ids(hass, [5, True]) == []
async def test_get_entity_ids(hass: HomeAssistant) -> None:
@ -460,9 +460,10 @@ async def test_get_entity_ids(hass: HomeAssistant) -> None:
order=None,
)
assert ["light.bowl", "light.ceiling"] == sorted(
group.get_entity_ids(hass, test_group.entity_id)
)
assert sorted(group.get_entity_ids(hass, test_group.entity_id)) == [
"light.bowl",
"light.ceiling",
]
async def test_get_entity_ids_with_domain_filter(hass: HomeAssistant) -> None:
@ -482,19 +483,19 @@ async def test_get_entity_ids_with_domain_filter(hass: HomeAssistant) -> None:
order=None,
)
assert ["switch.ac"] == group.get_entity_ids(
assert group.get_entity_ids(
hass, mixed_group.entity_id, domain_filter="switch"
)
) == ["switch.ac"]
async def test_get_entity_ids_with_non_existing_group_name(hass: HomeAssistant) -> None:
"""Test get_entity_ids with a non existing group."""
assert [] == group.get_entity_ids(hass, "non_existing")
assert group.get_entity_ids(hass, "non_existing") == []
async def test_get_entity_ids_with_non_group_state(hass: HomeAssistant) -> None:
"""Test get_entity_ids with a non group state."""
assert [] == group.get_entity_ids(hass, "switch.AC")
assert group.get_entity_ids(hass, "switch.AC") == []
async def test_group_being_init_before_first_tracked_state_is_set_to_on(
@ -620,12 +621,12 @@ async def test_expand_entity_ids_expands_nested_groups(hass: HomeAssistant) -> N
order=None,
)
assert [
assert sorted(group.expand_entity_ids(hass, ["group.group_of_groups"])) == [
"light.test_1",
"light.test_2",
"switch.test_1",
"switch.test_2",
] == sorted(group.expand_entity_ids(hass, ["group.group_of_groups"]))
]
async def test_set_assumed_state_based_on_tracked(hass: HomeAssistant) -> None:

View File

@ -179,14 +179,14 @@ async def test_get_hvac_modes(
state = hass.states.get(ENTITY_CLIMATE)
modes = state.attributes.get("hvac_modes")
assert [
assert modes == [
HVACMode.AUTO,
HVACMode.OFF,
HVACMode.COOL,
HVACMode.HEAT,
HVACMode.DRY,
HVACMode.FAN_ONLY,
] == modes
]
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])

View File

@ -141,7 +141,7 @@ async def test_get_operation_modes(
await mqtt_mock_entry()
state = hass.states.get(ENTITY_WATER_HEATER)
assert [
assert state.attributes.get("operation_list") == [
STATE_ECO,
STATE_ELECTRIC,
STATE_GAS,
@ -149,7 +149,7 @@ async def test_get_operation_modes(
STATE_HIGH_DEMAND,
STATE_PERFORMANCE,
STATE_OFF,
] == state.attributes.get("operation_list")
]
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])

View File

@ -325,10 +325,10 @@ async def test_config_bad_children(hass: HomeAssistant) -> None:
config_bad_children = {"name": "test", "children": {}, "platform": "universal"}
config_no_children = validate_config(config_no_children)
assert [] == config_no_children["children"]
assert config_no_children["children"] == []
config_bad_children = validate_config(config_bad_children)
assert [] == config_bad_children["children"]
assert config_bad_children["children"] == []
async def test_config_bad_commands(hass: HomeAssistant) -> None:
@ -336,7 +336,7 @@ async def test_config_bad_commands(hass: HomeAssistant) -> None:
config = {"name": "test", "platform": "universal"}
config = validate_config(config)
assert {} == config["commands"]
assert config["commands"] == {}
async def test_config_bad_attributes(hass: HomeAssistant) -> None:
@ -344,7 +344,7 @@ async def test_config_bad_attributes(hass: HomeAssistant) -> None:
config = {"name": "test", "platform": "universal"}
config = validate_config(config)
assert {} == config["attributes"]
assert config["attributes"] == {}
async def test_config_bad_key(hass: HomeAssistant) -> None:

View File

@ -193,12 +193,12 @@ def test_platform_config() -> None:
def test_ensure_list() -> None:
"""Test ensure_list."""
schema = vol.Schema(cv.ensure_list)
assert [] == schema(None)
assert [1] == schema(1)
assert [1] == schema([1])
assert ["1"] == schema("1")
assert ["1"] == schema(["1"])
assert [{"1": "2"}] == schema({"1": "2"})
assert schema(None) == []
assert schema(1) == [1]
assert schema([1]) == [1]
assert schema("1") == ["1"]
assert schema(["1"]) == ["1"]
assert schema({"1": "2"}) == [{"1": "2"}]
def test_entity_id() -> None:
@ -965,7 +965,7 @@ def test_deprecated_with_replacement_key(
assert (
"The 'mars' option is deprecated, please replace it with 'jupiter'"
) in caplog.text
assert {"jupiter": True} == output
assert output == {"jupiter": True}
caplog.clear()
assert len(caplog.records) == 0
@ -1036,7 +1036,7 @@ def test_deprecated_with_replacement_key_and_default(
assert (
"The 'mars' option is deprecated, please replace it with 'jupiter'"
) in caplog.text
assert {"jupiter": True} == output
assert output == {"jupiter": True}
caplog.clear()
assert len(caplog.records) == 0
@ -1049,7 +1049,7 @@ def test_deprecated_with_replacement_key_and_default(
test_data = {"venus": True}
output = deprecated_schema(test_data.copy())
assert len(caplog.records) == 0
assert {"venus": True, "jupiter": False} == output
assert output == {"venus": True, "jupiter": False}
deprecated_schema_with_default = vol.All(
vol.Schema(
@ -1068,7 +1068,7 @@ def test_deprecated_with_replacement_key_and_default(
assert (
"The 'mars' option is deprecated, please replace it with 'jupiter'"
) in caplog.text
assert {"jupiter": True} == output
assert output == {"jupiter": True}
def test_deprecated_cant_find_module() -> None:

View File

@ -117,7 +117,7 @@ async def test_setup_does_discovery(
await hass.async_block_till_done()
assert mock_setup.called
assert ("platform_test", {}, {"msg": "discovery_info"}) == mock_setup.call_args[0]
assert mock_setup.call_args[0] == ("platform_test", {}, {"msg": "discovery_info"})
async def test_set_scan_interval_via_config(hass: HomeAssistant) -> None:
@ -191,9 +191,9 @@ async def test_extract_from_service_available_device(hass: HomeAssistant) -> Non
call_1 = ServiceCall("test", "service", data={"entity_id": ENTITY_MATCH_ALL})
assert ["test_domain.test_1", "test_domain.test_3"] == sorted(
assert sorted(
ent.entity_id for ent in (await component.async_extract_from_service(call_1))
)
) == ["test_domain.test_1", "test_domain.test_3"]
call_2 = ServiceCall(
"test",
@ -201,9 +201,9 @@ async def test_extract_from_service_available_device(hass: HomeAssistant) -> Non
data={"entity_id": ["test_domain.test_3", "test_domain.test_4"]},
)
assert ["test_domain.test_3"] == sorted(
assert sorted(
ent.entity_id for ent in (await component.async_extract_from_service(call_2))
)
) == ["test_domain.test_3"]
async def test_platform_not_ready(hass: HomeAssistant) -> None:
@ -288,9 +288,9 @@ async def test_extract_from_service_filter_out_non_existing_entities(
{"entity_id": ["test_domain.test_2", "test_domain.non_exist"]},
)
assert ["test_domain.test_2"] == [
assert [
ent.entity_id for ent in await component.async_extract_from_service(call)
]
] == ["test_domain.test_2"]
async def test_extract_from_service_no_group_expand(hass: HomeAssistant) -> None:
@ -467,8 +467,11 @@ async def test_extract_all_omit_entity_id(
call = ServiceCall("test", "service")
assert [] == sorted(
ent.entity_id for ent in await component.async_extract_from_service(call)
assert (
sorted(
ent.entity_id for ent in await component.async_extract_from_service(call)
)
== []
)
@ -484,9 +487,9 @@ async def test_extract_all_use_match_all(
call = ServiceCall("test", "service", {"entity_id": "all"})
assert ["test_domain.test_1", "test_domain.test_2"] == sorted(
assert sorted(
ent.entity_id for ent in await component.async_extract_from_service(call)
)
) == ["test_domain.test_1", "test_domain.test_2"]
assert (
"Not passing an entity ID to a service to target all entities is deprecated"
) not in caplog.text

View File

@ -547,7 +547,7 @@ async def test_split_entity_string(hass: HomeAssistant) -> None:
},
)
await hass.async_block_till_done()
assert ["hello.world", "sensor.beer"] == calls[-1].data.get("entity_id")
assert calls[-1].data.get("entity_id") == ["hello.world", "sensor.beer"]
async def test_not_mutate_input(hass: HomeAssistant) -> None:
@ -1792,10 +1792,10 @@ async def test_extract_from_service_available_device(hass: HomeAssistant) -> Non
call_1 = ServiceCall("test", "service", data={"entity_id": ENTITY_MATCH_ALL})
assert ["test_domain.test_1", "test_domain.test_3"] == [
assert [
ent.entity_id
for ent in (await service.async_extract_entities(hass, entities, call_1))
]
] == ["test_domain.test_1", "test_domain.test_3"]
call_2 = ServiceCall(
"test",
@ -1803,10 +1803,10 @@ async def test_extract_from_service_available_device(hass: HomeAssistant) -> Non
data={"entity_id": ["test_domain.test_3", "test_domain.test_4"]},
)
assert ["test_domain.test_3"] == [
assert [
ent.entity_id
for ent in (await service.async_extract_entities(hass, entities, call_2))
]
] == ["test_domain.test_3"]
assert (
await service.async_extract_entities(
@ -1830,10 +1830,10 @@ async def test_extract_from_service_empty_if_no_entity_id(hass: HomeAssistant) -
]
call = ServiceCall("test", "service")
assert [] == [
assert [
ent.entity_id
for ent in (await service.async_extract_entities(hass, entities, call))
]
] == []
async def test_extract_from_service_filter_out_non_existing_entities(
@ -1851,10 +1851,10 @@ async def test_extract_from_service_filter_out_non_existing_entities(
{"entity_id": ["test_domain.test_2", "test_domain.non_exist"]},
)
assert ["test_domain.test_2"] == [
assert [
ent.entity_id
for ent in (await service.async_extract_entities(hass, entities, call))
]
] == ["test_domain.test_2"]
async def test_extract_from_service_area_id(

View File

@ -490,9 +490,10 @@ def test_load_yaml_config_preserves_key_order() -> None:
fp.write("hello: 2\n")
fp.write("world: 1\n")
assert [("hello", 2), ("world", 1)] == list(
config_util.load_yaml_config_file(YAML_PATH).items()
)
assert list(config_util.load_yaml_config_file(YAML_PATH).items()) == [
("hello", 2),
("world", 1),
]
async def test_create_default_config_returns_none_if_write_error(

View File

@ -200,17 +200,17 @@ def test_color_hs_to_xy() -> None:
def test_rgb_hex_to_rgb_list() -> None:
"""Test rgb_hex_to_rgb_list."""
assert [255, 255, 255] == color_util.rgb_hex_to_rgb_list("ffffff")
assert color_util.rgb_hex_to_rgb_list("ffffff") == [255, 255, 255]
assert [0, 0, 0] == color_util.rgb_hex_to_rgb_list("000000")
assert color_util.rgb_hex_to_rgb_list("000000") == [0, 0, 0]
assert [255, 255, 255, 255] == color_util.rgb_hex_to_rgb_list("ffffffff")
assert color_util.rgb_hex_to_rgb_list("ffffffff") == [255, 255, 255, 255]
assert [0, 0, 0, 0] == color_util.rgb_hex_to_rgb_list("00000000")
assert color_util.rgb_hex_to_rgb_list("00000000") == [0, 0, 0, 0]
assert [51, 153, 255] == color_util.rgb_hex_to_rgb_list("3399ff")
assert color_util.rgb_hex_to_rgb_list("3399ff") == [51, 153, 255]
assert [51, 153, 255, 0] == color_util.rgb_hex_to_rgb_list("3399ff00")
assert color_util.rgb_hex_to_rgb_list("3399ff00") == [51, 153, 255, 0]
def test_color_name_to_rgb_valid_name() -> None:

View File

@ -294,12 +294,12 @@ def test_parse_time_expression() -> None:
assert list(range(0, 60, 5)) == dt_util.parse_time_expression("/5", 0, 59)
assert [1, 2, 3] == dt_util.parse_time_expression([2, 1, 3], 0, 59)
assert dt_util.parse_time_expression([2, 1, 3], 0, 59) == [1, 2, 3]
assert list(range(24)) == dt_util.parse_time_expression("*", 0, 23)
assert [42] == dt_util.parse_time_expression(42, 0, 59)
assert [42] == dt_util.parse_time_expression("42", 0, 59)
assert dt_util.parse_time_expression(42, 0, 59) == [42]
assert dt_util.parse_time_expression("42", 0, 59) == [42]
with pytest.raises(ValueError):
dt_util.parse_time_expression(61, 0, 60)