-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathtest_dash_validator.py
61 lines (47 loc) · 1.48 KB
/
test_dash_validator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import pytest
from _plotly_utils.basevalidators import DashValidator
# Constants
# ---------
dash_types = ["solid", "dot", "dash", "longdash", "dashdot", "longdashdot"]
# Fixtures
# --------
@pytest.fixture()
def validator():
return DashValidator("prop", "parent", dash_types)
# Acceptance
# ----------
@pytest.mark.parametrize("val", dash_types)
def test_acceptance_dash_types(val, validator):
# Values should be accepted and returned unchanged
assert validator.validate_coerce(val) == val
@pytest.mark.parametrize(
"val",
[
"2",
"2.2",
"2.002",
"1 2 002",
"1,2,3",
"1, 2, 3",
"1px 2px 3px",
"1.5px, 2px, 3.9px",
"23% 18% 13px",
"200% 3px",
],
)
def test_acceptance_dash_lists(val, validator):
# Values should be accepted and returned unchanged
assert validator.validate_coerce(val) == val
# Rejection
# ---------
# ### Value Rejection ###
@pytest.mark.parametrize("val", ["bogus", "not-a-dash"])
def test_rejection_by_bad_dash_type(val, validator):
with pytest.raises(ValueError) as validation_failure:
validator.validate_coerce(val)
assert "Invalid value" in str(validation_failure.value)
@pytest.mark.parametrize("val", ["", "1,,3,4", "2 3 C", "2pxx 3 4"])
def test_rejection_by_bad_dash_list(val, validator):
with pytest.raises(ValueError) as validation_failure:
validator.validate_coerce(val)
assert "Invalid value" in str(validation_failure.value)