@@ -79,11 +79,16 @@ def from_js_regex(pattern: str, alphabet: CharStrategy) -> st.SearchStrategy[str
79
79
80
80
81
81
def merged_as_strategies (
82
- schemas : List [Schema ], custom_formats : Optional [Dict [str , st .SearchStrategy [str ]]]
82
+ schemas : List [Schema ],
83
+ * ,
84
+ alphabet : CharStrategy ,
85
+ custom_formats : Optional [Dict [str , st .SearchStrategy [str ]]],
83
86
) -> st .SearchStrategy [JSONType ]:
84
87
assert schemas , "internal error: must pass at least one schema to merge"
85
88
if len (schemas ) == 1 :
86
- return from_schema (schemas [0 ], custom_formats = custom_formats )
89
+ return __from_schema (
90
+ schemas [0 ], alphabet = alphabet , custom_formats = custom_formats
91
+ )
87
92
# Try to merge combinations of strategies.
88
93
strats = []
89
94
combined : Set [str ] = set ()
@@ -96,7 +101,9 @@ def merged_as_strategies(
96
101
s = merged ([inputs [g ] for g in group ])
97
102
if s is not None and s != FALSEY :
98
103
strats .append (
99
- from_schema (s , custom_formats = custom_formats ).filter (
104
+ __from_schema (
105
+ s , alphabet = alphabet , custom_formats = custom_formats
106
+ ).filter (
100
107
lambda obj , validators = tuple (
101
108
make_validator (s ).is_valid for s in schemas
102
109
): all (v (obj ) for v in validators )
@@ -165,7 +172,7 @@ def __from_schema(
165
172
schema : Union [bool , Schema ],
166
173
* ,
167
174
alphabet : CharStrategy ,
168
- custom_formats : Optional [Dict [str , st .SearchStrategy [str ]]] = None ,
175
+ custom_formats : Optional [Dict [str , st .SearchStrategy [str ]]],
169
176
) -> st .SearchStrategy [JSONType ]:
170
177
try :
171
178
schema = resolve_all_refs (schema )
@@ -217,27 +224,36 @@ def __from_schema(
217
224
not_ = schema .pop ("not" )
218
225
assert isinstance (not_ , dict )
219
226
validator = make_validator (not_ ).is_valid
220
- return from_schema ( schema , custom_formats = custom_formats ). filter (
221
- lambda v : not validator ( v )
222
- )
227
+ return __from_schema (
228
+ schema , alphabet = alphabet , custom_formats = custom_formats
229
+ ). filter ( lambda v : not validator ( v ))
223
230
if "anyOf" in schema :
224
231
tmp = schema .copy ()
225
232
ao = tmp .pop ("anyOf" )
226
233
assert isinstance (ao , list )
227
- return st .one_of ([merged_as_strategies ([tmp , s ], custom_formats ) for s in ao ])
234
+ return st .one_of (
235
+ [
236
+ merged_as_strategies (
237
+ [tmp , s ], alphabet = alphabet , custom_formats = custom_formats
238
+ )
239
+ for s in ao
240
+ ]
241
+ )
228
242
if "allOf" in schema :
229
243
tmp = schema .copy ()
230
244
ao = tmp .pop ("allOf" )
231
245
assert isinstance (ao , list )
232
- return merged_as_strategies ([tmp , * ao ], custom_formats )
246
+ return merged_as_strategies (
247
+ [tmp , * ao ], alphabet = alphabet , custom_formats = custom_formats
248
+ )
233
249
if "oneOf" in schema :
234
250
tmp = schema .copy ()
235
251
oo = tmp .pop ("oneOf" )
236
252
assert isinstance (oo , list )
237
253
schemas = [merged ([tmp , s ]) for s in oo ]
238
254
return st .one_of (
239
255
[
240
- from_schema ( s , custom_formats = custom_formats )
256
+ __from_schema ( s , alphabet = alphabet , custom_formats = custom_formats )
241
257
for s in schemas
242
258
if s is not None
243
259
]
@@ -692,7 +708,13 @@ def from_object_schema(draw: Any) -> Any:
692
708
pattern_schemas .insert (0 , properties [key ])
693
709
694
710
if pattern_schemas :
695
- out [key ] = draw (merged_as_strategies (pattern_schemas , custom_formats ))
711
+ out [key ] = draw (
712
+ merged_as_strategies (
713
+ pattern_schemas ,
714
+ alphabet = alphabet ,
715
+ custom_formats = custom_formats ,
716
+ )
717
+ )
696
718
else :
697
719
out [key ] = draw (
698
720
__from_schema (
0 commit comments