summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorINADA Naoki <inada-n@klab.com>2014-06-23 22:46:08 +0900
committerINADA Naoki <songofacandy@gmail.com>2015-01-25 01:41:21 +0900
commit75ce78dd1512460712f2600ffd927bedeeb02fbc (patch)
tree001ad5db9fa54c1a141ca6558ec297fa3dfdf67e /test
parentc43fb48724049dc35c34fd389091e384dec46bb8 (diff)
downloadmsgpack-python-75ce78dd1512460712f2600ffd927bedeeb02fbc.tar.gz
Add max_<type>_len option to unpacker. (fixes #97).
Fix build error on 32bit environment (fixes #102).
Diffstat (limited to 'test')
-rw-r--r--test/test_limits.py73
1 files changed, 72 insertions, 1 deletions
diff --git a/test/test_limits.py b/test/test_limits.py
index 1cfa2d6..3c1cf2a 100644
--- a/test/test_limits.py
+++ b/test/test_limits.py
@@ -3,7 +3,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals
import pytest
-from msgpack import packb, unpackb, Packer
+from msgpack import packb, unpackb, Packer, Unpacker, ExtType
def test_integer():
@@ -32,6 +32,77 @@ def test_map_header():
packer.pack_array_header(2**32)
+def test_max_str_len():
+ d = 'x' * 3
+ packed = packb(d)
+
+ unpacker = Unpacker(max_str_len=3, encoding='utf-8')
+ unpacker.feed(packed)
+ assert unpacker.unpack() == d
+
+ unpacker = Unpacker(max_str_len=2, encoding='utf-8')
+ with pytest.raises(ValueError):
+ unpacker.feed(packed)
+ unpacker.unpack()
+
+
+def test_max_bin_len():
+ d = b'x' * 3
+ packed = packb(d, use_bin_type=True)
+
+ unpacker = Unpacker(max_bin_len=3)
+ unpacker.feed(packed)
+ assert unpacker.unpack() == d
+
+ unpacker = Unpacker(max_bin_len=2)
+ with pytest.raises(ValueError):
+ unpacker.feed(packed)
+ unpacker.unpack()
+
+
+def test_max_array_len():
+ d = [1,2,3]
+ packed = packb(d)
+
+ unpacker = Unpacker(max_array_len=3)
+ unpacker.feed(packed)
+ assert unpacker.unpack() == d
+
+ unpacker = Unpacker(max_array_len=2)
+ with pytest.raises(ValueError):
+ unpacker.feed(packed)
+ unpacker.unpack()
+
+
+def test_max_map_len():
+ d = {1: 2, 3: 4, 5: 6}
+ packed = packb(d)
+
+ unpacker = Unpacker(max_map_len=3)
+ unpacker.feed(packed)
+ assert unpacker.unpack() == d
+
+ unpacker = Unpacker(max_map_len=2)
+ with pytest.raises(ValueError):
+ unpacker.feed(packed)
+ unpacker.unpack()
+
+
+def test_max_ext_len():
+ d = ExtType(42, b"abc")
+ packed = packb(d)
+
+ unpacker = Unpacker(max_ext_len=3)
+ unpacker.feed(packed)
+ assert unpacker.unpack() == d
+
+ unpacker = Unpacker(max_ext_len=2)
+ with pytest.raises(ValueError):
+ unpacker.feed(packed)
+ unpacker.unpack()
+
+
+
# PyPy fails following tests because of constant folding?
# https://bugs.pypy.org/issue1721
#@pytest.mark.skipif(True, reason="Requires very large memory.")