Skip to content

Commit cd90a3f

Browse files
committed
test_unpack.py: add tests for ExtraData
1 parent 951995e commit cd90a3f

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

test/test_unpack.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55

66
from pytest import mark, raises
77

8-
from msgpack import ExtType, OutOfData, Unpacker, packb
8+
from msgpack import (
9+
ExtraData,
10+
ExtType,
11+
OutOfData,
12+
Unpacker,
13+
packb,
14+
unpack,
15+
unpackb,
16+
)
917

1018

1119
def test_unpack_array_header_from_file():
@@ -142,3 +150,20 @@ def ext_hook(code, data):
142150
up.feed(b"\xdc" + struct.pack(">H", 11) + b"\xd4\x05A" + b"\x2a" * 10)
143151
with raises(RuntimeError):
144152
up.unpack()
153+
154+
155+
def test_unpackb_raises_extra_data_with_trailing_bytes():
156+
packed = packb(42) + packb("trailing")
157+
with raises(ExtraData) as exc_info:
158+
unpackb(packed)
159+
err = exc_info.value
160+
assert err.unpacked == 42
161+
assert err.extra == packb("trailing")
162+
163+
164+
def test_unpack_raises_extra_data_on_stream_with_trailing_bytes():
165+
stream = BytesIO(packb(100) + packb(200))
166+
with raises(ExtraData) as exc_info:
167+
unpack(stream)
168+
assert exc_info.value.unpacked == 100
169+
assert exc_info.value.extra == packb(200)

0 commit comments

Comments
 (0)