From 7d2d46effce37f9fbf394fac74d380aaa7c95f02 Mon Sep 17 00:00:00 2001 From: palaviv Date: Fri, 12 Feb 2016 11:00:39 +0200 Subject: msgpack pack and unpack throws only exception that inherit from MsgpackBaseException. cython and fallback throws same exceptions --- test/test_limits.py | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'test') 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() -- cgit v1.2.1