@@ -457,24 +457,26 @@ def test_parse_success(self, data: dict[str, Any]) -> None:
457457 # no exception was raised.
458458
459459 @pytest .mark .parametrize (
460- "data,error_count" ,
460+ "data,error_count,error_loc " ,
461461 [
462- pytest .param ({}, 1 , id = "missing amounts & attributes" ),
463- pytest .param ({"unknown" : "value" }, 1 , id = "unknown field" ),
464- pytest .param ({"amounts" : []}, 1 , id = "too few amounts" ),
465- pytest .param ({"attributes" : []}, 1 , id = "too few attributes" ),
462+ pytest .param ({}, 1 , (), id = "missing amounts & attributes" ),
463+ pytest .param ({"unknown" : "value" }, 1 , ( "unknown" ,), id = "unknown field" ),
464+ pytest .param ({"amounts" : []}, 1 , ( "amounts" ,), id = "too few amounts" ),
465+ pytest .param ({"attributes" : []}, 1 , ( "attributes" ,), id = "too few attributes" ),
466466 pytest .param (
467467 {"amounts" : [{"name" : f"amount.mycap{ i } " , "min" : 1 } for i in range (0 , 51 )]},
468468 1 ,
469+ (),
469470 id = "too many as only amounts" ,
470471 ),
471472 pytest .param (
472473 {
473474 "attributes" : [
474- {"name" : f"attr.mycap{ i } | " , "anyOf" : ["foo" ]} for i in range (0 , 51 )
475+ {"name" : f"attr.mycap{ i } " , "anyOf" : ["foo" ]} for i in range (0 , 51 )
475476 ]
476477 },
477478 1 ,
479+ (),
478480 id = "too many as only attributes" ,
479481 ),
480482 pytest .param (
@@ -485,16 +487,66 @@ def test_parse_success(self, data: dict[str, Any]) -> None:
485487 ],
486488 },
487489 1 ,
490+ (),
488491 id = "too many as combination" ,
489492 ),
493+ pytest .param (
494+ {
495+ "amounts" : [
496+ {"name" : "amount.mycap" , "min" : 1 },
497+ {"name" : "amount.mycap" , "min" : 2 },
498+ ]
499+ },
500+ 1 ,
501+ ("amounts" ,),
502+ id = "duplicate amount names" ,
503+ ),
504+ pytest .param (
505+ {
506+ "amounts" : [
507+ {"name" : "amount.mycap" , "min" : 1 },
508+ {"name" : "amount.MYCAP" , "min" : 2 },
509+ ]
510+ },
511+ 1 ,
512+ ("amounts" ,),
513+ id = "duplicate amount names case insensitive" ,
514+ ),
515+ pytest .param (
516+ {
517+ "attributes" : [
518+ {"name" : "attr.mycap" , "anyOf" : ["foo" ]},
519+ {"name" : "attr.mycap" , "anyOf" : ["bar" ]},
520+ ]
521+ },
522+ 1 ,
523+ ("attributes" ,),
524+ id = "duplicate attribute names" ,
525+ ),
526+ pytest .param (
527+ {
528+ "attributes" : [
529+ {"name" : "attr.mycap" , "anyOf" : ["foo" ]},
530+ {"name" : "attr.MYCAP" , "anyOf" : ["bar" ]},
531+ ]
532+ },
533+ 1 ,
534+ ("attributes" ,),
535+ id = "duplicate attribute names case insensitive" ,
536+ ),
490537 ],
491538 )
492- def test_parse_fails (self , data : dict [str , Any ], error_count : int ) -> None :
493- # Failure case testing for Open Job Description AmountRequirementTemplate .
539+ def test_parse_fails (self , data : dict [str , Any ], error_count : int , error_loc : tuple ) -> None :
540+ # Failure case testing for Open Job Description HostRequirementsTemplate .
494541
495542 # WHEN
496543 with pytest .raises (ValidationError ) as excinfo :
497- _parse_model (model = AmountRequirementTemplate , obj = data )
544+ _parse_model (model = HostRequirementsTemplate , obj = data )
498545
499546 # THEN
500547 assert len (excinfo .value .errors ()) == error_count , str (excinfo .value )
548+ if error_loc :
549+ actual_loc = excinfo .value .errors ()[0 ]["loc" ]
550+ assert (
551+ actual_loc [: len (error_loc )] == error_loc
552+ ), f"Expected { error_loc } , got { actual_loc } "
0 commit comments