-
Notifications
You must be signed in to change notification settings - Fork 0
/
testexamples.py
91 lines (73 loc) · 2.26 KB
/
testexamples.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
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
82
83
84
85
86
87
88
89
90
91
"""
testexamples is the file containing both project examples
and the data for the test suite.
"""
from doolally import (
Schema,
StaticTypeArray,
StaticTypeObject,
Union,
Number,
String,
Bool,
StringEnum,
IntegerEnum,
union_with_null,
AnyAtomic,
AnyCollection,
Any,
)
## Animals
CAT_BREEDS = ["Sphynx", "Abyssinian", "Burmese"]
DOG_BREEDS = ["Labrador", "German Shepherd", "Boxer Terrier"]
class Animal(Schema):
name = String(required=True,
description="The name of the animal")
age = Number(required=True, is_int=True, signed=False,
description="The age of the animal in human years")
class Cat(Animal):
doolally_description = "Cat represents a common housecat"
breed = StringEnum(required=True,
whitelist=CAT_BREEDS,
description="Breed of the cat")
class Dog(Animal):
doolally_description = "Dog is a pet dog"
breed = StringEnum(required=True,
whitelist=DOG_BREEDS,
description="Breed of the dog")
class AnimalPerson(Schema):
# A person optionally may have a pet
# they can have a dog or a cat, but not both
pet = Union(required=False,
element_fields=[Dog(), Cat()])
class EmailAddr(Schema):
# Which provider is the email?
# This is either a string, or null if not known
provider = union_with_null(required=True,
element_fields=[String()])
class Numbers(Schema):
NUMBERS = [
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
*map(lambda x: str(x), range(1, 11)),
]
numbers = StaticTypeArray(required=False,
element_field=Union(
element_fields=[
StringEnum(whitelist=NUMBERS),
Number(),
],
))
latitude = Number(required=False,
min_value=0,
max_value=90,
is_int=False,
description="latitude on the earth")