Allow packed data to be captured while executing skip(), etc.

This commit is contained in:
Joel Nothman 2012-10-04 11:26:29 +10:00
parent d5f99959cc
commit 87f292cbf9
2 changed files with 57 additions and 12 deletions

32
test/test_unpack_raw.py Normal file
View 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()