Skip to content

Commit 0d0dad2

Browse files
committed
Revert changes to validator tests
1 parent de2bcb5 commit 0d0dad2

14 files changed

+12
-169
lines changed

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

-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# from ..basevalidators import AngleValidator
44
from _plotly_utils.basevalidators import AngleValidator
55
import numpy as np
6-
from plotly.tests.b64 import b64
76

87

98
# Fixtures
@@ -52,14 +51,6 @@ def test_aok_acceptance(val, validator_aok):
5251
assert np.array_equal(validator_aok.validate_coerce(np.array(val)), np.array(val))
5352

5453

55-
# Test base64 array
56-
def test_aok_base64_array(validator_aok):
57-
val = b64(np.array([1, 2, 3], dtype="int64"))
58-
coerce_val = validator_aok.validate_coerce(val)
59-
assert coerce_val["bdata"] == "AQID"
60-
assert coerce_val["dtype"] == "i1"
61-
62-
6354
# ### Test coercion above 180 ###
6455
@pytest.mark.parametrize(
6556
"val,expected",

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

-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
from _plotly_utils.basevalidators import AnyValidator
33
import numpy as np
4-
from plotly.tests.b64 import b64
54

65

76
# Fixtures
@@ -50,10 +49,3 @@ def test_acceptance_array(val, validator_aok):
5049
else:
5150
assert coerce_val == val
5251
assert validator_aok.present(coerce_val) == val
53-
54-
55-
def test_base64_array(validator_aok):
56-
val = b64(np.array([1, 2, 3], dtype="int64"))
57-
coerce_val = validator_aok.validate_coerce(val)
58-
assert coerce_val["bdata"] == "AQID"
59-
assert coerce_val["dtype"] == "i1"

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

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from _plotly_utils.basevalidators import BaseDataValidator
33
from plotly.graph_objs import Scatter, Bar, Box
4-
import numpy as np
4+
55

66
# Fixtures
77
# --------
@@ -118,19 +118,6 @@ def test_rejection_element_tracetype(validator):
118118
assert "Invalid element(s)" in str(validation_failure.value)
119119

120120

121-
def test_b64(validator):
122-
val = [dict(type="scatter", x=np.array([1, 2, 3]))]
123-
res = validator.validate_coerce(val)
124-
res_present = validator.present(res)
125-
126-
assert isinstance(res, list)
127-
assert isinstance(res_present, tuple)
128-
129-
assert isinstance(res_present[0], Scatter)
130-
assert res_present[0].type == "scatter"
131-
assert res_present[0].x == {"bdata": "AQID", "dtype": "i1"}
132-
133-
134121
def test_skip_invalid(validator_nouid):
135122
val = (
136123
dict(

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

-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
from _plotly_utils.basevalidators import ColorValidator
33
import numpy as np
4-
from plotly.tests.b64 import b64
54

65

76
# Fixtures
@@ -132,19 +131,6 @@ def test_acceptance_aok(val, validator_aok):
132131
assert coerce_val == val
133132

134133

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-
147-
148134
@pytest.mark.parametrize(
149135
"val",
150136
[

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

+1-11
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-
from plotly.tests.b64 import b64
5+
66

77
# Fixtures
88
# --------
@@ -48,13 +48,3 @@ 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-
53-
# Test that it doesn't use a base64 array
54-
# Numpy v2 has a StrDType but we don't want to convert it yet.
55-
# Change this test if you add support for it.
56-
def test_acceptance_b64_aok(validator):
57-
val = b64(np.array(["red", "rgb(255, 0, 0)"]))
58-
coerce_val = validator.validate_coerce(val)
59-
assert coerce_val[0] == "red"
60-
assert coerce_val[1] == "rgb(255, 0, 0)"

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

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from _plotly_utils.basevalidators import CompoundArrayValidator
33
from plotly.graph_objs.layout import Image
44

5+
56
# Fixtures
67
# --------
78
@pytest.fixture()

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

+2-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from _plotly_utils.basevalidators import DataArrayValidator
33
import numpy as np
44
import pandas as pd
5-
from plotly.tests.b64 import b64
65

76
# Fixtures
87
# --------
@@ -34,22 +33,12 @@ def test_validator_acceptance_simple(val, validator):
3433

3534
@pytest.mark.parametrize(
3635
"val",
37-
[pd.Series(["a", "b", "c"])],
36+
[np.array([2, 3, 4]), pd.Series(["a", "b", "c"]), np.array([[1, 2, 3], [4, 5, 6]])],
3837
)
3938
def test_validator_acceptance_homogeneous(val, validator):
4039
coerce_val = validator.validate_coerce(val)
4140
assert isinstance(coerce_val, np.ndarray)
42-
assert np.array_equal(validator.present(coerce_val), b64(val))
43-
44-
45-
@pytest.mark.parametrize(
46-
"val",
47-
[np.array([2, 3, 4]), np.array([[1, 2, 3], [4, 5, 6]])],
48-
)
49-
def test_validator_acceptance_homogeneous(val, validator):
50-
coerce_val = validator.validate_coerce(val)
51-
assert isinstance(coerce_val, object)
52-
assert np.array_equal(validator.present(coerce_val), b64(val))
41+
assert np.array_equal(validator.present(coerce_val), val)
5342

5443

5544
# ### Rejection ###

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

-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import numpy as np
33
import pandas as pd
44
from _plotly_utils.basevalidators import EnumeratedValidator
5-
from plotly.tests.b64 import b64
65

76

87
# Fixtures
@@ -95,14 +94,6 @@ def test_acceptance_aok(val, validator_aok):
9594
assert coerce_val == val
9695

9796

98-
# Test base64 array
99-
def test_aok_base64_array(validator_aok):
100-
val = b64(np.array([1, 2, 3], dtype="int64"))
101-
coerce_val = validator_aok.validate_coerce(val)
102-
assert coerce_val["bdata"] == "AQID"
103-
assert coerce_val["dtype"] == "i1"
104-
105-
10697
# ### Rejection by value ###
10798
@pytest.mark.parametrize("val", [True, 0, 1, 23, np.inf, set()])
10899
def test_rejection_by_value_aok(val, validator_aok):

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

+1-9
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-
from plotly.tests.b64 import b64
5+
66

77
EXTRAS = ["none", "all", True, False, 3]
88
FLAGS = ["lines", "markers", "text"]
@@ -130,14 +130,6 @@ 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-
141133
# ### Acceptance (lists) ###
142134
def test_acceptance_aok_scalarlist_flaglist(flaglist, validator_extra_aok):
143135
assert np.array_equal(

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

-46
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pytest
44
from pytest import approx
55
from _plotly_utils.basevalidators import IntegerValidator
6-
from plotly.tests.b64 import b64
76
import numpy as np
87
import pandas as pd
98

@@ -145,51 +144,6 @@ def test_acceptance_aok_list(val, validator_aok):
145144
assert np.array_equal(validator_aok.validate_coerce(val), val)
146145

147146

148-
# Test base64 encoded arrays with array_ok=True
149-
INT_BASE64_TEST_CASES = [
150-
# Note: we decided not to support int64 in plotly.js,
151-
# so the the max / min value are limited to int32 and the
152-
# dtype is cast to int32 in the output
153-
(
154-
b64(np.array([-900000000, 900000000, 3], dtype="int64")),
155-
{"bdata": "ABdbygDppDUDAAAA", "dtype": "i4"},
156-
),
157-
(
158-
b64(np.array([-900000000, 900000000, 3], dtype="int32")),
159-
{"bdata": "ABdbygDppDUDAAAA", "dtype": "i4"},
160-
),
161-
(
162-
b64(np.array([32767, -32767, 3], dtype="int16")),
163-
{"bdata": "/38BgAMA", "dtype": "i2"},
164-
),
165-
(
166-
b64(np.array([127, -127, 3], dtype="int8")),
167-
{"bdata": "f4ED", "dtype": "i1"},
168-
),
169-
(
170-
b64(np.array([900000000, 2, 3], dtype="uint64")),
171-
{"bdata": "AOmkNQIAAAADAAAA", "dtype": "u4"},
172-
),
173-
(
174-
b64(np.array([900000000, 2, 3], dtype="uint32")),
175-
{"bdata": "AOmkNQIAAAADAAAA", "dtype": "u4"},
176-
),
177-
(
178-
b64(np.array([32767, 0, 3], dtype="uint16")),
179-
{"bdata": "/38AAAMA", "dtype": "u2"},
180-
),
181-
(
182-
b64(np.array([127, 2, 3], dtype="uint8")),
183-
{"bdata": "fwID", "dtype": "u1"},
184-
),
185-
]
186-
187-
188-
@pytest.mark.parametrize("val, expected", INT_BASE64_TEST_CASES)
189-
def test_acceptance_aok_base64(val, expected, validator_aok):
190-
assert np.array_equal(validator_aok.validate_coerce(val), expected)
191-
192-
193147
# ### Coerce ###
194148
# Coerced to general consistent numeric type
195149
@pytest.mark.parametrize(

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

-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from _plotly_utils.basevalidators import NumberValidator
55
import numpy as np
66
import pandas as pd
7-
from plotly.tests.b64 import b64
87

98
# Fixtures
109
# --------
@@ -109,14 +108,6 @@ def test_acceptance_aok_list(val, validator_aok):
109108
)
110109

111110

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-
120111
# ### Coerce ###
121112
# Coerced to general consistent numeric type
122113
@pytest.mark.parametrize(

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

+4-8
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
ColorValidator,
1010
)
1111

12-
from plotly.tests.b64 import _b64
13-
1412

1513
@pytest.fixture
1614
def data_array_validator(request):
@@ -93,7 +91,7 @@ def test_numeric_validator_numeric_pandas(number_validator, numeric_pandas):
9391
res = number_validator.validate_coerce(numeric_pandas)
9492

9593
# Check type
96-
assert isinstance(res, object)
94+
assert isinstance(res, np.ndarray)
9795

9896
# Check dtype
9997
assert res.dtype == numeric_pandas.dtype
@@ -106,7 +104,7 @@ def test_integer_validator_numeric_pandas(integer_validator, numeric_pandas):
106104
res = integer_validator.validate_coerce(numeric_pandas)
107105

108106
# Check type
109-
assert isinstance(res, object)
107+
assert isinstance(res, np.ndarray)
110108

111109
# Check dtype
112110
if numeric_pandas.dtype.kind in ("u", "i"):
@@ -124,12 +122,10 @@ def test_data_array_validator(data_array_validator, numeric_pandas):
124122
res = data_array_validator.validate_coerce(numeric_pandas)
125123

126124
# Check type
127-
assert isinstance(res, object)
128-
129-
numeric_pandas = _b64(numeric_pandas)
125+
assert isinstance(res, np.ndarray)
130126

131127
# Check dtype
132-
assert res["dtype"] == numeric_pandas["dtype"]
128+
assert res.dtype == numeric_pandas.dtype
133129

134130
# Check values
135131
np.testing.assert_array_equal(res, numeric_pandas)

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

-13
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from _plotly_utils.basevalidators import StringValidator
44
import numpy as np
55

6-
from plotly.tests.b64 import b64
7-
86

97
# Fixtures
108
# --------
@@ -147,17 +145,6 @@ def test_acceptance_aok_list(val, validator_aok):
147145
assert coerce_val == val
148146

149147

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"]))
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-
161148
# ### Rejection by type ###
162149
@pytest.mark.parametrize("val", [["foo", ()], ["foo", 3, 4], [3, 2, 1]])
163150
def test_rejection_aok(val, validator_aok_strict):

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
ColorValidator,
1010
)
1111

12-
from plotly.tests.b64 import _b64
13-
1412

1513
@pytest.fixture
1614
def data_array_validator(request):
@@ -101,12 +99,10 @@ def test_data_array_validator(data_array_validator, numeric_xarray):
10199
res = data_array_validator.validate_coerce(numeric_xarray)
102100

103101
# Check type
104-
assert isinstance(res, object)
105-
106-
numeric_xarray = _b64(numeric_xarray)
102+
assert isinstance(res, np.ndarray)
107103

108104
# Check dtype
109-
assert res["dtype"] == numeric_xarray["dtype"]
105+
assert res.dtype == numeric_xarray.dtype
110106

111107
# Check values
112108
np.testing.assert_array_equal(res, numeric_xarray)

0 commit comments

Comments
 (0)