remove too much parameterized tests
This commit is contained in:
parent
3dad39811d
commit
6e36476239
|
@ -3,42 +3,39 @@
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from msgpack import packb, unpackb, Packer, Unpacker, ExtType, PackException, PackOverflowError, PackValueError
|
from msgpack import (
|
||||||
from msgpack import UnpackValueError, UnpackException
|
packb, unpackb, Packer, Unpacker, ExtType,
|
||||||
|
PackOverflowError, PackValueError, UnpackValueError,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_exception", [OverflowError, ValueError, PackOverflowError,
|
def test_integer():
|
||||||
PackException, PackValueError])
|
|
||||||
def test_integer(expected_exception):
|
|
||||||
x = -(2 ** 63)
|
x = -(2 ** 63)
|
||||||
assert unpackb(packb(x)) == x
|
assert unpackb(packb(x)) == x
|
||||||
with pytest.raises(expected_exception):
|
with pytest.raises(PackOverflowError):
|
||||||
packb(x-1)
|
packb(x-1)
|
||||||
|
|
||||||
x = 2 ** 64 - 1
|
x = 2 ** 64 - 1
|
||||||
assert unpackb(packb(x)) == x
|
assert unpackb(packb(x)) == x
|
||||||
with pytest.raises(expected_exception):
|
with pytest.raises(PackOverflowError):
|
||||||
packb(x+1)
|
packb(x+1)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_exception", [ValueError, PackException, PackValueError])
|
def test_array_header():
|
||||||
def test_array_header(expected_exception):
|
|
||||||
packer = Packer()
|
packer = Packer()
|
||||||
packer.pack_array_header(2**32-1)
|
packer.pack_array_header(2**32-1)
|
||||||
with pytest.raises(expected_exception):
|
with pytest.raises(PackValueError):
|
||||||
packer.pack_array_header(2**32)
|
packer.pack_array_header(2**32)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_exception", [ValueError, PackException, PackValueError])
|
def test_map_header():
|
||||||
def test_map_header(expected_exception):
|
|
||||||
packer = Packer()
|
packer = Packer()
|
||||||
packer.pack_map_header(2**32-1)
|
packer.pack_map_header(2**32-1)
|
||||||
with pytest.raises(expected_exception):
|
with pytest.raises(PackValueError):
|
||||||
packer.pack_array_header(2**32)
|
packer.pack_array_header(2**32)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException])
|
def test_max_str_len():
|
||||||
def test_max_str_len(expected_exception):
|
|
||||||
d = 'x' * 3
|
d = 'x' * 3
|
||||||
packed = packb(d)
|
packed = packb(d)
|
||||||
|
|
||||||
|
@ -47,13 +44,12 @@ def test_max_str_len(expected_exception):
|
||||||
assert unpacker.unpack() == d
|
assert unpacker.unpack() == d
|
||||||
|
|
||||||
unpacker = Unpacker(max_str_len=2, encoding='utf-8')
|
unpacker = Unpacker(max_str_len=2, encoding='utf-8')
|
||||||
with pytest.raises(expected_exception):
|
with pytest.raises(UnpackValueError):
|
||||||
unpacker.feed(packed)
|
unpacker.feed(packed)
|
||||||
unpacker.unpack()
|
unpacker.unpack()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException])
|
def test_max_bin_len():
|
||||||
def test_max_bin_len(expected_exception):
|
|
||||||
d = b'x' * 3
|
d = b'x' * 3
|
||||||
packed = packb(d, use_bin_type=True)
|
packed = packb(d, use_bin_type=True)
|
||||||
|
|
||||||
|
@ -62,13 +58,12 @@ def test_max_bin_len(expected_exception):
|
||||||
assert unpacker.unpack() == d
|
assert unpacker.unpack() == d
|
||||||
|
|
||||||
unpacker = Unpacker(max_bin_len=2)
|
unpacker = Unpacker(max_bin_len=2)
|
||||||
with pytest.raises(expected_exception):
|
with pytest.raises(UnpackValueError):
|
||||||
unpacker.feed(packed)
|
unpacker.feed(packed)
|
||||||
unpacker.unpack()
|
unpacker.unpack()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException])
|
def test_max_array_len():
|
||||||
def test_max_array_len(expected_exception):
|
|
||||||
d = [1,2,3]
|
d = [1,2,3]
|
||||||
packed = packb(d)
|
packed = packb(d)
|
||||||
|
|
||||||
|
@ -77,13 +72,12 @@ def test_max_array_len(expected_exception):
|
||||||
assert unpacker.unpack() == d
|
assert unpacker.unpack() == d
|
||||||
|
|
||||||
unpacker = Unpacker(max_array_len=2)
|
unpacker = Unpacker(max_array_len=2)
|
||||||
with pytest.raises(expected_exception):
|
with pytest.raises(UnpackValueError):
|
||||||
unpacker.feed(packed)
|
unpacker.feed(packed)
|
||||||
unpacker.unpack()
|
unpacker.unpack()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException])
|
def test_max_map_len():
|
||||||
def test_max_map_len(expected_exception):
|
|
||||||
d = {1: 2, 3: 4, 5: 6}
|
d = {1: 2, 3: 4, 5: 6}
|
||||||
packed = packb(d)
|
packed = packb(d)
|
||||||
|
|
||||||
|
@ -92,13 +86,12 @@ def test_max_map_len(expected_exception):
|
||||||
assert unpacker.unpack() == d
|
assert unpacker.unpack() == d
|
||||||
|
|
||||||
unpacker = Unpacker(max_map_len=2)
|
unpacker = Unpacker(max_map_len=2)
|
||||||
with pytest.raises(expected_exception):
|
with pytest.raises(UnpackValueError):
|
||||||
unpacker.feed(packed)
|
unpacker.feed(packed)
|
||||||
unpacker.unpack()
|
unpacker.unpack()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_exception", [ValueError, UnpackValueError, UnpackException])
|
def test_max_ext_len():
|
||||||
def test_max_ext_len(expected_exception):
|
|
||||||
d = ExtType(42, b"abc")
|
d = ExtType(42, b"abc")
|
||||||
packed = packb(d)
|
packed = packb(d)
|
||||||
|
|
||||||
|
@ -107,7 +100,7 @@ def test_max_ext_len(expected_exception):
|
||||||
assert unpacker.unpack() == d
|
assert unpacker.unpack() == d
|
||||||
|
|
||||||
unpacker = Unpacker(max_ext_len=2)
|
unpacker = Unpacker(max_ext_len=2)
|
||||||
with pytest.raises(expected_exception):
|
with pytest.raises(UnpackValueError):
|
||||||
unpacker.feed(packed)
|
unpacker.feed(packed)
|
||||||
unpacker.unpack()
|
unpacker.unpack()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue