Skip to content

Commit e500e38

Browse files
committed
Add more base64 array_ok tests
1 parent 1c0b48e commit e500e38

File tree

7 files changed

+63
-3
lines changed

7 files changed

+63
-3
lines changed

packages/python/plotly/_plotly_utils/tests/validators/test_color_validator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
from _plotly_utils.basevalidators import ColorValidator
33
import numpy as np
4+
from plotly.tests.b64 import b64
45

56

67
# Fixtures
@@ -131,6 +132,18 @@ def test_acceptance_aok(val, validator_aok):
131132
assert coerce_val == val
132133

133134

135+
# Test that it doesn't use a base64 array
136+
# Numpy v2 has a StrDType but we don't want to convert it yet.
137+
# Change this test if you add support for it.
138+
def test_acceptance_aok_base64_array(validator_aok):
139+
val = b64(np.array(['aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure']))
140+
coerce_val = validator_aok.validate_coerce(val)
141+
assert coerce_val[0] == 'aliceblue'
142+
assert coerce_val[1] == 'antiquewhite'
143+
assert coerce_val[2] == 'aqua'
144+
assert coerce_val[3] == 'aquamarine'
145+
assert coerce_val[4] == 'azure'
146+
134147
@pytest.mark.parametrize(
135148
"val",
136149
[

packages/python/plotly/_plotly_utils/tests/validators/test_colorlist_validator.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33

44
from _plotly_utils.basevalidators import ColorlistValidator
5-
5+
from plotly.tests.b64 import b64
66

77
# Fixtures
88
# --------
@@ -48,3 +48,12 @@ def test_acceptance_aok(val, validator):
4848
coerce_val = validator.validate_coerce(val)
4949
assert isinstance(coerce_val, list)
5050
assert validator.present(coerce_val) == tuple(val)
51+
52+
# Test that it doesn't use a base64 array
53+
# Numpy v2 has a StrDType but we don't want to convert it yet.
54+
# Change this test if you add support for it.
55+
def test_acceptance_b64_aok(validator):
56+
val = b64(np.array(["red", "rgb(255, 0, 0)"]))
57+
coerce_val = validator.validate_coerce(val)
58+
assert coerce_val[0] == "red"
59+
assert coerce_val[1] == "rgb(255, 0, 0)"

packages/python/plotly/_plotly_utils/tests/validators/test_compoundarray_validator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import pytest
22
from _plotly_utils.basevalidators import CompoundArrayValidator
33
from plotly.graph_objs.layout import Image
4-
4+
import numpy as np
5+
from plotly.tests.b64 import b64
56

67
# Fixtures
78
# --------

packages/python/plotly/_plotly_utils/tests/validators/test_enumerated_validator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import numpy as np
33
import pandas as pd
44
from _plotly_utils.basevalidators import EnumeratedValidator
5+
from plotly.tests.b64 import b64
56

67

78
# Fixtures
@@ -93,6 +94,12 @@ def test_acceptance_aok(val, validator_aok):
9394
else:
9495
assert coerce_val == val
9596

97+
# Test base64 array
98+
def test_aok_base64_array(validator_aok):
99+
val = b64(np.array([1, 2, 3], dtype="int64"))
100+
coerce_val = validator_aok.validate_coerce(val)
101+
assert coerce_val["bdata"] == "AQID"
102+
assert coerce_val["dtype"] == "i1"
96103

97104
# ### Rejection by value ###
98105
@pytest.mark.parametrize("val", [True, 0, 1, 23, np.inf, set()])

packages/python/plotly/_plotly_utils/tests/validators/test_flaglist_validator.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33
from _plotly_utils.basevalidators import FlaglistValidator
44
import numpy as np
5-
5+
from plotly.tests.b64 import b64
66

77
EXTRAS = ["none", "all", True, False, 3]
88
FLAGS = ["lines", "markers", "text"]
@@ -130,6 +130,14 @@ def test_acceptance_aok_scalar_extra(extra, validator_extra_aok):
130130
assert validator_extra_aok.validate_coerce(extra) == extra
131131

132132

133+
# Test base64 array
134+
def test_acceptance_aok_scalar_base64(validator_extra_aok):
135+
val = b64(np.array([1, 2, 3], dtype="int64"))
136+
coerce_val = validator_extra_aok.validate_coerce(val)
137+
assert coerce_val["bdata"] == "AQID"
138+
assert coerce_val["dtype"] == "i1"
139+
140+
133141
# ### Acceptance (lists) ###
134142
def test_acceptance_aok_scalarlist_flaglist(flaglist, validator_extra_aok):
135143
assert np.array_equal(

packages/python/plotly/_plotly_utils/tests/validators/test_number_validator.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from _plotly_utils.basevalidators import NumberValidator
55
import numpy as np
66
import pandas as pd
7+
from plotly.tests.b64 import b64
78

89
# Fixtures
910
# --------
@@ -108,6 +109,14 @@ def test_acceptance_aok_list(val, validator_aok):
108109
)
109110

110111

112+
# Test base64 array
113+
def test_acceptance_aok_base64(validator_aok):
114+
val = b64(np.array([1, 2, 3], dtype="int64"))
115+
coerce_val = validator_aok.validate_coerce(val)
116+
assert coerce_val["bdata"] == "AQID"
117+
assert coerce_val["dtype"] == "i1"
118+
119+
111120
# ### Coerce ###
112121
# Coerced to general consistent numeric type
113122
@pytest.mark.parametrize(

packages/python/plotly/_plotly_utils/tests/validators/test_string_validator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from _plotly_utils.basevalidators import StringValidator
44
import numpy as np
55

6+
from plotly.tests.b64 import b64
7+
68

79
# Fixtures
810
# --------
@@ -145,6 +147,17 @@ def test_acceptance_aok_list(val, validator_aok):
145147
assert coerce_val == val
146148

147149

150+
# Test that it doesn't use a base64 array
151+
# Numpy v2 has a StrDType but we don't want to convert it yet.
152+
# Change this test if you add support for it.
153+
def test_aok_base64_array(validator_aok):
154+
val = b64(np.array(['a', 'b', 'c'], dtype=np.dtypes.StrDType))
155+
coerce_val = validator_aok.validate_coerce(val)
156+
assert coerce_val[0] == 'a'
157+
assert coerce_val[1] == 'b'
158+
assert coerce_val[2] == 'c'
159+
160+
148161
# ### Rejection by type ###
149162
@pytest.mark.parametrize("val", [["foo", ()], ["foo", 3, 4], [3, 2, 1]])
150163
def test_rejection_aok(val, validator_aok_strict):

0 commit comments

Comments
 (0)