-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrecursive.py
More file actions
63 lines (50 loc) · 1.38 KB
/
Copy pathrecursive.py
File metadata and controls
63 lines (50 loc) · 1.38 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
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
from simple_schema_validator import schema_validator, types
def validate(schema, data):
validation = schema_validator(schema, data)
if not validation:
print(f'Keys in data, but not in schema: {validation.additional_keys}')
print(f'Keys in schema, but not in data: {validation.missing_keys}')
print(f'Keys with different type from schema {validation.type_errors}')
else:
print('Valid.')
def main():
data_1 = {
'type': 'chat',
'message': [{
'title': 'Graduation',
'content': 'Hello there!',
'urgency': None
}]
}
data_2 = {
'type': 'data',
'message': [{
'title': 'Survey',
'content': 'N people answered your survey',
'urgency': 'very urgent'
}]
}
data_3 = {
'type': 'chat',
'message': [{
'title': 'Some titile',
'content': 'Hello there!',
'urgency': 1
}]
}
schema = {
'type': str,
'message': [{
'title': str,
'content': str,
'urgency': types.Optional[str]
}]
}
print('Validating data_1 ...')
validate(schema, data_1)
print('Validating data_2 ...')
validate(schema, data_2)
print('Validating data_3 ...')
validate(schema, data_3)
if __name__ == '__main__':
main()