diff options
author | Joel Nothman <joel.nothman@gmail.com> | 2012-10-04 11:26:29 +1000 |
---|---|---|
committer | Joel Nothman <joel.nothman@gmail.com> | 2012-10-04 11:26:29 +1000 |
commit | 87f292cbf929c0cf8c8de867a5e7dd285cf1550a (patch) | |
tree | 3397a2d08f16a99cec6d1c0cdc0fb37063204787 /test | |
parent | d5f99959cc2ec393c13fc9e44714351272bac7fc (diff) | |
download | msgpack-python-87f292cbf929c0cf8c8de867a5e7dd285cf1550a.tar.gz |
Allow packed data to be captured while executing skip(), etc.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_unpack_raw.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/test_unpack_raw.py b/test/test_unpack_raw.py new file mode 100644 index 0000000..ed2e04b --- /dev/null +++ b/test/test_unpack_raw.py @@ -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() |