mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Use set literals in tests (#33669)
This commit is contained in:
parent
d267d674b9
commit
03dd92d51b
@ -167,7 +167,7 @@ def assert_endpoint_capabilities(endpoint, *interfaces):
|
|||||||
them.
|
them.
|
||||||
"""
|
"""
|
||||||
capabilities = endpoint["capabilities"]
|
capabilities = endpoint["capabilities"]
|
||||||
supported = set(feature["interface"] for feature in capabilities)
|
supported = {feature["interface"] for feature in capabilities}
|
||||||
|
|
||||||
assert supported == set(interfaces)
|
assert supported == set(interfaces)
|
||||||
return capabilities
|
return capabilities
|
||||||
|
@ -181,7 +181,7 @@ async def test_discover_lights(hue_client):
|
|||||||
|
|
||||||
result_json = await result.json()
|
result_json = await result.json()
|
||||||
|
|
||||||
devices = set(val["uniqueid"] for val in result_json.values())
|
devices = {val["uniqueid"] for val in result_json.values()}
|
||||||
|
|
||||||
# Make sure the lights we added to the config are there
|
# Make sure the lights we added to the config are there
|
||||||
assert "00:2f:d2:31:ce:c5:55:cc-ee" in devices # light.ceiling_lights
|
assert "00:2f:d2:31:ce:c5:55:cc-ee" in devices # light.ceiling_lights
|
||||||
|
@ -295,7 +295,7 @@ class TestComponentsGroup(unittest.TestCase):
|
|||||||
|
|
||||||
group_state = self.hass.states.get(f"{group.DOMAIN}.second_group")
|
group_state = self.hass.states.get(f"{group.DOMAIN}.second_group")
|
||||||
assert STATE_ON == group_state.state
|
assert STATE_ON == group_state.state
|
||||||
assert set((test_group.entity_id, "light.bowl")) == set(
|
assert {test_group.entity_id, "light.bowl"} == set(
|
||||||
group_state.attributes["entity_id"]
|
group_state.attributes["entity_id"]
|
||||||
)
|
)
|
||||||
assert group_state.attributes.get(group.ATTR_AUTO) is None
|
assert group_state.attributes.get(group.ATTR_AUTO) is None
|
||||||
@ -304,7 +304,7 @@ class TestComponentsGroup(unittest.TestCase):
|
|||||||
|
|
||||||
group_state = self.hass.states.get(f"{group.DOMAIN}.test_group")
|
group_state = self.hass.states.get(f"{group.DOMAIN}.test_group")
|
||||||
assert STATE_UNKNOWN == group_state.state
|
assert STATE_UNKNOWN == group_state.state
|
||||||
assert set(("sensor.happy", "hello.world")) == set(
|
assert {"sensor.happy", "hello.world"} == set(
|
||||||
group_state.attributes["entity_id"]
|
group_state.attributes["entity_id"]
|
||||||
)
|
)
|
||||||
assert group_state.attributes.get(group.ATTR_AUTO) is None
|
assert group_state.attributes.get(group.ATTR_AUTO) is None
|
||||||
|
@ -23,8 +23,8 @@ async def test_bridge_setup(hass):
|
|||||||
|
|
||||||
assert hue_bridge.api is api
|
assert hue_bridge.api is api
|
||||||
assert len(mock_forward.mock_calls) == 3
|
assert len(mock_forward.mock_calls) == 3
|
||||||
forward_entries = set(c[1][1] for c in mock_forward.mock_calls)
|
forward_entries = {c[1][1] for c in mock_forward.mock_calls}
|
||||||
assert forward_entries == set(["light", "binary_sensor", "sensor"])
|
assert forward_entries == {"light", "binary_sensor", "sensor"}
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_setup_invalid_username(hass):
|
async def test_bridge_setup_invalid_username(hass):
|
||||||
|
@ -43,7 +43,7 @@ async def test_new_message(hass, mock_device_tracker_conf):
|
|||||||
topic = "/location/paulus"
|
topic = "/location/paulus"
|
||||||
location = "work"
|
location = "work"
|
||||||
|
|
||||||
hass.config.components = set(["mqtt", "zone"])
|
hass.config.components = {"mqtt", "zone"}
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {dev_id: topic}}}
|
hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {dev_id: topic}}}
|
||||||
)
|
)
|
||||||
@ -60,7 +60,7 @@ async def test_single_level_wildcard_topic(hass, mock_device_tracker_conf):
|
|||||||
topic = "/location/room/paulus"
|
topic = "/location/room/paulus"
|
||||||
location = "work"
|
location = "work"
|
||||||
|
|
||||||
hass.config.components = set(["mqtt", "zone"])
|
hass.config.components = {"mqtt", "zone"}
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -79,7 +79,7 @@ async def test_multi_level_wildcard_topic(hass, mock_device_tracker_conf):
|
|||||||
topic = "/location/room/paulus"
|
topic = "/location/room/paulus"
|
||||||
location = "work"
|
location = "work"
|
||||||
|
|
||||||
hass.config.components = set(["mqtt", "zone"])
|
hass.config.components = {"mqtt", "zone"}
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -98,7 +98,7 @@ async def test_single_level_wildcard_topic_not_matching(hass, mock_device_tracke
|
|||||||
topic = "/location/paulus"
|
topic = "/location/paulus"
|
||||||
location = "work"
|
location = "work"
|
||||||
|
|
||||||
hass.config.components = set(["mqtt", "zone"])
|
hass.config.components = {"mqtt", "zone"}
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -117,7 +117,7 @@ async def test_multi_level_wildcard_topic_not_matching(hass, mock_device_tracker
|
|||||||
topic = "/somewhere/room/paulus"
|
topic = "/somewhere/room/paulus"
|
||||||
location = "work"
|
location = "work"
|
||||||
|
|
||||||
hass.config.components = set(["mqtt", "zone"])
|
hass.config.components = {"mqtt", "zone"}
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -138,7 +138,7 @@ async def test_matching_custom_payload_for_home_and_not_home(
|
|||||||
payload_home = "present"
|
payload_home = "present"
|
||||||
payload_not_home = "not present"
|
payload_not_home = "not present"
|
||||||
|
|
||||||
hass.config.components = set(["mqtt", "zone"])
|
hass.config.components = {"mqtt", "zone"}
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -171,7 +171,7 @@ async def test_not_matching_custom_payload_for_home_and_not_home(
|
|||||||
payload_not_home = "not present"
|
payload_not_home = "not present"
|
||||||
payload_not_matching = "test"
|
payload_not_matching = "test"
|
||||||
|
|
||||||
hass.config.components = set(["mqtt", "zone"])
|
hass.config.components = {"mqtt", "zone"}
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -198,7 +198,7 @@ async def test_matching_source_type(hass, mock_device_tracker_conf):
|
|||||||
source_type = SOURCE_TYPE_BLUETOOTH
|
source_type = SOURCE_TYPE_BLUETOOTH
|
||||||
location = "work"
|
location = "work"
|
||||||
|
|
||||||
hass.config.components = set(["mqtt", "zone"])
|
hass.config.components = {"mqtt", "zone"}
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -115,13 +115,9 @@ async def test_devices(
|
|||||||
}
|
}
|
||||||
|
|
||||||
entity_map = device["entity_map"]
|
entity_map = device["entity_map"]
|
||||||
assert zha_entity_ids == set(
|
assert zha_entity_ids == {
|
||||||
[
|
e["entity_id"] for e in entity_map.values() if not e.get("default_match", False)
|
||||||
e["entity_id"]
|
}
|
||||||
for e in entity_map.values()
|
|
||||||
if not e.get("default_match", False)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
assert event_channels == set(device["event_channels"])
|
assert event_channels == set(device["event_channels"])
|
||||||
|
|
||||||
for call in _dispatch.call_args_list:
|
for call in _dispatch.call_args_list:
|
||||||
@ -133,7 +129,7 @@ async def test_devices(
|
|||||||
assert entity_id is not None
|
assert entity_id is not None
|
||||||
no_tail_id = NO_TAIL_ID.sub("", entity_map[key]["entity_id"])
|
no_tail_id = NO_TAIL_ID.sub("", entity_map[key]["entity_id"])
|
||||||
assert entity_id.startswith(no_tail_id)
|
assert entity_id.startswith(no_tail_id)
|
||||||
assert set([ch.name for ch in channels]) == set(entity_map[key]["channels"])
|
assert {ch.name for ch in channels} == set(entity_map[key]["channels"])
|
||||||
assert entity_cls.__name__ == entity_map[key]["entity_class"]
|
assert entity_cls.__name__ == entity_map[key]["entity_class"]
|
||||||
|
|
||||||
|
|
||||||
@ -281,7 +277,7 @@ async def test_discover_endpoint(device_info, channels_mock, hass):
|
|||||||
map_id = (comp, unique_id)
|
map_id = (comp, unique_id)
|
||||||
assert map_id in device_info["entity_map"]
|
assert map_id in device_info["entity_map"]
|
||||||
entity_info = device_info["entity_map"][map_id]
|
entity_info = device_info["entity_map"][map_id]
|
||||||
assert set([ch.name for ch in channels]) == set(entity_info["channels"])
|
assert {ch.name for ch in channels} == set(entity_info["channels"])
|
||||||
assert ent_cls.__name__ == entity_info["entity_class"]
|
assert ent_cls.__name__ == entity_info["entity_class"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ def test_match_rule_claim_channels_color(channel):
|
|||||||
|
|
||||||
rule = registries.MatchRule(channel_names="on_off", aux_channels={"color", "level"})
|
rule = registries.MatchRule(channel_names="on_off", aux_channels={"color", "level"})
|
||||||
claimed = rule.claim_channels([ch_color, ch_level, ch_onoff])
|
claimed = rule.claim_channels([ch_color, ch_level, ch_onoff])
|
||||||
assert {"color", "level", "on_off"} == set([ch.name for ch in claimed])
|
assert {"color", "level", "on_off"} == {ch.name for ch in claimed}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -253,7 +253,7 @@ def test_match_rule_claim_channels(rule, match, channel, channels):
|
|||||||
channels.append(ch_power)
|
channels.append(ch_power)
|
||||||
|
|
||||||
claimed = rule.claim_channels(channels)
|
claimed = rule.claim_channels(channels)
|
||||||
assert match == set([ch.name for ch in claimed])
|
assert match == {ch.name for ch in claimed}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -15,7 +15,7 @@ def test_extract_domain_configs():
|
|||||||
"zone 100": None,
|
"zone 100": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert set(["zone", "zone Hallo", "zone 100"]) == set(
|
assert {"zone", "zone Hallo", "zone 100"} == set(
|
||||||
helpers.extract_domain_configs(config, "zone")
|
helpers.extract_domain_configs(config, "zone")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -920,7 +920,7 @@ class TestConfig(unittest.TestCase):
|
|||||||
with TemporaryDirectory() as tmp_dir:
|
with TemporaryDirectory() as tmp_dir:
|
||||||
# The created dir is in /tmp. This is a symlink on OS X
|
# The created dir is in /tmp. This is a symlink on OS X
|
||||||
# causing this test to fail unless we resolve path first.
|
# causing this test to fail unless we resolve path first.
|
||||||
self.config.whitelist_external_dirs = set((os.path.realpath(tmp_dir),))
|
self.config.whitelist_external_dirs = {os.path.realpath(tmp_dir)}
|
||||||
|
|
||||||
test_file = os.path.join(tmp_dir, "test.jpg")
|
test_file = os.path.join(tmp_dir, "test.jpg")
|
||||||
with open(test_file, "w") as tmp_file:
|
with open(test_file, "w") as tmp_file:
|
||||||
@ -930,7 +930,7 @@ class TestConfig(unittest.TestCase):
|
|||||||
for path in valid:
|
for path in valid:
|
||||||
assert self.config.is_allowed_path(path)
|
assert self.config.is_allowed_path(path)
|
||||||
|
|
||||||
self.config.whitelist_external_dirs = set(("/home", "/var"))
|
self.config.whitelist_external_dirs = {"/home", "/var"}
|
||||||
|
|
||||||
unvalid = [
|
unvalid = [
|
||||||
"/hass/config/secure",
|
"/hass/config/secure",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user