-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathtest_compound_validator.py
61 lines (42 loc) · 1.57 KB
/
test_compound_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 CompoundValidator
from plotly.graph_objs.scatter import Marker
# Fixtures
# --------
@pytest.fixture()
def validator():
return CompoundValidator('prop', 'scatter',
data_class_str='Marker',
data_docs='')
# Tests
# -----
def test_acceptance(validator: CompoundValidator):
val = Marker(color='green', size=10)
res = validator.validate_coerce(val)
assert isinstance(res, Marker)
assert res.color == 'green'
assert res.size == 10
def test_acceptance_none(validator: CompoundValidator):
val = None
res = validator.validate_coerce(val)
assert isinstance(res, Marker)
assert res.color is None
assert res.size is None
def test_acceptance_dict(validator: CompoundValidator):
val = dict(color='green', size=10)
res = validator.validate_coerce(val)
assert isinstance(res, Marker)
assert res.color == 'green'
assert res.size == 10
def test_rejection_type(validator: CompoundValidator):
val = 37
with pytest.raises(ValueError) as validation_failure:
validator.validate_coerce(val)
assert "Invalid value" in str(validation_failure.value)
def test_rejection_value(validator: CompoundValidator):
val = dict(color='green', size=10, bogus=99)
with pytest.raises(ValueError) as validation_failure:
validator.validate_coerce(val)
assert ("Invalid property specified for object of type "
"plotly.graph_objs.scatter.Marker: 'bogus'" in
str(validation_failure.value))