forked from core-api/python-coreschema
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_intersection.py
More file actions
32 lines (26 loc) · 1.05 KB
/
test_intersection.py
File metadata and controls
32 lines (26 loc) · 1.05 KB
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
from coreschema import Integer, String, Boolean
def test_intersection_of_types():
# validate will never succeed in this case.
schema = Integer() & String()
assert schema.validate('abc') == [('Must be an integer.', [])]
assert schema.validate(123) == [('Must be a string.', [])]
def test_intersection_of_intersections():
# validate will never succeed in this case.
schema = (Integer() & String()) & Boolean()
assert schema.validate('abc') == [
('Must be an integer.', []),
('Must be a boolean.', [])
]
assert schema.validate(123) == [
('Must be a string.', []),
('Must be a boolean.', [])
]
def test_intersection_of_type_restrictions():
schema = Integer(multiple_of=3) & Integer(multiple_of=5)
assert schema.validate(2) == [
('Must be a multiple of 3.', []),
('Must be a multiple of 5.', [])
]
assert schema.validate(3) == [('Must be a multiple of 5.', [])]
assert schema.validate(5) == [('Must be a multiple of 3.', [])]
assert schema.validate(15) == []