summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorpalaviv <palaviv@gmail.com>2016-02-12 11:00:39 +0200
committerpalaviv <palaviv@gmail.com>2016-02-12 11:00:39 +0200
commit7d2d46effce37f9fbf394fac74d380aaa7c95f02 (patch)
treede896ab281c25da5a17d416a707b5e79c4bab094 /test
parent82b31215079bc47bd4d5a8f3c18d83ac73c8221b (diff)
downloadmsgpack-python-7d2d46effce37f9fbf394fac74d380aaa7c95f02.tar.gz
msgpack pack and unpack throws only exception that inherit from MsgpackBaseException. cython and fallback throws same exceptions
Diffstat (limited to 'test')
-rw-r--r--test/test_limits.py46
1 files changed, 28 insertions, 18 deletions
diff --git a/test/test_limits.py b/test/test_limits.py
index 3c1cf2a..34acf7c 100644
--- a/test/test_limits.py
+++ b/test/test_limits.py
@@ -3,36 +3,42 @@
from __future__ import absolute_import, division, print_function, unicode_literals
import pytest
-from msgpack import packb, unpackb, Packer, Unpacker, ExtType
+from msgpack import packb, unpackb, Packer, Unpacker, ExtType, PackException, PackOverflowError, PackValueError
+from msgpack import UnpackValueError, UnpackException, MsgpackBaseException
-def test_integer():
+@pytest.mark.parametrize("expected_exception", [OverflowError, ValueError, PackOverflowError,
+ PackException, PackValueError, MsgpackBaseException])
+def test_integer(expected_exception):
x = -(2 ** 63)
assert unpackb(packb(x)) == x
- with pytest.raises((OverflowError, ValueError)):
+ with pytest.raises(expected_exception):
packb(x-1)
x = 2 ** 64 - 1
assert unpackb(packb(x)) == x
- with pytest.raises((OverflowError, ValueError)):
+ with pytest.raises(expected_exception):
packb(x+1)
-def test_array_header():
+@pytest.mark.parametrize("expected_exception", [ValueError, PackException, PackValueError, MsgpackBaseException])
+def test_array_header(expected_exception):
packer = Packer()
packer.pack_array_header(2**32-1)
- with pytest.raises((OverflowError, ValueError)):
+ with pytest.raises(expected_exception):
packer.pack_array_header(2**32)
-def test_map_header():
+@pytest.mark.parametrize("expected_exception", [ValueError, PackException, PackValueError, MsgpackBaseException])
+def test_map_header(expected_exception):
packer = Packer()
packer.pack_map_header(2**32-1)
- with pytest.raises((OverflowError, ValueError)):
+ with pytest.raises(expected_exception):
packer.pack_array_header(2**32)
-def test_max_str_len():
+@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException, MsgpackBaseException])
+def test_max_str_len(expected_exception):
d = 'x' * 3
packed = packb(d)
@@ -41,12 +47,13 @@ def test_max_str_len():
assert unpacker.unpack() == d
unpacker = Unpacker(max_str_len=2, encoding='utf-8')
- with pytest.raises(ValueError):
+ with pytest.raises(expected_exception):
unpacker.feed(packed)
unpacker.unpack()
-def test_max_bin_len():
+@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException, MsgpackBaseException])
+def test_max_bin_len(expected_exception):
d = b'x' * 3
packed = packb(d, use_bin_type=True)
@@ -55,12 +62,13 @@ def test_max_bin_len():
assert unpacker.unpack() == d
unpacker = Unpacker(max_bin_len=2)
- with pytest.raises(ValueError):
+ with pytest.raises(expected_exception):
unpacker.feed(packed)
unpacker.unpack()
-def test_max_array_len():
+@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException, MsgpackBaseException])
+def test_max_array_len(expected_exception):
d = [1,2,3]
packed = packb(d)
@@ -69,12 +77,13 @@ def test_max_array_len():
assert unpacker.unpack() == d
unpacker = Unpacker(max_array_len=2)
- with pytest.raises(ValueError):
+ with pytest.raises(expected_exception):
unpacker.feed(packed)
unpacker.unpack()
-def test_max_map_len():
+@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException, MsgpackBaseException])
+def test_max_map_len(expected_exception):
d = {1: 2, 3: 4, 5: 6}
packed = packb(d)
@@ -83,12 +92,13 @@ def test_max_map_len():
assert unpacker.unpack() == d
unpacker = Unpacker(max_map_len=2)
- with pytest.raises(ValueError):
+ with pytest.raises(expected_exception):
unpacker.feed(packed)
unpacker.unpack()
-def test_max_ext_len():
+@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException, MsgpackBaseException])
+def test_max_ext_len(expected_exception):
d = ExtType(42, b"abc")
packed = packb(d)
@@ -97,7 +107,7 @@ def test_max_ext_len():
assert unpacker.unpack() == d
unpacker = Unpacker(max_ext_len=2)
- with pytest.raises(ValueError):
+ with pytest.raises(expected_exception):
unpacker.feed(packed)
unpacker.unpack()