@@ -231,7 +231,7 @@ def test_node_init(
231231 ],
232232 ids = ["No rules" , "String" , "List" , "ListString" , "InRange" , "Regex" , "Date" , "URL" ],
233233)
234- def test_get_validation_rule_based_fields (
234+ def test_get_validation_rule_based_fields_no_explicit_type (
235235 validation_rules : list [str ],
236236 expected_type : Optional [JSONSchemaType ],
237237 expected_is_array : bool ,
@@ -240,15 +240,104 @@ def test_get_validation_rule_based_fields(
240240 expected_pattern : Optional [str ],
241241 expected_format : Optional [JSONSchemaFormat ],
242242) -> None :
243- """Tests for _get_validation_rule_based_fields"""
243+ """
244+ Test for _get_validation_rule_based_fields
245+ Tests that output is expected based on the input validation rules
246+ """
247+ (
248+ is_array ,
249+ property_type ,
250+ property_format ,
251+ minimum ,
252+ maximum ,
253+ pattern ,
254+ ) = _get_validation_rule_based_fields (validation_rules , None , "name" )
255+ assert property_type == expected_type
256+ assert property_format == expected_format
257+ assert is_array == expected_is_array
258+ assert minimum == expected_min
259+ assert maximum == expected_max
260+ assert pattern == expected_pattern
261+
262+
263+ @pytest .mark .parametrize (
264+ "validation_rules, explicit_type, expected_type, expected_is_array, expected_min, expected_max, expected_pattern, expected_format" ,
265+ [
266+ (
267+ ["str" ],
268+ JSONSchemaType .STRING ,
269+ JSONSchemaType .STRING ,
270+ False ,
271+ None ,
272+ None ,
273+ None ,
274+ None ,
275+ ),
276+ (
277+ ["inRange 50 100" ],
278+ JSONSchemaType .NUMBER ,
279+ JSONSchemaType .NUMBER ,
280+ False ,
281+ 50 ,
282+ 100 ,
283+ None ,
284+ None ,
285+ ),
286+ (
287+ ["regex search [a-f]" ],
288+ JSONSchemaType .STRING ,
289+ JSONSchemaType .STRING ,
290+ False ,
291+ None ,
292+ None ,
293+ "[a-f]" ,
294+ None ,
295+ ),
296+ (
297+ ["date" ],
298+ JSONSchemaType .STRING ,
299+ JSONSchemaType .STRING ,
300+ False ,
301+ None ,
302+ None ,
303+ None ,
304+ JSONSchemaFormat .DATE ,
305+ ),
306+ (
307+ ["url" ],
308+ JSONSchemaType .STRING ,
309+ JSONSchemaType .STRING ,
310+ False ,
311+ None ,
312+ None ,
313+ None ,
314+ JSONSchemaFormat .URI ,
315+ ),
316+ ],
317+ ids = ["String" , "InRange" , "Regex" , "Date" , "URL" ],
318+ )
319+ def test_get_validation_rule_based_fields_with_explicit_type (
320+ validation_rules : list [str ],
321+ explicit_type : JSONSchemaType ,
322+ expected_type : Optional [JSONSchemaType ],
323+ expected_is_array : bool ,
324+ expected_min : Optional [float ],
325+ expected_max : Optional [float ],
326+ expected_pattern : Optional [str ],
327+ expected_format : Optional [JSONSchemaFormat ],
328+ ) -> None :
329+ """
330+ Test for _get_validation_rule_based_fields
331+ Tests that output is expected based on the input validation rules, and explicit type
332+ """
244333 (
245334 is_array ,
246335 property_type ,
247336 property_format ,
248337 minimum ,
249338 maximum ,
250339 pattern ,
251- ) = _get_validation_rule_based_fields (validation_rules )
340+ ) = _get_validation_rule_based_fields (validation_rules , explicit_type , "name" )
252341 assert property_type == expected_type
253342 assert property_format == expected_format
254343 assert is_array == expected_is_array
@@ -257,6 +346,35 @@ def test_get_validation_rule_based_fields(
257346 assert pattern == expected_pattern
258347
259348
349+ @pytest .mark .parametrize (
350+ "validation_rules, explicit_type" ,
351+ [
352+ (["str" ], JSONSchemaType .INTEGER ),
353+ (["inRange 50 100" ], JSONSchemaType .STRING ),
354+ (["regex search [a-f]" ], JSONSchemaType .INTEGER ),
355+ (["date" ], JSONSchemaType .INTEGER ),
356+ (["url" ], JSONSchemaType .INTEGER ),
357+ ],
358+ ids = [
359+ "String rule, integer type" ,
360+ "InRange rule, string type" ,
361+ "Regex rule, integer type" ,
362+ "Date rule, integer type" ,
363+ "Url rule, integer type" ,
364+ ],
365+ )
366+ def test_get_validation_rule_based_fields_with_exception (
367+ validation_rules : list [str ],
368+ explicit_type : JSONSchemaType ,
369+ ) -> None :
370+ """
371+ Test for _get_validation_rule_based_fields
372+ Tests that output is expected based on the input validation rules, and explicit type
373+ """
374+ with pytest .raises (ValueError ):
375+ _get_validation_rule_based_fields (validation_rules , explicit_type , "name" )
376+
377+
260378class TestGraphTraversalState :
261379 """Tests for GraphTraversalState class"""
262380
0 commit comments