File: test_boolean_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 (26 lines) | stat: -rw-r--r-- 728 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
import pytest
from _plotly_utils.basevalidators import BooleanValidator
import numpy as np


# Boolean Validator
# =================
# ### Fixtures ###
@pytest.fixture(params=[True, False])
def validator(request):
    return BooleanValidator("prop", "parent", dflt=request.param)


# ### Acceptance ###
@pytest.mark.parametrize("val", [True, False])
def test_acceptance(val, validator):
    assert val == validator.validate_coerce(val)


# ### Rejection ###
@pytest.mark.parametrize("val", [1.0, 0.0, "True", "False", [], 0, np.nan])
def test_rejection(val, validator):
    with pytest.raises(ValueError) as validation_failure:
        validator.validate_coerce(val)

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