Skip to content

Commit 91b130b

Browse files
committed
Test: add new none-required error lines
1 parent 502bf9c commit 91b130b

File tree

3 files changed

+122
-14
lines changed

3 files changed

+122
-14
lines changed

tests/test_hypothesis.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,20 @@ def test_definition_cycles(definition_schema, data):
117117
try:
118118
assert definition_schema.validate_python(data) == data
119119
except ValidationError as exc:
120-
assert exc.errors(include_url=False) == [
121-
{
122-
'type': 'recursion_loop',
123-
'loc': IsTuple(length=(1, None)),
124-
'msg': 'Recursion error - cyclic reference detected',
125-
'input': AnyThing(),
126-
}
127-
]
120+
errors = exc.errors(include_url=False)
121+
122+
# 1st error-line should be the 'recursion-loop' error
123+
assert errors[0] == {
124+
'type': 'recursion_loop',
125+
'loc': IsTuple(length=(1, None)),
126+
'msg': 'Recursion error - cyclic reference detected',
127+
'input': AnyThing(),
128+
}
129+
130+
# There is one 'none-required' error per sub-branch location
131+
assert all(e['type'] == 'none_required' for e in errors[1:])
132+
nb_sub_branch_locs = len(data) - 1
133+
assert nb_sub_branch_locs == len(errors[:1])
128134

129135

130136
def test_definition_broken(definition_schema):

tests/validators/test_definitions_recursive.py

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,13 @@ def test_recursion_branch():
326326
'loc': ('branch',),
327327
'msg': 'Recursion error - cyclic reference detected',
328328
'input': {'name': 'recursive', 'branch': IsPartialDict(name='recursive')},
329-
}
329+
},
330+
{
331+
'type': 'none_required',
332+
'loc': ('branch',),
333+
'msg': 'Input should be None',
334+
'input': {'name': 'recursive', 'branch': IsPartialDict(name='recursive')},
335+
},
330336
]
331337

332338

@@ -375,7 +381,13 @@ def test_recursion_branch_from_attributes():
375381
'loc': ('branch',),
376382
'msg': 'Recursion error - cyclic reference detected',
377383
'input': HasAttributes(name='root', branch=AnyThing()),
378-
}
384+
},
385+
{
386+
'type': 'none_required',
387+
'loc': ('branch',),
388+
'msg': 'Input should be None',
389+
'input': HasAttributes(name='root', branch=AnyThing()),
390+
},
379391
]
380392

381393

@@ -475,12 +487,30 @@ def test_multiple_tuple_recursion(multiple_tuple_schema: SchemaValidator):
475487
'msg': 'Recursion error - cyclic reference detected',
476488
'input': [1, IsList(length=2)],
477489
},
490+
{
491+
'type': 'none_required',
492+
'loc': ('f1', 1),
493+
'msg': 'Input should be None',
494+
'input': [1, IsList(length=2)],
495+
},
478496
{
479497
'type': 'recursion_loop',
480498
'loc': ('f2', 1),
481499
'msg': 'Recursion error - cyclic reference detected',
482500
'input': [1, IsList(length=2)],
483501
},
502+
{
503+
'type': 'none_required',
504+
'loc': ('f2', 1),
505+
'msg': 'Input should be None',
506+
'input': [1, IsList(length=2)],
507+
},
508+
{
509+
'type': 'none_required',
510+
'loc': ('f2',),
511+
'msg': 'Input should be None',
512+
'input': [1, IsList(length=2)],
513+
},
484514
]
485515

486516

