mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-11-11 06:51:04 +00:00
Allow packed data to be captured while executing skip(), etc.
This commit is contained in:
parent
d5f99959cc
commit
87f292cbf9
2 changed files with 57 additions and 12 deletions
32
test/test_unpack_raw.py
Normal file
32
test/test_unpack_raw.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
"""Tests for cases where the user seeks to obtain packed msgpack objects"""
|
||||
|
||||
from nose import main
|
||||
from nose.tools import *
|
||||
import six
|
||||
from msgpack import Unpacker, packb
|
||||
|
||||
def test_write_bytes():
|
||||
unpacker = Unpacker()
|
||||
unpacker.feed(b'abc')
|
||||
f = six.BytesIO()
|
||||
assert_equal(unpacker.unpack(f.write), ord('a'))
|
||||
assert_equal(f.getvalue(), b'a')
|
||||
f.truncate(0)
|
||||
assert_is_none(unpacker.skip(f.write))
|
||||
assert_equal(f.getvalue(), b'b')
|
||||
f.truncate(0)
|
||||
assert_is_none(unpacker.skip())
|
||||
assert_equal(f.getvalue(), b'')
|
||||
|
||||
def test_write_bytes_multi_buffer():
|
||||
long_val = (5) * 100
|
||||
expected = packb(long_val)
|
||||
unpacker = Unpacker(six.BytesIO(expected), read_size=3, max_buffer_size=3)
|
||||
|
||||
f = six.BytesIO()
|
||||
unpacked = unpacker.unpack(f.write)
|
||||
assert_equal(unpacked, long_val)
|
||||
assert_equal(f.getvalue(), expected)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue