@@ -33,6 +33,18 @@ def validator_aok(request):
33
33
return IntegerValidator ("prop" , "parent" , min = - 2 , max = 10 , array_ok = True )
34
34
35
35
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
+
36
48
# ### Acceptance ###
37
49
@pytest .mark .parametrize ("val" , [1 , - 19 , 0 , - 1234 ])
38
50
def test_acceptance (val , validator ):
@@ -57,6 +69,27 @@ def test_acceptance_min_max(val, validator_min_max):
57
69
assert validator_min_max .validate_coerce (val ) == approx (val )
58
70
59
71
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
+
60
93
@pytest .mark .parametrize (
61
94
"val" , [- 1.01 , - 10 , 2.1 , 3 , np .iinfo (int ).max , np .iinfo (int ).min ]
62
95
)
0 commit comments