Skip to content

Commit 6660820

Browse files
angle aok tests
1 parent 8986034 commit 6660820

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

Diff for: packages/python/plotly/_plotly_utils/tests/validators/test_angle_validator.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77

88
# Fixtures
99
# --------
10-
@pytest.fixture()
11-
def validator():
10+
@pytest.fixture
11+
def validator(request):
1212
return AngleValidator("prop", "parent")
1313

1414

15+
@pytest.fixture
16+
def validator_aok(request):
17+
return AngleValidator("prop", "parent", array_ok=True)
18+
19+
1520
# Tests
1621
# -----
1722
# ### Test acceptance ###
@@ -36,3 +41,32 @@ def test_rejection(val, validator):
3641
validator.validate_coerce(val)
3742

3843
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

Comments
 (0)