summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2012-12-06 01:49:58 -0800
committerINADA Naoki <songofacandy@gmail.com>2012-12-06 01:49:58 -0800
commit54916f79a56c76879c83ae9d3e9ff90a45e88c09 (patch)
treefb3ed3d310176716314cefc590ffa8410c248c65 /test
parent1c389135b88d3fc8be4151228fff1fb5764f119b (diff)
parent87f292cbf929c0cf8c8de867a5e7dd285cf1550a (diff)
downloadmsgpack-python-54916f79a56c76879c83ae9d3e9ff90a45e88c09.tar.gz
Merge pull request #23 from jnothman/write_bytes
Allow packed data to be captured while executing skip(), etc.
Diffstat (limited to 'test')
-rw-r--r--test/test_unpack_raw.py32
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()