Skip to content

Commit 653d81c

Browse files
committed
more explanation in test_case.test_mixed_bin_str (also renamed it)
1 parent ae8bc2e commit 653d81c

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

test/test_case.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,26 @@ def test_match():
100100
def test_unicode():
101101
assert unpackb(packb('foobar'), use_list=1) == b'foobar'
102102

103-
def test_bintype_symmetry():
103+
def test_mixed_bin_str():
104+
# This test explicitly checks behaviour when a MessagePack byte sequence has both
105+
# "bin family" types and "str family" types.
104106
# For background on this test see github issue #281
105-
# - basically: packing with use_bin_type=True and unpacking with raw=False
106-
# should be completely symmetric
107-
buf = b'\x92\xa3\xe2\x98\x83\xc4\x03\x00\x01\x02'
107+
# - basically: packing with use_bin_type=True and unpacking with raw=False should be
108+
# completely symmetric
109+
expected = [u'\u2603', b'\x00\x01\x02']
110+
buf = (b'\x92' # array with length 2 (fixarray)
111+
b'\xa3\xe2\x98\x83' # str format with length 3 (fixstr) (UTF8 snowman)
112+
b'\xc4\x03\x00\x01\x02' # bin format with length 3 (bin8) (0x000102)
113+
)
114+
115+
# Check symmetry
108116
unpacked = unpackb(buf, raw=False)
109117
packed = packb(unpacked, use_bin_type=True)
110118
assert packed == buf
119+
111120
# Also confirm that unpacking went to the expected types
112-
# - Note that we can't use test_match since it just uses basic equality
113-
# testing. We need to assert exact type matching here.
114-
expected = [u'\u2603', b'\x00\x01\x02']
121+
# - Note that we can't use test_match since it just uses basic equality testing. We
122+
# need to assert exact type matching here.
115123
for x, y in zip(expected, unpacked):
116124
assert type(x) is type(y)
117125
assert x == y

0 commit comments

Comments
 (0)