File: test_subplotid_validator.py

package info (click to toggle)
plotly 5.4.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 90,200 kB
  • sloc: python: 368,793; javascript: 213,159; sh: 49; makefile: 4
file content (43 lines) | stat: -rw-r--r-- 1,136 bytes parent folder | download
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
import pytest
from _plotly_utils.basevalidators import SubplotidValidator
import numpy as np


# Fixtures
# --------
@pytest.fixture()
def validator():
    return SubplotidValidator("prop", "parent", dflt="geo")


# Tests
# -----
# ### Acceptance ###
@pytest.mark.parametrize("val", ["geo"] + ["geo%d" % i for i in range(2, 10)])
def test_acceptance(val, validator):
    assert validator.validate_coerce(val) == val


# ### Rejection by type ###
@pytest.mark.parametrize("val", [23, [], {}, set(), np.inf, np.nan])
def test_rejection_type(val, validator):
    with pytest.raises(ValueError) as validation_failure:
        validator.validate_coerce(val)

    assert "Invalid value" in str(validation_failure.value)


# ### Rejection by value ###
@pytest.mark.parametrize(
    "val",
    [
        "",  # Cannot be empty
        "bogus",  # Must begin with 'geo'
        "geo0",  # If followed by a number the number must be > 1
    ],
)
def test_rejection_value(val, validator):
    with pytest.raises(ValueError) as validation_failure:
        validator.validate_coerce(val)

    assert "Invalid value" in str(validation_failure.value)