File: test_literal_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 (27 lines) | stat: -rw-r--r-- 669 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
import pytest
from _plotly_utils.basevalidators import LiteralValidator
import numpy as np


# Fixtures
# --------
@pytest.fixture()
def validator():
    return LiteralValidator("prop", "parent", "scatter")


# Tests
# -----
# ### Acceptance ###
@pytest.mark.parametrize("val", ["scatter"])
def test_acceptance(val, validator):
    assert validator.validate_coerce(val) is val


# ### Test rejection ###
@pytest.mark.parametrize("val", ["hello", (), [], [1, 2, 3], set(), "34"])
def test_rejection(val, validator):
    with pytest.raises(ValueError) as validation_failure:
        validator.validate_coerce(val)

    assert "read-only" in str(validation_failure.value)