@@ -497,12 +527,30 @@ def test_multiple_tuple_recursion_once(multiple_tuple_schema: SchemaValidator):
497527
'msg': 'Recursion error - cyclic reference detected',
498528
'input': [1, IsList(length=2)],
499529
},
530+
{
531+
'type': 'none_required',
532+
'loc': ('f1', 1),
533+
'msg': 'Input should be None',
534+
'input': [1, IsList(length=2)],
535+
},
500536
{
501537
'type': 'recursion_loop',
502538
'loc': ('f2', 1),
503539
'msg': 'Recursion error - cyclic reference detected',
504540
'input': [1, IsList(length=2)],
505541
},
542+
{
543+
'type': 'none_required',
544+
'loc': ('f2', 1),
545+
'msg': 'Input should be None',
546+
'input': [1, IsList(length=2)],
547+
},
548+
{
549+
'type': 'none_required',
550+
'loc': ('f2',),
551+
'msg': 'Input should be None',
552+
'input': [1, IsList(length=2)],
553+
},
506554
]
507555

508556

@@ -539,7 +587,13 @@ def wrap_func(input_value, validator, info):
539587
'loc': (1,),
540588
'msg': 'Recursion error - cyclic reference detected',
541589
'input': IsList(positions={0: 1}, length=2),
542-
}
590+
},
591+
{
592+
'type': 'none_required',
593+
'loc': (1,),
594+
'msg': 'Input should be None',
595+
'input': IsList(positions={0: 1}, length=2),
596+
},
543597
]
544598

545599

@@ -927,7 +981,19 @@ def test_cyclic_data() -> None:
927981
'loc': ('b', 'a'),
928982
'msg': 'Recursion error - cyclic reference detected',
929983
'input': cyclic_data,
930-
}
984+
},
985+
{
986+
'type': 'none_required',
987+
'loc': ('b', 'a'),
988+
'msg': 'Input should be None',
989+
'input': cyclic_data,
990+
},
991+
{
992+
'type': 'none_required',
993+
'loc': ('b',),
994+
'msg': 'Input should be None',
995+
'input': cyclic_data['b'],
996+
},
931997
]
932998

933999

@@ -977,7 +1043,25 @@ def test_cyclic_data_threeway() -> None:
9771043
'loc': ('b', 'c', 'a'),
9781044
'msg': 'Recursion error - cyclic reference detected',
9791045
'input': cyclic_data,
980-
}
1046+
},
1047+
{
1048+
'type': 'none_required',
1049+
'loc': ('b', 'c', 'a'),
1050+
'msg': 'Input should be None',
1051+
'input': cyclic_data,
1052+
},
1053+
{
1054+
'type': 'none_required',
1055+
'loc': ('b', 'c'),
1056+
'msg': 'Input should be None',
1057+
'input': cyclic_data['b']['c'],
1058+
},
1059+
{
1060+
'type': 'none_required',
1061+
'loc': ('b',),
1062+
'msg': 'Input should be None',
1063+
'input': cyclic_data['b'],
1064+
},
9811065
]
9821066

9831067

@@ -1051,6 +1135,12 @@ def test_complex_recursive_type() -> None:
10511135
'msg': 'Input should be a valid boolean',
10521136
'input': datetime.date(1992, 12, 11),
10531137
},
1138+
{
1139+
'type': 'none_required',
1140+
'loc': ('dict[str,...]', 'a'),
1141+
'msg': 'Input should be None',
1142+
'input': datetime.date(1992, 12, 11),
1143+
},
10541144
{
10551145
'type': 'string_type',
10561146
'loc': ('str',),
@@ -1075,6 +1165,12 @@ def test_complex_recursive_type() -> None:
10751165
'msg': 'Input should be a valid boolean',
10761166
'input': {'a': datetime.date(1992, 12, 11)},
10771167
},
1168+
{
1169+
'type': 'none_required',
1170+
'loc': (),
1171+
'msg': 'Input should be None',
1172+
'input': {'a': datetime.date(1992, 12, 11)},
1173+
},
10781174
]
10791175

10801176

tests/validators/test_nullable.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ def test_nullable():
2121
'loc': (),
2222
'msg': 'Input should be a valid integer, unable to parse string as an integer',
2323
'input': 'hello',
24-
}
24+
},
25+
{
26+
'type': 'none_required',
27+
'loc': (),
28+
'msg': 'Input should be None',
29+
'input': 'hello',
30+
},
2531
]
2632

2733

0 commit comments

Comments
 (0)