Debian Codegraph @

tests/validators/test_validator_number.py

raw symbols SCIP
1 import pytest
2
3 from cyclopts.validators import Number
4
5
6 def test_validator_number_type():
7 validator = Number()
8 with pytest.raises(TypeError):
9 validator(int, "this is a string.") # pyright: ignore[reportArgumentType]
10
11
12 def test_validator_number_lt():
13 validator = Number(lt=5)
14 validator(int, 0)
15
16 with pytest.raises(ValueError):
17 validator(int, 5)
18
19 with pytest.raises(ValueError):
20 validator(int, 6)
21
22
23 def test_validator_number_lt_sequence():
24 validator = Number(lt=5)
25 validator(int, (0, 0, 0))
26 validator(int, (0, 0, (1, 2)))
27
28 with pytest.raises(ValueError):
29 validator(int, 5)
30
31 with pytest.raises(ValueError):
32 validator(int, 6)
33
34 with pytest.raises(ValueError):
35 validator(int, (0, 0, 6))
36
37 with pytest.raises(ValueError):
38 validator(int, (0, 0, (1, 6)))
39
40
41 def test_validator_number_lte():
42 validator = Number(lte=5)
43 validator(int, 0)
44 validator(int, 5)
45
46 with pytest.raises(ValueError):
47 validator(int, 6)
48
49
50 def test_validator_number_gt():
51 validator = Number(gt=5)
52 validator(int, 10)
53
54 with pytest.raises(ValueError):
55 validator(int, 5)
56
57 with pytest.raises(ValueError):
58 validator(int, 4)
59
60
61 def test_validator_number_gte():
62 validator = Number(gte=5)
63 validator(int, 10)
64 validator(int, 5)
65
66 with pytest.raises(ValueError):
67 validator(int, 4)
68
69
70 def test_validator_number_modulo():
71 validator = Number(modulo=4)
72 validator(int, 8)
73 validator(float, 8.0)
74 with pytest.raises(ValueError):
75 validator(int, 9)
76
77
78 def test_validator_number_typeerror():
79 validator = Number(gte=5)
80 with pytest.raises(TypeError):
81 validator(str, "foo") # pyright: ignore[reportArgumentType]