Skip to content

Commit

Permalink
Revert changes to validator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marthacryan committed Oct 15, 2024
1 parent de2bcb5 commit 0d0dad2
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# from ..basevalidators import AngleValidator
from _plotly_utils.basevalidators import AngleValidator
import numpy as np
from plotly.tests.b64 import b64


# Fixtures
Expand Down Expand Up @@ -52,14 +51,6 @@ def test_aok_acceptance(val, validator_aok):
assert np.array_equal(validator_aok.validate_coerce(np.array(val)), np.array(val))


# Test base64 array
def test_aok_base64_array(validator_aok):
val = b64(np.array([1, 2, 3], dtype="int64"))
coerce_val = validator_aok.validate_coerce(val)
assert coerce_val["bdata"] == "AQID"
assert coerce_val["dtype"] == "i1"


# ### Test coercion above 180 ###
@pytest.mark.parametrize(
"val,expected",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from _plotly_utils.basevalidators import AnyValidator
import numpy as np
from plotly.tests.b64 import b64


# Fixtures
Expand Down Expand Up @@ -50,10 +49,3 @@ def test_acceptance_array(val, validator_aok):
else:
assert coerce_val == val
assert validator_aok.present(coerce_val) == val


def test_base64_array(validator_aok):
val = b64(np.array([1, 2, 3], dtype="int64"))
coerce_val = validator_aok.validate_coerce(val)
assert coerce_val["bdata"] == "AQID"
assert coerce_val["dtype"] == "i1"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from _plotly_utils.basevalidators import BaseDataValidator
from plotly.graph_objs import Scatter, Bar, Box
import numpy as np


# Fixtures
# --------
Expand Down Expand Up @@ -118,19 +118,6 @@ def test_rejection_element_tracetype(validator):
assert "Invalid element(s)" in str(validation_failure.value)


def test_b64(validator):
val = [dict(type="scatter", x=np.array([1, 2, 3]))]
res = validator.validate_coerce(val)
res_present = validator.present(res)

assert isinstance(res, list)
assert isinstance(res_present, tuple)

assert isinstance(res_present[0], Scatter)
assert res_present[0].type == "scatter"
assert res_present[0].x == {"bdata": "AQID", "dtype": "i1"}


def test_skip_invalid(validator_nouid):
val = (
dict(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from _plotly_utils.basevalidators import ColorValidator
import numpy as np
from plotly.tests.b64 import b64


# Fixtures
Expand Down Expand Up @@ -132,19 +131,6 @@ def test_acceptance_aok(val, validator_aok):
assert coerce_val == val


# Test that it doesn't use a base64 array
# Numpy v2 has a StrDType but we don't want to convert it yet.
# Change this test if you add support for it.
def test_acceptance_aok_base64_array(validator_aok):
val = b64(np.array(["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure"]))
coerce_val = validator_aok.validate_coerce(val)
assert coerce_val[0] == "aliceblue"
assert coerce_val[1] == "antiquewhite"
assert coerce_val[2] == "aqua"
assert coerce_val[3] == "aquamarine"
assert coerce_val[4] == "azure"


@pytest.mark.parametrize(
"val",
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np

from _plotly_utils.basevalidators import ColorlistValidator
from plotly.tests.b64 import b64


# Fixtures
# --------
Expand Down Expand Up @@ -48,13 +48,3 @@ def test_acceptance_aok(val, validator):
coerce_val = validator.validate_coerce(val)
assert isinstance(coerce_val, list)
assert validator.present(coerce_val) == tuple(val)


# Test that it doesn't use a base64 array
# Numpy v2 has a StrDType but we don't want to convert it yet.
# Change this test if you add support for it.
def test_acceptance_b64_aok(validator):
val = b64(np.array(["red", "rgb(255, 0, 0)"]))
coerce_val = validator.validate_coerce(val)
assert coerce_val[0] == "red"
assert coerce_val[1] == "rgb(255, 0, 0)"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from _plotly_utils.basevalidators import CompoundArrayValidator
from plotly.graph_objs.layout import Image


# Fixtures
# --------
@pytest.fixture()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from _plotly_utils.basevalidators import DataArrayValidator
import numpy as np
import pandas as pd
from plotly.tests.b64 import b64

# Fixtures
# --------
Expand Down Expand Up @@ -34,22 +33,12 @@ def test_validator_acceptance_simple(val, validator):

@pytest.mark.parametrize(
"val",
[pd.Series(["a", "b", "c"])],
[np.array([2, 3, 4]), pd.Series(["a", "b", "c"]), np.array([[1, 2, 3], [4, 5, 6]])],
)
def test_validator_acceptance_homogeneous(val, validator):
coerce_val = validator.validate_coerce(val)
assert isinstance(coerce_val, np.ndarray)
assert np.array_equal(validator.present(coerce_val), b64(val))


@pytest.mark.parametrize(
"val",
[np.array([2, 3, 4]), np.array([[1, 2, 3], [4, 5, 6]])],
)
def test_validator_acceptance_homogeneous(val, validator):
coerce_val = validator.validate_coerce(val)
assert isinstance(coerce_val, object)
assert np.array_equal(validator.present(coerce_val), b64(val))
assert np.array_equal(validator.present(coerce_val), val)


# ### Rejection ###
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import numpy as np
import pandas as pd
from _plotly_utils.basevalidators import EnumeratedValidator
from plotly.tests.b64 import b64


# Fixtures
Expand Down Expand Up @@ -95,14 +94,6 @@ def test_acceptance_aok(val, validator_aok):
assert coerce_val == val


# Test base64 array
def test_aok_base64_array(validator_aok):
val = b64(np.array([1, 2, 3], dtype="int64"))
coerce_val = validator_aok.validate_coerce(val)
assert coerce_val["bdata"] == "AQID"
assert coerce_val["dtype"] == "i1"


# ### Rejection by value ###
@pytest.mark.parametrize("val", [True, 0, 1, 23, np.inf, set()])
def test_rejection_by_value_aok(val, validator_aok):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
from _plotly_utils.basevalidators import FlaglistValidator
import numpy as np
from plotly.tests.b64 import b64


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


# Test base64 array
def test_acceptance_aok_scalar_base64(validator_extra_aok):
val = b64(np.array([1, 2, 3], dtype="int64"))
coerce_val = validator_extra_aok.validate_coerce(val)
assert coerce_val["bdata"] == "AQID"
assert coerce_val["dtype"] == "i1"


# ### Acceptance (lists) ###
def test_acceptance_aok_scalarlist_flaglist(flaglist, validator_extra_aok):
assert np.array_equal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest
from pytest import approx
from _plotly_utils.basevalidators import IntegerValidator
from plotly.tests.b64 import b64
import numpy as np
import pandas as pd

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


# Test base64 encoded arrays with array_ok=True
INT_BASE64_TEST_CASES = [
# Note: we decided not to support int64 in plotly.js,
# so the the max / min value are limited to int32 and the
# dtype is cast to int32 in the output
(
b64(np.array([-900000000, 900000000, 3], dtype="int64")),
{"bdata": "ABdbygDppDUDAAAA", "dtype": "i4"},
),
(
b64(np.array([-900000000, 900000000, 3], dtype="int32")),
{"bdata": "ABdbygDppDUDAAAA", "dtype": "i4"},
),
(
b64(np.array([32767, -32767, 3], dtype="int16")),
{"bdata": "/38BgAMA", "dtype": "i2"},
),
(
b64(np.array([127, -127, 3], dtype="int8")),
{"bdata": "f4ED", "dtype": "i1"},
),
(
b64(np.array([900000000, 2, 3], dtype="uint64")),
{"bdata": "AOmkNQIAAAADAAAA", "dtype": "u4"},
),
(
b64(np.array([900000000, 2, 3], dtype="uint32")),
{"bdata": "AOmkNQIAAAADAAAA", "dtype": "u4"},
),
(
b64(np.array([32767, 0, 3], dtype="uint16")),
{"bdata": "/38AAAMA", "dtype": "u2"},
),
(
b64(np.array([127, 2, 3], dtype="uint8")),
{"bdata": "fwID", "dtype": "u1"},
),
]


@pytest.mark.parametrize("val, expected", INT_BASE64_TEST_CASES)
def test_acceptance_aok_base64(val, expected, validator_aok):
assert np.array_equal(validator_aok.validate_coerce(val), expected)


# ### Coerce ###
# Coerced to general consistent numeric type
@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from _plotly_utils.basevalidators import NumberValidator
import numpy as np
import pandas as pd
from plotly.tests.b64 import b64

# Fixtures
# --------
Expand Down Expand Up @@ -109,14 +108,6 @@ def test_acceptance_aok_list(val, validator_aok):
)


# Test base64 array
def test_acceptance_aok_base64(validator_aok):
val = b64(np.array([1, 2, 3], dtype="int64"))
coerce_val = validator_aok.validate_coerce(val)
assert coerce_val["bdata"] == "AQID"
assert coerce_val["dtype"] == "i1"


# ### Coerce ###
# Coerced to general consistent numeric type
@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
ColorValidator,
)

from plotly.tests.b64 import _b64


@pytest.fixture
def data_array_validator(request):
Expand Down Expand Up @@ -93,7 +91,7 @@ def test_numeric_validator_numeric_pandas(number_validator, numeric_pandas):
res = number_validator.validate_coerce(numeric_pandas)

# Check type
assert isinstance(res, object)
assert isinstance(res, np.ndarray)

# Check dtype
assert res.dtype == numeric_pandas.dtype
Expand All @@ -106,7 +104,7 @@ def test_integer_validator_numeric_pandas(integer_validator, numeric_pandas):
res = integer_validator.validate_coerce(numeric_pandas)

# Check type
assert isinstance(res, object)
assert isinstance(res, np.ndarray)

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

# Check type
assert isinstance(res, object)

numeric_pandas = _b64(numeric_pandas)
assert isinstance(res, np.ndarray)

# Check dtype
assert res["dtype"] == numeric_pandas["dtype"]
assert res.dtype == numeric_pandas.dtype

# Check values
np.testing.assert_array_equal(res, numeric_pandas)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from _plotly_utils.basevalidators import StringValidator
import numpy as np

from plotly.tests.b64 import b64


# Fixtures
# --------
Expand Down Expand Up @@ -147,17 +145,6 @@ def test_acceptance_aok_list(val, validator_aok):
assert coerce_val == val


# Test that it doesn't use a base64 array
# Numpy v2 has a StrDType but we don't want to convert it yet.
# Change this test if you add support for it.
def test_aok_base64_array(validator_aok):
val = b64(np.array(["a", "b", "c"]))
coerce_val = validator_aok.validate_coerce(val)
assert coerce_val[0] == "a"
assert coerce_val[1] == "b"
assert coerce_val[2] == "c"


# ### Rejection by type ###
@pytest.mark.parametrize("val", [["foo", ()], ["foo", 3, 4], [3, 2, 1]])
def test_rejection_aok(val, validator_aok_strict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
ColorValidator,
)

from plotly.tests.b64 import _b64


@pytest.fixture
def data_array_validator(request):
Expand Down Expand Up @@ -101,12 +99,10 @@ def test_data_array_validator(data_array_validator, numeric_xarray):
res = data_array_validator.validate_coerce(numeric_xarray)

# Check type
assert isinstance(res, object)

numeric_xarray = _b64(numeric_xarray)
assert isinstance(res, np.ndarray)

# Check dtype
assert res["dtype"] == numeric_xarray["dtype"]
assert res.dtype == numeric_xarray.dtype

# Check values
np.testing.assert_array_equal(res, numeric_xarray)
Expand Down

0 comments on commit 0d0dad2

Please sign in to comment.