File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66from 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
1119def 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 \x05 A" + 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 )
You can’t perform that action at this time.
0 commit comments