@@ -67,7 +67,6 @@ def definition_schema():
67
67
[
68
68
cs .typed_dict_schema (
69
69
{
70
- 'name' : cs .typed_dict_field (cs .str_schema ()),
71
70
'sub_branch' : cs .typed_dict_field (
72
71
cs .with_default_schema (
73
72
cs .nullable_schema (cs .definition_reference_schema ('Branch' )), default = None
@@ -82,11 +81,10 @@ def definition_schema():
82
81
83
82
84
83
def test_definition_simple (definition_schema ):
85
- assert definition_schema .validate_python ({'name' : 'root' }) == {'name' : 'root' , 'sub_branch' : None }
84
+ assert definition_schema .validate_python ({}) == {'sub_branch' : None }
86
85
87
86
88
87
class BranchModel (TypedDict ):
89
- name : str
90
88
sub_branch : Optional ['BranchModel' ]
91
89
92
90
@@ -97,34 +95,30 @@ def test_recursive(definition_schema, data):
97
95
assert definition_schema .validate_python (data ) == data
98
96
99
97
100
- @strategies .composite
101
- def branch_models_with_cycles (draw , existing = None ):
102
- if existing is None :
103
- existing = []
104
- model = BranchModel (name = draw (strategies .text ()), sub_branch = None )
105
- existing .append (model )
106
- model ['sub_branch' ] = draw (
107
- strategies .none ()
108
- | strategies .builds (BranchModel , name = strategies .text (), sub_branch = branch_models_with_cycles (existing ))
109
- | strategies .sampled_from (existing )
110
- )
111
- return model
98
+ @given (strategies .integers (min_value = 0 , max_value = 10 ))
99
+ @pytest .mark .thread_unsafe # https://github.com/Quansight-Labs/pytest-run-parallel/issues/20
100
+ def test_definition_cycles (definition_schema , depth ):
101
+ data = BranchModel (sub_branch = None )
102
+ model = data
112
103
104
+ for _ in range (depth ):
105
+ next_model = BranchModel (sub_branch = None )
106
+ model ['sub_branch' ] = next_model
107
+ model = next_model
113
108
114
- @given (branch_models_with_cycles ())
115
- @pytest .mark .thread_unsafe # https://github.com/Quansight-Labs/pytest-run-parallel/issues/20
116
- def test_definition_cycles (definition_schema , data ):
117
- try :
118
- assert definition_schema .validate_python (data ) == data
119
- 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
- ]
109
+ model ['sub_branch' ] = data
110
+
111
+ with pytest .raises (ValidationError ) as exc_info :
112
+ definition_schema .validate_python (data )
113
+
114
+ assert exc_info .value .errors (include_url = False ) == [
115
+ {
116
+ 'type' : 'recursion_loop' ,
117
+ 'loc' : IsTuple (length = (1 , None )),
118
+ 'msg' : 'Recursion error - cyclic reference detected' ,
119
+ 'input' : AnyThing (),
120
+ }
121
+ ]
128
122
129
123
130
124
def test_definition_broken (definition_schema ):
0 commit comments