3
3
from __future__ import absolute_import , division , print_function , unicode_literals
4
4
import pytest
5
5
6
- from msgpack import packb , unpackb , Packer , Unpacker , ExtType , PackException , PackOverflowError , PackValueError
7
- from msgpack import UnpackValueError , UnpackException
6
+ from msgpack import (
7
+ packb , unpackb , Packer , Unpacker , ExtType ,
8
+ PackOverflowError , PackValueError , UnpackValueError ,
9
+ )
8
10
9
11
10
- @pytest .mark .parametrize ("expected_exception" , [OverflowError , ValueError , PackOverflowError ,
11
- PackException , PackValueError ])
12
- def test_integer (expected_exception ):
12
+ def test_integer ():
13
13
x = - (2 ** 63 )
14
14
assert unpackb (packb (x )) == x
15
- with pytest .raises (expected_exception ):
15
+ with pytest .raises (PackOverflowError ):
16
16
packb (x - 1 )
17
17
18
18
x = 2 ** 64 - 1
19
19
assert unpackb (packb (x )) == x
20
- with pytest .raises (expected_exception ):
20
+ with pytest .raises (PackOverflowError ):
21
21
packb (x + 1 )
22
22
23
23
24
- @pytest .mark .parametrize ("expected_exception" , [ValueError , PackException , PackValueError ])
25
- def test_array_header (expected_exception ):
24
+ def test_array_header ():
26
25
packer = Packer ()
27
26
packer .pack_array_header (2 ** 32 - 1 )
28
- with pytest .raises (expected_exception ):
27
+ with pytest .raises (PackValueError ):
29
28
packer .pack_array_header (2 ** 32 )
30
29
31
30
32
- @pytest .mark .parametrize ("expected_exception" , [ValueError , PackException , PackValueError ])
33
- def test_map_header (expected_exception ):
31
+ def test_map_header ():
34
32
packer = Packer ()
35
33
packer .pack_map_header (2 ** 32 - 1 )
36
- with pytest .raises (expected_exception ):
34
+ with pytest .raises (PackValueError ):
37
35
packer .pack_array_header (2 ** 32 )
38
36
39
37
40
- @pytest .mark .parametrize ("expected_exception" , [ValueError , UnpackValueError , UnpackException ])
41
- def test_max_str_len (expected_exception ):
38
+ def test_max_str_len ():
42
39
d = 'x' * 3
43
40
packed = packb (d )
44
41
@@ -47,13 +44,12 @@ def test_max_str_len(expected_exception):
47
44
assert unpacker .unpack () == d
48
45
49
46
unpacker = Unpacker (max_str_len = 2 , encoding = 'utf-8' )
50
- with pytest .raises (expected_exception ):
47
+ with pytest .raises (UnpackValueError ):
51
48
unpacker .feed (packed )
52
49
unpacker .unpack ()
53
50
54
51
55
- @pytest .mark .parametrize ("expected_exception" , [ValueError , UnpackValueError , UnpackException ])
56
- def test_max_bin_len (expected_exception ):
52
+ def test_max_bin_len ():
57
53
d = b'x' * 3
58
54
packed = packb (d , use_bin_type = True )
59
55
@@ -62,13 +58,12 @@ def test_max_bin_len(expected_exception):
62
58
assert unpacker .unpack () == d
63
59
64
60
unpacker = Unpacker (max_bin_len = 2 )
65
- with pytest .raises (expected_exception ):
61
+ with pytest .raises (UnpackValueError ):
66
62
unpacker .feed (packed )
67
63
unpacker .unpack ()
68
64
69
65
70
- @pytest .mark .parametrize ("expected_exception" , [ValueError , UnpackValueError , UnpackException ])
71
- def test_max_array_len (expected_exception ):
66
+ def test_max_array_len ():
72
67
d = [1 ,2 ,3 ]
73
68
packed = packb (d )
74
69
@@ -77,13 +72,12 @@ def test_max_array_len(expected_exception):
77
72
assert unpacker .unpack () == d
78
73
79
74
unpacker = Unpacker (max_array_len = 2 )
80
- with pytest .raises (expected_exception ):
75
+ with pytest .raises (UnpackValueError ):
81
76
unpacker .feed (packed )
82
77
unpacker .unpack ()
83
78
84
79
85
- @pytest .mark .parametrize ("expected_exception" , [ValueError , UnpackValueError , UnpackException ])
86
- def test_max_map_len (expected_exception ):
80
+ def test_max_map_len ():
87
81
d = {1 : 2 , 3 : 4 , 5 : 6 }
88
82
packed = packb (d )
89
83
@@ -92,13 +86,12 @@ def test_max_map_len(expected_exception):
92
86
assert unpacker .unpack () == d
93
87
94
88
unpacker = Unpacker (max_map_len = 2 )
95
- with pytest .raises (expected_exception ):
89
+ with pytest .raises (UnpackValueError ):
96
90
unpacker .feed (packed )
97
91
unpacker .unpack ()
98
92
99
93
100
- @pytest .mark .parametrize ("expected_exception" , [ValueError , UnpackValueError , UnpackException ])
101
- def test_max_ext_len (expected_exception ):
94
+ def test_max_ext_len ():
102
95
d = ExtType (42 , b"abc" )
103
96
packed = packb (d )
104
97
@@ -107,7 +100,7 @@ def test_max_ext_len(expected_exception):
107
100
assert unpacker .unpack () == d
108
101
109
102
unpacker = Unpacker (max_ext_len = 2 )
110
- with pytest .raises (expected_exception ):
103
+ with pytest .raises (UnpackValueError ):
111
104
unpacker .feed (packed )
112
105
unpacker .unpack ()
113
106
0 commit comments