-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboolean_test.py
36 lines (27 loc) · 1.03 KB
/
boolean_test.py
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
import pytest
import zon
@pytest.fixture
def validator():
return zon.boolean()
def test_boolean_validate(validator):
assert validator.validate(True)
assert not validator.validate(False)
with pytest.raises(zon.error.ZonError):
validator.validate("1")
with pytest.raises(zon.error.ZonError):
validator.validate([1])
with pytest.raises(zon.error.ZonError):
validator.validate({"a": 1})
with pytest.raises(zon.error.ZonError):
validator.validate(1)
with pytest.raises(zon.error.ZonError):
validator.validate(1.5)
def test_boolean_safe_validate(validator):
assert validator.safe_validate(True) == (True, True)
assert validator.safe_validate(False) == (True, False)
# TODO: check for the specific error?
assert validator.safe_validate("1")[0] is False
assert validator.safe_validate([1])[0] is False
assert validator.safe_validate({"a": 1})[0] is False
assert validator.safe_validate(1)[0] is False
assert validator.safe_validate(1.5)[0] is False