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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
import pytest
from cyclopts.validators import Number
def test_validator_number_type():
validator = Number()
with pytest.raises(TypeError):
validator(int, "this is a string.") # pyright: ignore[reportArgumentType]
def test_validator_number_lt():
validator = Number(lt=5)
validator(int, 0)
with pytest.raises(ValueError):
validator(int, 5)
with pytest.raises(ValueError):
validator(int, 6)
def test_validator_number_lt_sequence():
validator = Number(lt=5)
validator(int, (0, 0, 0))
validator(int, (0, 0, (1, 2)))
with pytest.raises(ValueError):
validator(int, 5)
with pytest.raises(ValueError):
validator(int, 6)
with pytest.raises(ValueError):
validator(int, (0, 0, 6))
with pytest.raises(ValueError):
validator(int, (0, 0, (1, 6)))
def test_validator_number_lte():
validator = Number(lte=5)
validator(int, 0)
validator(int, 5)
with pytest.raises(ValueError):
validator(int, 6)
def test_validator_number_gt():
validator = Number(gt=5)
validator(int, 10)
with pytest.raises(ValueError):
validator(int, 5)
with pytest.raises(ValueError):
validator(int, 4)
def test_validator_number_gte():
validator = Number(gte=5)
validator(int, 10)
validator(int, 5)
with pytest.raises(ValueError):
validator(int, 4)
def test_validator_number_modulo():
validator = Number(modulo=4)
validator(int, 8)
validator(float, 8.0)
with pytest.raises(ValueError):
validator(int, 9)
def test_validator_number_typeerror():
validator = Number(gte=5)
with pytest.raises(TypeError):
validator(str, "foo") # pyright: ignore[reportArgumentType]
|