Skip to content

Commit cf1936b

Browse files
committed
Increase test coverage and improve parsing error messages
1 parent 8b8b984 commit cf1936b

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

tests/test_commands.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,22 @@ def test_command_optional_params():
276276
assert Version.from_frame(medium_version_rsp.to_frame()) == medium_version_rsp
277277
assert Version.from_frame(short_version_rsp.to_frame()) == short_version_rsp
278278

279-
# Deserialization still fails if the frame is incomplete or too long
279+
# Deserialization still fails if the frame is incomplete
280280
with pytest.raises(ValueError):
281281
Version.from_frame(
282282
frames.GeneralFrame(
283283
header=long_version_rsp.to_frame().header, data=long_data[:-1]
284284
)
285285
)
286286

287+
# Deserialization will fail if the frame is incomplete but has no truncated fields
288+
with pytest.raises(ValueError):
289+
Version.from_frame(
290+
frames.GeneralFrame(
291+
header=long_version_rsp.to_frame().header, data=long_data[:4]
292+
)
293+
)
294+
287295
with pytest.raises(ValueError):
288296
Version.from_frame(
289297
frames.GeneralFrame(

tests/test_types_named.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,12 @@ def test_zdo_nullable_node_descriptor():
124124

125125
assert not data
126126
assert desc2.serialize() == desc3.serialize()
127+
128+
129+
def test_missing_enum_mixin():
130+
class TestEnum(t.MissingEnumMixin, t.enum_uint8):
131+
FOO = 0x01
132+
133+
assert TestEnum(0x01) == 0x01 == TestEnum.FOO
134+
assert TestEnum(0x02) == 0x02
135+
assert 0x02 not in TestEnum._value2member_map_

zigpy_znp/types/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def from_frame(cls, frame, *, ignore_unparsed=False) -> "CommandBase":
420420
elif not param.optional:
421421
# If we're out of data but the parameter is required, this is bad
422422
raise ValueError(
423-
f"Frame has been parsed but parameters remain: {param}"
423+
f"Data has been consumed but required parameters remain: {param}"
424424
)
425425
else:
426426
# If we're out of data and the parameter is optional, we're done

0 commit comments

Comments
 (0)