Skip to content

Commit a79509a

Browse files
test(wire): pin BLOB round-trip across bytes/bytearray/memoryview (ISSUE-106)
Parameterized test asserting all three bytes-like inputs encode to identical wire bytes and decode back as ``bytes``. A future refactor that narrows the encoder's accepted types would now fail the test.
1 parent 188a631 commit a79509a

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tests/test_types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,20 @@ def test_boolean_explicit_rejects_non_bool_non_int(self) -> None:
361361
with pytest.raises(EncodeError, match="BOOLEAN"):
362362
encode_value({"key": "val"}, ValueType.BOOLEAN)
363363

364+
@pytest.mark.parametrize(
365+
"payload",
366+
[b"hello", bytearray(b"hello"), memoryview(b"hello")],
367+
)
368+
def test_blob_roundtrip_bytes_like(self, payload: object) -> None:
369+
"""ISSUE-106: all three bytes-like inputs encode identically and
370+
decode back to ``bytes``."""
371+
encoded, vtype = encode_value(payload, ValueType.BLOB)
372+
assert vtype == ValueType.BLOB
373+
decoded, consumed = decode_value(encoded, ValueType.BLOB)
374+
assert decoded == b"hello"
375+
assert isinstance(decoded, bytes)
376+
assert consumed == len(encoded)
377+
364378
def test_boolean_rejects_arbitrary_int(self) -> None:
365379
"""BOOLEAN requires exact bool or 0/1 — arbitrary ints are rejected.
366380

0 commit comments

Comments
 (0)