Skip to content

Commit bef11c6

Browse files
committed
update test_dict to reintroduce function I accidentally deleted
1 parent be8ef2b commit bef11c6

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

tests/validators/test_dict.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,63 @@ def test_json_dict_complex_key():
257257
v.validate_json('{"1+2j": 2, "": 4}') == {complex(1, 2): 2, complex(0, float('inf')): 4}
258258

259259

260+
@pytest.mark.parametrize(
261+
('fail_fast', 'expected'),
262+
[
263+
pytest.param(
264+
True,
265+
[
266+
{
267+
'type': 'int_parsing',
268+
'loc': ('a', '[key]'),
269+
'msg': 'Input should be a valid integer, unable to parse string as an integer',
270+
'input': 'a',
271+
},
272+
],
273+
id='fail_fast',
274+
),
275+
pytest.param(
276+
False,
277+
[
278+
{
279+
'type': 'int_parsing',
280+
'loc': ('a', '[key]'),
281+
'msg': 'Input should be a valid integer, unable to parse string as an integer',
282+
'input': 'a',
283+
},
284+
{
285+
'type': 'int_parsing',
286+
'loc': ('a',),
287+
'msg': 'Input should be a valid integer, unable to parse string as an integer',
288+
'input': 'b',
289+
},
290+
{
291+
'type': 'int_parsing',
292+
'loc': ('c', '[key]'),
293+
'msg': 'Input should be a valid integer, unable to parse string as an integer',
294+
'input': 'c',
295+
},
296+
{
297+
'type': 'int_parsing',
298+
'loc': ('c',),
299+
'msg': 'Input should be a valid integer, unable to parse string as an integer',
300+
'input': 'd',
301+
},
302+
],
303+
id='not_fail_fast',
304+
),
305+
],
306+
)
307+
def test_dict_fail_fast(fail_fast, expected):
308+
v = SchemaValidator(
309+
{'type': 'dict', 'keys_schema': {'type': 'int'}, 'values_schema': {'type': 'int'}, 'fail_fast': fail_fast}
310+
)
311+
312+
with pytest.raises(ValidationError) as exc_info:
313+
v.validate_python({'a': 'b', 'c': 'd'})
314+
315+
assert exc_info.value.errors(include_url=False) == expected
316+
260317
def test_ordered_dict_key_order_preservation():
261318
# GH 12273
262319
v = SchemaValidator(cs.dict_schema(keys_schema=cs.str_schema(), values_schema=cs.int_schema()))

0 commit comments

Comments
 (0)