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 From e15085db0362899520f714e3959c37721c839cef Mon Sep 17 00:00:00 2001 From: palaviv Date: Fri, 12 Feb 2016 15:39:50 +0200 Subject: removed MsgpackBaseException --- test/test_limits.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/test_limits.py b/test/test_limits.py index 34acf7c..e9bc9df 100644 --- a/test/test_limits.py +++ b/test/test_limits.py @@ -4,11 +4,11 @@ from __future__ import absolute_import, division, print_function, unicode_litera import pytest from msgpack import packb, unpackb, Packer, Unpacker, ExtType, PackException, PackOverflowError, PackValueError -from msgpack import UnpackValueError, UnpackException, MsgpackBaseException +from msgpack import UnpackValueError, UnpackException @pytest.mark.parametrize("expected_exception", [OverflowError, ValueError, PackOverflowError, - PackException, PackValueError, MsgpackBaseException]) + PackException, PackValueError]) def test_integer(expected_exception): x = -(2 ** 63) assert unpackb(packb(x)) == x @@ -21,7 +21,7 @@ def test_integer(expected_exception): packb(x+1) -@pytest.mark.parametrize("expected_exception", [ValueError, PackException, PackValueError, MsgpackBaseException]) +@pytest.mark.parametrize("expected_exception", [ValueError, PackException, PackValueError]) def test_array_header(expected_exception): packer = Packer() packer.pack_array_header(2**32-1) @@ -29,7 +29,7 @@ def test_array_header(expected_exception): packer.pack_array_header(2**32) -@pytest.mark.parametrize("expected_exception", [ValueError, PackException, PackValueError, MsgpackBaseException]) +@pytest.mark.parametrize("expected_exception", [ValueError, PackException, PackValueError]) def test_map_header(expected_exception): packer = Packer() packer.pack_map_header(2**32-1) @@ -37,7 +37,7 @@ def test_map_header(expected_exception): packer.pack_array_header(2**32) -@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException, MsgpackBaseException]) +@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException]) def test_max_str_len(expected_exception): d = 'x' * 3 packed = packb(d) @@ -52,7 +52,7 @@ def test_max_str_len(expected_exception): unpacker.unpack() -@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException, MsgpackBaseException]) +@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException]) def test_max_bin_len(expected_exception): d = b'x' * 3 packed = packb(d, use_bin_type=True) @@ -67,7 +67,7 @@ def test_max_bin_len(expected_exception): unpacker.unpack() -@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException, MsgpackBaseException]) +@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException]) def test_max_array_len(expected_exception): d = [1,2,3] packed = packb(d) @@ -82,7 +82,7 @@ def test_max_array_len(expected_exception): unpacker.unpack() -@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException, MsgpackBaseException]) +@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException]) def test_max_map_len(expected_exception): d = {1: 2, 3: 4, 5: 6} packed = packb(d) @@ -97,7 +97,7 @@ def test_max_map_len(expected_exception): unpacker.unpack() -@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException, MsgpackBaseException]) +@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException]) def test_max_ext_len(expected_exception): d = ExtType(42, b"abc") packed = packb(d) -- cgit v1.2.1 From 6e364762394fdb06d0453411a5f020ee594c06b0 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sun, 14 Feb 2016 11:58:56 +0900 Subject: remove too much parameterized tests --- test/test_limits.py | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/test_limits.py b/test/test_limits.py index e9bc9df..197ef46 100644 --- a/test/test_limits.py +++ b/test/test_limits.py @@ -3,42 +3,39 @@ from __future__ import absolute_import, division, print_function, unicode_literals import pytest -from msgpack import packb, unpackb, Packer, Unpacker, ExtType, PackException, PackOverflowError, PackValueError -from msgpack import UnpackValueError, UnpackException +from msgpack import ( + packb, unpackb, Packer, Unpacker, ExtType, + PackOverflowError, PackValueError, UnpackValueError, +) -@pytest.mark.parametrize("expected_exception", [OverflowError, ValueError, PackOverflowError, - PackException, PackValueError]) -def test_integer(expected_exception): +def test_integer(): x = -(2 ** 63) assert unpackb(packb(x)) == x - with pytest.raises(expected_exception): + with pytest.raises(PackOverflowError): packb(x-1) x = 2 ** 64 - 1 assert unpackb(packb(x)) == x - with pytest.raises(expected_exception): + with pytest.raises(PackOverflowError): packb(x+1) -@pytest.mark.parametrize("expected_exception", [ValueError, PackException, PackValueError]) -def test_array_header(expected_exception): +def test_array_header(): packer = Packer() packer.pack_array_header(2**32-1) - with pytest.raises(expected_exception): + with pytest.raises(PackValueError): packer.pack_array_header(2**32) -@pytest.mark.parametrize("expected_exception", [ValueError, PackException, PackValueError]) -def test_map_header(expected_exception): +def test_map_header(): packer = Packer() packer.pack_map_header(2**32-1) - with pytest.raises(expected_exception): + with pytest.raises(PackValueError): packer.pack_array_header(2**32) -@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException]) -def test_max_str_len(expected_exception): +def test_max_str_len(): d = 'x' * 3 packed = packb(d) @@ -47,13 +44,12 @@ def test_max_str_len(expected_exception): assert unpacker.unpack() == d unpacker = Unpacker(max_str_len=2, encoding='utf-8') - with pytest.raises(expected_exception): + with pytest.raises(UnpackValueError): unpacker.feed(packed) unpacker.unpack() -@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException]) -def test_max_bin_len(expected_exception): +def test_max_bin_len(): d = b'x' * 3 packed = packb(d, use_bin_type=True) @@ -62,13 +58,12 @@ def test_max_bin_len(expected_exception): assert unpacker.unpack() == d unpacker = Unpacker(max_bin_len=2) - with pytest.raises(expected_exception): + with pytest.raises(UnpackValueError): unpacker.feed(packed) unpacker.unpack() -@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException]) -def test_max_array_len(expected_exception): +def test_max_array_len(): d = [1,2,3] packed = packb(d) @@ -77,13 +72,12 @@ def test_max_array_len(expected_exception): assert unpacker.unpack() == d unpacker = Unpacker(max_array_len=2) - with pytest.raises(expected_exception): + with pytest.raises(UnpackValueError): unpacker.feed(packed) unpacker.unpack() -@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException]) -def test_max_map_len(expected_exception): +def test_max_map_len(): d = {1: 2, 3: 4, 5: 6} packed = packb(d) @@ -92,13 +86,12 @@ def test_max_map_len(expected_exception): assert unpacker.unpack() == d unpacker = Unpacker(max_map_len=2) - with pytest.raises(expected_exception): + with pytest.raises(UnpackValueError): unpacker.feed(packed) unpacker.unpack() -@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException]) -def test_max_ext_len(expected_exception): +def test_max_ext_len(): d = ExtType(42, b"abc") packed = packb(d) @@ -107,7 +100,7 @@ def test_max_ext_len(expected_exception): assert unpacker.unpack() == d unpacker = Unpacker(max_ext_len=2) - with pytest.raises(expected_exception): + with pytest.raises(UnpackValueError): unpacker.feed(packed) unpacker.unpack() -- cgit v1.2.1