7
7
8
8
# Fixtures
9
9
# --------
10
- @pytest .fixture ()
11
- def validator ():
10
+ @pytest .fixture
11
+ def validator (request ):
12
12
return AngleValidator ("prop" , "parent" )
13
13
14
14
15
+ @pytest .fixture
16
+ def validator_aok (request ):
17
+ return AngleValidator ("prop" , "parent" , array_ok = True )
18
+
19
+
15
20
# Tests
16
21
# -----
17
22
# ### Test acceptance ###
@@ -36,3 +41,32 @@ def test_rejection(val, validator):
36
41
validator .validate_coerce (val )
37
42
38
43
assert "Invalid value" in str (validation_failure .value )
44
+
45
+
46
+ # ### Test acceptance ###
47
+ @pytest .mark .parametrize ("val" , [[0 , 179 , - 179 ]])
48
+ def test_aok_acceptance (val , validator_aok ):
49
+ assert validator_aok .validate_coerce (val ) == val
50
+ assert validator_aok .validate_coerce (tuple (val )) == val
51
+ assert np .array_equal (validator_aok .validate_coerce (np .array (val )), np .array (val ))
52
+
53
+
54
+ # ### Test coercion above 180 ###
55
+ @pytest .mark .parametrize (
56
+ "val,expected" ,
57
+ [(180 , - 180 ), (181 , - 179 ), (- 180.25 , 179.75 ), (540 , - 180 ), (- 541 , 179 )],
58
+ )
59
+ def test_aok_coercion (val , expected , validator_aok ):
60
+ assert validator_aok .validate_coerce ([val ]) == [expected ]
61
+ assert np .array_equal (
62
+ validator_aok .validate_coerce (np .array ([val ])), np .array ([expected ])
63
+ )
64
+
65
+
66
+ # ### Test rejection ###
67
+ @pytest .mark .parametrize ("val" , [["hello" ], [()], [[]], [set ()], ["34" ]])
68
+ def test_aok_rejection (val , validator_aok ):
69
+ with pytest .raises (ValueError ) as validation_failure :
70
+ validator_aok .validate_coerce (val )
71
+
72
+ assert "Invalid element(s)" in str (validation_failure .value )
0 commit comments