13
13
14
14
15
15
def test_dict (py_and_json : PyAndJson ):
16
- v = py_and_json (
17
- {
18
- 'type' : 'dict' ,
19
- 'keys_schema' : {'type' : 'int' },
20
- 'values_schema' : {'type' : 'int' },
21
- }
22
- )
16
+ v = py_and_json ({'type' : 'dict' , 'keys_schema' : {'type' : 'int' }, 'values_schema' : {'type' : 'int' }})
23
17
assert v .validate_test ({'1' : 2 , '3' : 4 }) == {1 : 2 , 3 : 4 }
24
- v = py_and_json (
25
- {
26
- 'type' : 'dict' ,
27
- 'strict' : True ,
28
- 'keys_schema' : {'type' : 'int' },
29
- 'values_schema' : {'type' : 'int' },
30
- }
31
- )
18
+ v = py_and_json ({'type' : 'dict' , 'strict' : True , 'keys_schema' : {'type' : 'int' }, 'values_schema' : {'type' : 'int' }})
32
19
assert v .validate_test ({'1' : 2 , '3' : 4 }) == {1 : 2 , 3 : 4 }
33
20
assert v .validate_test ({}) == {}
34
- with pytest .raises (
35
- ValidationError ,
36
- match = re .escape ('[type=dict_type, input_value=[], input_type=list]' ),
37
- ):
21
+ with pytest .raises (ValidationError , match = re .escape ('[type=dict_type, input_value=[], input_type=list]' )):
38
22
v .validate_test ([])
39
23
40
24
@@ -44,22 +28,13 @@ def test_dict(py_and_json: PyAndJson):
44
28
({'1' : b'1' , '2' : b'2' }, {'1' : '1' , '2' : '2' }),
45
29
(OrderedDict (a = b'1' , b = '2' ), {'a' : '1' , 'b' : '2' }),
46
30
({}, {}),
47
- (
48
- 'foobar' ,
49
- Err ("Input should be a valid dictionary [type=dict_type, input_value='foobar', input_type=str]" ),
50
- ),
31
+ ('foobar' , Err ("Input should be a valid dictionary [type=dict_type, input_value='foobar', input_type=str]" )),
51
32
([], Err ('Input should be a valid dictionary [type=dict_type,' )),
52
33
([('x' , 'y' )], Err ('Input should be a valid dictionary [type=dict_type,' )),
53
- (
54
- [('x' , 'y' ), ('z' , 'z' )],
55
- Err ('Input should be a valid dictionary [type=dict_type,' ),
56
- ),
34
+ ([('x' , 'y' ), ('z' , 'z' )], Err ('Input should be a valid dictionary [type=dict_type,' )),
57
35
((), Err ('Input should be a valid dictionary [type=dict_type,' )),
58
36
((('x' , 'y' ),), Err ('Input should be a valid dictionary [type=dict_type,' )),
59
- (
60
- (type ('Foobar' , (), {'x' : 1 })()),
61
- Err ('Input should be a valid dictionary [type=dict_type,' ),
62
- ),
37
+ ((type ('Foobar' , (), {'x' : 1 })()), Err ('Input should be a valid dictionary [type=dict_type,' )),
63
38
],
64
39
ids = repr ,
65
40
)
@@ -125,11 +100,7 @@ def test_dict_error_key_other():
125
100
def test_dict_any_value ():
126
101
v = SchemaValidator (cs .dict_schema (keys_schema = cs .str_schema ()))
127
102
v = SchemaValidator (cs .dict_schema (keys_schema = cs .str_schema ()))
128
- assert v .validate_python ({'1' : 1 , '2' : 'a' , '3' : None }) == {
129
- '1' : 1 ,
130
- '2' : 'a' ,
131
- '3' : None ,
132
- }
103
+ assert v .validate_python ({'1' : 1 , '2' : 'a' , '3' : None }) == {'1' : 1 , '2' : 'a' , '3' : None }
133
104
134
105
135
106
def test_mapping ():
@@ -273,27 +244,17 @@ def test_dict_complex_key():
273
244
274
245
v = SchemaValidator (cs .dict_schema (keys_schema = cs .complex_schema (), values_schema = cs .str_schema ()))
275
246
with pytest .raises (
276
- ValidationError ,
277
- match = 'Input should be a valid python complex object, a number, or a valid complex string' ,
247
+ ValidationError , match = 'Input should be a valid python complex object, a number, or a valid complex string'
278
248
):
279
249
v .validate_python ({'1+2ja' : b'1' })
280
250
281
251
282
252
def test_json_dict_complex_key ():
283
253
v = SchemaValidator (cs .dict_schema (keys_schema = cs .complex_schema (), values_schema = cs .int_schema ()))
284
- assert v .validate_json ('{"1+2j": 2, "-3": 4}' ) == {
285
- complex (1 , 2 ): 2 ,
286
- complex (- 3 , 0 ): 4 ,
287
- }
288
- assert v .validate_json ('{"1+2j": 2, "infj": 4}' ) == {
289
- complex (1 , 2 ): 2 ,
290
- complex (0 , float ('inf' )): 4 ,
291
- }
254
+ assert v .validate_json ('{"1+2j": 2, "-3": 4}' ) == {complex (1 , 2 ): 2 , complex (- 3 , 0 ): 4 }
255
+ assert v .validate_json ('{"1+2j": 2, "infj": 4}' ) == {complex (1 , 2 ): 2 , complex (0 , float ('inf' )): 4 }
292
256
with pytest .raises (ValidationError , match = 'Input should be a valid complex string' ):
293
- v .validate_json ('{"1+2j": 2, "": 4}' ) == {
294
- complex (1 , 2 ): 2 ,
295
- complex (0 , float ('inf' )): 4 ,
296
- }
257
+ v .validate_json ('{"1+2j": 2, "": 4}' ) == {complex (1 , 2 ): 2 , complex (0 , float ('inf' )): 4 }
297
258
298
259
299
260
def test_ordered_dict_key_order_preservation ():
0 commit comments