Skip to content

Commit a2a87f2

Browse files
committed
test: Name the core tests that the collection filter never matched
core matches python_functions = test_it_*, so a test named anything else is not skipped or reported, it simply never exists. Forty six had accumulated that way, including every test of the Gen1 auth path, of the legacy HTTP client's auth handling, and of the EM component accessors. They now carry the name the convention asks for, and run. Two had drifted while nothing ran them: the legacy gateway gained a timeout argument its caller now passes, and an expired entry count had been written for one entry in a case that expires two, which the same test's own later assertions already said.
1 parent 1e53578 commit a2a87f2

7 files changed

Lines changed: 53 additions & 49 deletions

File tree

packages/core/tests/unit/domain/entities/test_device_status.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def test_it_creates_zigbee_component_from_status_only(self):
559559
class TestDeviceStatusEMComponents:
560560
"""Test EM component support and total_power calculation."""
561561

562-
def test_total_power_with_em_only(self):
562+
def test_it_totals_power_with_em_only(self):
563563
"""Pro 3EM device with no switches -- total_power should come from EM."""
564564
em_comp = EMComponent(
565565
key="em:0",
@@ -576,7 +576,7 @@ def test_total_power_with_em_only(self):
576576
assert summary["total_power"] == 312.278
577577
assert summary["switch_count"] == 0
578578

579-
def test_total_power_with_em1_only(self):
579+
def test_it_totals_power_with_em1_only(self):
580580
"""Pro EM device with multiple EM1 channels and no switches."""
581581
em1_a = EM1Component(key="em1:0", component_type="em1", act_power=951.2)
582582
em1_b = EM1Component(key="em1:1", component_type="em1", act_power=200.5)
@@ -589,7 +589,7 @@ def test_total_power_with_em1_only(self):
589589
assert summary["total_power"] == pytest.approx(1151.7)
590590
assert summary["switch_count"] == 0
591591

592-
def test_total_power_with_switches_and_em(self):
592+
def test_it_totals_power_with_switches_and_em(self):
593593
"""Mixed device with both switches and EM components."""
594594
switch_comp = SwitchComponent(
595595
key="switch:0", component_type="switch", output=True, power=100.0
@@ -604,7 +604,7 @@ def test_total_power_with_switches_and_em(self):
604604
assert summary["total_power"] == pytest.approx(412.278)
605605
assert summary["switch_count"] == 1
606606

607-
def test_total_power_with_switches_only(self):
607+
def test_it_totals_power_with_switches_only(self):
608608
"""Backward compatibility: switch-only devices still work."""
609609
switch_a = SwitchComponent(
610610
key="switch:0", component_type="switch", output=True, power=50.0
@@ -621,14 +621,14 @@ def test_total_power_with_switches_only(self):
621621
assert summary["total_power"] == 50.0
622622
assert summary["switch_count"] == 2
623623

624-
def test_total_power_with_no_power_components(self):
624+
def test_it_totals_power_with_no_power_components(self):
625625
"""Pure sensor device with no power-producing components."""
626626
device_status = DeviceStatus(device_ip="192.168.1.100", components=[])
627627

628628
summary = device_status.get_device_summary()
629629
assert summary["total_power"] == 0
630630

631-
def test_total_power_with_null_em_power(self):
631+
def test_it_totals_power_with_null_em_power(self):
632632
"""EM component with None total_act_power should not break sum."""
633633
em_comp = EMComponent(key="em:0", component_type="em", total_act_power=None)
634634
switch_comp = SwitchComponent(
@@ -642,7 +642,7 @@ def test_total_power_with_null_em_power(self):
642642
summary = device_status.get_device_summary()
643643
assert summary["total_power"] == 100.0
644644

645-
def test_total_power_with_null_em1_power(self):
645+
def test_it_totals_power_with_null_em1_power(self):
646646
"""EM1 component with None act_power should not break sum."""
647647
em1_comp = EM1Component(key="em1:0", component_type="em1", act_power=None)
648648

@@ -651,7 +651,7 @@ def test_total_power_with_null_em1_power(self):
651651
summary = device_status.get_device_summary()
652652
assert summary["total_power"] == 0
653653

654-
def test_get_em_components(self):
654+
def test_it_gets_em_components(self):
655655
em_comp = EMComponent(key="em:0", component_type="em", total_act_power=312.0)
656656
switch_comp = SwitchComponent(
657657
key="switch:0", component_type="switch", output=True, power=50.0
@@ -665,7 +665,7 @@ def test_get_em_components(self):
665665
assert len(em_components) == 1
666666
assert em_components[0].total_act_power == 312.0
667667

668-
def test_get_em1_components(self):
668+
def test_it_gets_em1_components(self):
669669
em1_a = EM1Component(key="em1:0", component_type="em1", act_power=951.2)
670670
em1_b = EM1Component(key="em1:1", component_type="em1", act_power=200.5)
671671

@@ -676,7 +676,7 @@ def test_get_em1_components(self):
676676
em1_components = device_status.get_em1_components()
677677
assert len(em1_components) == 2
678678

679-
def test_get_em_data_components(self):
679+
def test_it_gets_em_data_components(self):
680680
emdata_comp = EMDataComponent(
681681
key="emdata:0", component_type="emdata", total_act=344297.48
682682
)
@@ -689,7 +689,7 @@ def test_get_em_data_components(self):
689689
assert len(em_data) == 1
690690
assert em_data[0].total_act == 344297.48
691691

692-
def test_get_em1_data_components(self):
692+
def test_it_gets_em1_data_components(self):
693693
em1data_comp = EM1DataComponent(
694694
key="em1data:0", component_type="em1data", total_act_energy=12345.67
695695
)
@@ -702,7 +702,7 @@ def test_get_em1_data_components(self):
702702
assert len(em1_data) == 1
703703
assert em1_data[0].total_act_energy == 12345.67
704704

705-
def test_em_components_created_from_raw_response(self):
705+
def test_it_creates_em_components_from_a_raw_response(self):
706706
"""Test that EM components are properly created from raw API response."""
707707
device_ip = "192.168.1.100"
708708
response_data = {

packages/core/tests/unit/domain/value_objects/test_action_name.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_it_still_honours_a_namespace_the_component_owns(
184184
):
185185
assert ActionName.of(action).resolve(component_key, self.METHODS) == expected
186186

187-
def test_a_bare_method_still_searches_the_components_namespaces(self):
187+
def test_it_searches_the_components_namespaces_for_a_bare_method(self):
188188
assert ActionName.of("FactoryReset").resolve("sys", self.METHODS) == (
189189
"Shelly.FactoryReset"
190190
)
@@ -197,7 +197,7 @@ def test_it_keeps_an_owned_qualified_action_working_without_a_method_list(self):
197197
def test_it_refuses_an_unowned_qualified_action_without_a_method_list(self):
198198
assert ActionName.of("Shelly.FactoryReset").resolve("wifi", []) is None
199199

200-
def test_a_bare_method_still_works_without_a_method_list(self):
200+
def test_it_resolves_a_bare_method_without_a_method_list(self):
201201
assert ActionName.of("SetConfig").resolve("wifi", []) == "Wifi.SetConfig"
202202

203203

@@ -212,12 +212,12 @@ def test_it_splits_only_at_the_first_dot(self):
212212
assert action.namespace == "BLE"
213213
assert action.method == "CloudRelay.List"
214214

215-
def test_a_listed_name_pasted_back_still_resolves(self):
215+
def test_it_resolves_a_listed_name_pasted_back(self):
216216
action = ActionName.of("BLE.CloudRelay.List")
217217

218218
assert action.resolve("ble", self.METHODS) == "BLE.CloudRelay.List"
219219

220-
def test_dropping_the_leading_namespace_reads_as_another_one_and_is_refused(self):
220+
def test_it_refuses_a_name_whose_leading_namespace_was_dropped(self):
221221
action = ActionName.of("CloudRelay.List")
222222

223223
assert action.namespace == "CloudRelay"

packages/core/tests/unit/domain/value_objects/test_component_namespace.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,19 @@ def test_it_returns_nothing_when_the_device_reported_nothing(self):
145145

146146

147147
class TestOwnershipIsNotALoosePrefix:
148-
def test_zigbee_owns_its_named_shelly_method_and_nothing_else_under_shelly(self):
148+
def test_it_gives_zigbee_its_named_shelly_method_and_nothing_else(self):
149149
namespace = ComponentNamespace.for_component_type("zigbee")
150150

151151
assert namespace.owns("Shelly.ZigbeeClear") is True
152152
assert namespace.owns("Shelly.ZigbeeAnything") is False
153153
assert namespace.owns("Shelly.FactoryReset") is False
154154

155-
def test_an_exact_entry_still_matches_the_device_casing(self):
155+
def test_it_matches_the_device_casing_from_an_exact_entry(self):
156156
namespace = ComponentNamespace.for_component_type("zigbee")
157157

158158
assert namespace.actions_in(["shelly.zigbeeclear"]) == ["shelly.zigbeeclear"]
159159

160-
def test_a_namespace_prefix_entry_still_matches_a_whole_family(self):
160+
def test_it_matches_a_whole_family_from_a_namespace_prefix_entry(self):
161161
namespace = ComponentNamespace.for_component_type("zigbee")
162162

163163
assert namespace.actions_in(["Zigbee.GetStatus", "Zigbee.SetConfig"]) == [

packages/core/tests/unit/gateways/device/test_legacy_component_mapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_it_treats_garbage_auto_timer_as_disabled(self, mapper):
9494

9595

9696
class TestSwitchComponentAcceptsMappedGen1Relay:
97-
def test_switch_component_accepts_mapped_relay_with_timer(self, mapper):
97+
def test_it_accepts_a_mapped_relay_with_a_timer(self, mapper):
9898
components = mapper.map(
9999
{"mac": "AABBCCDDEEFF", "type": "SHSW-1"},
100100
{"relays": [{"ison": True}]},
@@ -110,7 +110,7 @@ def test_switch_component_accepts_mapped_relay_with_timer(self, mapper):
110110
assert component.config["auto_off_delay"] == 0.5
111111
assert component.config["auto_on_delay"] == 30.0
112112

113-
def test_raw_numeric_seconds_still_raise_at_the_component(self):
113+
def test_it_still_raises_at_the_component_on_raw_numeric_seconds(self):
114114
# The component stays strict on purpose; only the mapper heals raw seconds.
115115
with pytest.raises(ValidationError):
116116
SwitchComponent.from_raw_data(

packages/core/tests/unit/gateways/device/test_legacy_device_gateway_auth.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,17 @@ def sample_credential(self):
6969

7070
# --- _ensure_mac ---
7171

72-
async def test_ensure_mac_fetches_from_shelly(self, gateway, mock_http_client):
72+
async def test_it_fetches_the_mac_from_shelly(self, gateway, mock_http_client):
7373
mock_http_client.fetch_json.return_value = {"mac": "AA:BB:CC:DD:EE:FF"}
7474

7575
mac = await gateway._ensure_mac("192.168.1.100")
7676

7777
assert mac == "AABBCCDDEEFF"
78-
mock_http_client.fetch_json.assert_called_once_with("192.168.1.100", "shelly")
78+
mock_http_client.fetch_json.assert_called_once_with(
79+
"192.168.1.100", "shelly", timeout=None
80+
)
7981

80-
async def test_ensure_mac_caches_result(self, gateway, mock_http_client):
82+
async def test_it_caches_the_mac_it_fetched(self, gateway, mock_http_client):
8183
mock_http_client.fetch_json.return_value = {"mac": "AABBCCDDEEFF"}
8284

8385
await gateway._ensure_mac("192.168.1.100")
@@ -86,14 +88,16 @@ async def test_ensure_mac_caches_result(self, gateway, mock_http_client):
8688
assert mac == "AABBCCDDEEFF"
8789
assert mock_http_client.fetch_json.call_count == 1
8890

89-
async def test_ensure_mac_returns_none_on_failure(self, gateway, mock_http_client):
91+
async def test_it_has_no_mac_when_the_fetch_fails(self, gateway, mock_http_client):
9092
mock_http_client.fetch_json.side_effect = Exception("timeout")
9193

9294
mac = await gateway._ensure_mac("192.168.1.100")
9395

9496
assert mac is None
9597

96-
async def test_ensure_mac_returns_none_when_no_mac(self, gateway, mock_http_client):
98+
async def test_it_has_no_mac_when_the_device_reports_none(
99+
self, gateway, mock_http_client
100+
):
97101
mock_http_client.fetch_json.return_value = {"type": "SHSW-1"}
98102

99103
mac = await gateway._ensure_mac("192.168.1.100")
@@ -102,7 +106,7 @@ async def test_ensure_mac_returns_none_when_no_mac(self, gateway, mock_http_clie
102106

103107
# --- _resolve_auth ---
104108

105-
async def test_resolve_auth_returns_credentials(
109+
async def test_it_resolves_credentials(
106110
self, gateway, mock_http_client, mock_auth_service, sample_credential
107111
):
108112
mock_http_client.fetch_json.return_value = {"mac": "AABBCCDDEEFF"}
@@ -113,7 +117,7 @@ async def test_resolve_auth_returns_credentials(
113117
assert auth == ("admin", "secret")
114118
mock_auth_service.resolve_credentials.assert_called_once_with("AABBCCDDEEFF")
115119

116-
async def test_resolve_auth_caches_credentials(
120+
async def test_it_caches_resolved_credentials(
117121
self, gateway, mock_http_client, mock_auth_service, sample_credential
118122
):
119123
mock_http_client.fetch_json.return_value = {"mac": "AABBCCDDEEFF"}
@@ -125,14 +129,14 @@ async def test_resolve_auth_caches_credentials(
125129
assert auth == ("admin", "secret")
126130
assert mock_auth_service.resolve_credentials.call_count == 1
127131

128-
async def test_resolve_auth_returns_none_without_service(
132+
async def test_it_resolves_nothing_without_an_authentication_service(
129133
self, gateway_no_auth, mock_http_client
130134
):
131135
auth = await gateway_no_auth._resolve_auth("192.168.1.100")
132136

133137
assert auth is None
134138

135-
async def test_resolve_auth_returns_none_when_no_credential(
139+
async def test_it_resolves_nothing_when_no_credential_is_stored(
136140
self, gateway, mock_http_client, mock_auth_service
137141
):
138142
mock_http_client.fetch_json.return_value = {"mac": "AABBCCDDEEFF"}
@@ -144,7 +148,7 @@ async def test_resolve_auth_returns_none_when_no_credential(
144148

145149
# --- discover_device with auth ---
146150

147-
async def test_discover_detects_auth_and_fetches_with_credentials(
151+
async def test_it_detects_auth_and_discovers_with_credentials(
148152
self,
149153
gateway,
150154
mock_http_client,
@@ -169,7 +173,7 @@ async def test_discover_detects_auth_and_fetches_with_credentials(
169173
for call in mock_http_client.fetch_json_optional.call_args_list:
170174
assert call[1].get("auth") == ("admin", "secret")
171175

172-
async def test_discover_no_auth_when_not_required(
176+
async def test_it_discovers_without_auth_when_it_is_not_required(
173177
self,
174178
gateway,
175179
mock_http_client,
@@ -192,7 +196,7 @@ async def test_discover_no_auth_when_not_required(
192196

193197
# --- get_device_status with auth ---
194198

195-
async def test_get_device_status_uses_proactive_auth(
199+
async def test_it_reads_status_with_proactive_auth(
196200
self,
197201
gateway,
198202
mock_http_client,
@@ -217,7 +221,7 @@ async def test_get_device_status_uses_proactive_auth(
217221
status_call = mock_http_client.fetch_json.call_args_list[1]
218222
assert status_call[1].get("auth") == ("admin", "secret")
219223

220-
async def test_get_device_status_raises_on_auth_failure(
224+
async def test_it_raises_on_auth_failure_while_reading_status(
221225
self,
222226
gateway,
223227
mock_http_client,
@@ -236,7 +240,7 @@ async def test_get_device_status_raises_on_auth_failure(
236240

237241
# --- execute_action with auth ---
238242

239-
async def test_execute_action_sends_auth(
243+
async def test_it_sends_auth_with_an_action(
240244
self,
241245
gateway,
242246
mock_http_client,
@@ -255,7 +259,7 @@ async def test_execute_action_sends_auth(
255259
call_kwargs = mock_http_client.get_with_params.call_args[1]
256260
assert call_kwargs.get("auth") == ("admin", "secret")
257261

258-
async def test_execute_action_no_auth_without_service(
262+
async def test_it_sends_no_auth_with_an_action_without_a_service(
259263
self, gateway_no_auth, mock_http_client
260264
):
261265
mock_http_client.get_with_params.return_value = {"ison": True}
@@ -270,13 +274,13 @@ async def test_execute_action_no_auth_without_service(
270274

271275
# --- invalidate_credential_cache ---
272276

273-
async def test_invalidate_credential_cache(self, gateway):
277+
async def test_it_invalidates_the_credential_cache(self, gateway):
274278
gateway._basic_auth_cache["AABBCCDDEEFF"] = ("admin", "old_pass")
275279

276280
gateway.invalidate_credential_cache("AA:BB:CC:DD:EE:FF")
277281

278282
assert "AABBCCDDEEFF" not in gateway._basic_auth_cache
279283

280-
async def test_invalidate_credential_cache_noop_for_unknown(self, gateway):
284+
async def test_it_invalidates_nothing_for_an_unknown_device(self, gateway):
281285
# Should not raise
282286
gateway.invalidate_credential_cache("FFFFFFFFFFFF")

packages/core/tests/unit/gateways/network/test_legacy_http_client_auth.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _mock_ok_response(self, data: dict) -> MagicMock:
2424
resp.json.return_value = data
2525
return resp
2626

27-
async def test_fetch_json_passes_auth_to_session(self, client, mock_session):
27+
async def test_it_passes_auth_to_the_session(self, client, mock_session):
2828
mock_session.get.return_value = self._mock_ok_response({"ok": True})
2929

3030
result = await client.fetch_json(
@@ -35,15 +35,15 @@ async def test_fetch_json_passes_auth_to_session(self, client, mock_session):
3535
call_kwargs = mock_session.get.call_args[1]
3636
assert call_kwargs["auth"] == ("admin", "secret")
3737

38-
async def test_fetch_json_passes_none_auth_by_default(self, client, mock_session):
38+
async def test_it_passes_no_auth_by_default(self, client, mock_session):
3939
mock_session.get.return_value = self._mock_ok_response({"ok": True})
4040

4141
await client.fetch_json("192.168.1.1", "status")
4242

4343
call_kwargs = mock_session.get.call_args[1]
4444
assert call_kwargs["auth"] is None
4545

46-
async def test_fetch_json_optional_passes_auth(self, client, mock_session):
46+
async def test_it_passes_auth_on_an_optional_fetch(self, client, mock_session):
4747
mock_session.get.return_value = self._mock_ok_response({"ok": True})
4848

4949
result = await client.fetch_json_optional(
@@ -54,7 +54,7 @@ async def test_fetch_json_optional_passes_auth(self, client, mock_session):
5454
call_kwargs = mock_session.get.call_args[1]
5555
assert call_kwargs["auth"] == ("admin", "pw")
5656

57-
async def test_get_with_params_passes_auth(self, client, mock_session):
57+
async def test_it_passes_auth_with_params(self, client, mock_session):
5858
mock_session.get.return_value = self._mock_ok_response({"ison": True})
5959

6060
result = await client.get_with_params(
@@ -65,7 +65,7 @@ async def test_get_with_params_passes_auth(self, client, mock_session):
6565
call_kwargs = mock_session.get.call_args[1]
6666
assert call_kwargs["auth"] == ("admin", "pass")
6767

68-
async def test_get_with_params_none_auth_by_default(self, client, mock_session):
68+
async def test_it_passes_no_auth_with_params_by_default(self, client, mock_session):
6969
mock_session.get.return_value = self._mock_ok_response({"ison": True})
7070

7171
await client.get_with_params("192.168.1.1", "relay/0", {"turn": "on"})

0 commit comments

Comments
 (0)