feat: add support for tuples to the marshaller (#267)

This commit is contained in:
J. Nick Koston
2023-11-10 08:46:37 -06:00
committed by GitHub
parent 6b48423b23
commit 0ccb7c5d87
6 changed files with 44 additions and 8 deletions

View File

@@ -714,3 +714,29 @@ def test_unmarshall_multi_byte_string():
assert unmarshaller.message.signature == "as"
unpacked = unpack_variants(message.body)
assert unpacked == [["//doesntmatter/über"]]
def test_marshalling_struct_accepts_tuples():
"""Test marshalling a struct accepts tuples."""
msg = Message(
path="/test",
member="test",
signature="(s)",
body=[(RaucState.GOOD,)],
)
marshalled = msg._marshall(False)
unmarshalled_msg = Unmarshaller(io.BytesIO(marshalled)).unmarshall()
assert unpack_variants(unmarshalled_msg.body)[0] == [RaucState.GOOD.value]
def test_marshalling_struct_accepts_lists():
"""Test marshalling a struct accepts lists."""
msg = Message(
path="/test",
member="test",
signature="(s)",
body=[[RaucState.GOOD]],
)
marshalled = msg._marshall(False)
unmarshalled_msg = Unmarshaller(io.BytesIO(marshalled)).unmarshall()
assert unpack_variants(unmarshalled_msg.body)[0] == [RaucState.GOOD.value]

View File

@@ -231,3 +231,9 @@ def test_variant_signature_type():
with pytest.raises(SignatureBodyMismatchError):
Variant(tree.types[0], "wrong")
def test_struct_accepts_tuples_or_lists():
tree = SignatureTree("(s)")
tree.verify([("ok",)])
tree.verify([["ok"]])