@@ -33,6 +33,18 @@ def validator_aok(request):
3333 return IntegerValidator ("prop" , "parent" , min = - 2 , max = 10 , array_ok = True )
3434
3535
36+ @pytest .fixture
37+ def validator_extras ():
38+ return IntegerValidator ("prop" , "parent" , min = - 2 , max = 10 , extras = ["normal" , "bold" ])
39+
40+
41+ @pytest .fixture
42+ def validator_extras_aok ():
43+ return IntegerValidator (
44+ "prop" , "parent" , min = - 2 , max = 10 , array_ok = True , extras = ["normal" , "bold" ]
45+ )
46+
47+
3648# ### Acceptance ###
3749@pytest .mark .parametrize ("val" , [1 , - 19 , 0 , - 1234 ])
3850def test_acceptance (val , validator ):
@@ -57,6 +69,27 @@ def test_acceptance_min_max(val, validator_min_max):
5769 assert validator_min_max .validate_coerce (val ) == approx (val )
5870
5971
72+ # With extras
73+ @pytest .mark .parametrize ("val" , ["normal" , "bold" , 10 , - 2 ])
74+ def test_acceptance_extras (val , validator_extras ):
75+ assert validator_extras .validate_coerce (val ) == val
76+
77+
78+ # Test extras for array_ok
79+ @pytest .mark .parametrize ("val" , [[10 , "normal" , "bold" ], ["normal" ], [10 , - 2 ], [5 ]])
80+ def test_acceptance_extras_array (val , validator_extras_aok ):
81+ assert validator_extras_aok .validate_coerce (val ) == val
82+
83+
84+ # Test rejection by extras
85+ @pytest .mark .parametrize ("val" , ["invalid value" , "different invalid value" , - 3 , 11 ])
86+ def test_rejection_extras (val , validator_extras ):
87+ with pytest .raises (ValueError ) as validation_failure :
88+ validator_extras .validate_coerce (val )
89+
90+ assert "Invalid value" in str (validation_failure .value )
91+
92+
6093@pytest .mark .parametrize (
6194 "val" , [- 1.01 , - 10 , 2.1 , 3 , np .iinfo (int ).max , np .iinfo (int ).min ]
6295)
0 commit comments