-
Notifications
You must be signed in to change notification settings - Fork 1
/
validate.py
executable file
·48 lines (34 loc) · 1.42 KB
/
validate.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
#!venv/bin/python
import json
def check_whitespace(container, key):
value = container[key]
assert value == value.strip(), (f"Invalid {key}: <{value}>", container)
def validate_details(details):
assert 4 <= len(details) <= 5, details
assert details["page"] is not None, ("Null page", details)
assert isinstance(details["page"], int), ("Page isn't a number", details)
assert details["page"] > 0, ("Invalid page", details)
def do_validate(attribute):
check_whitespace(details, attribute)
assert len(details[attribute]) > 0, ("Empty " + attribute, details)
if "character" in details:
do_validate("character")
for each in ("issue", "publication", "title"):
assert details[each] is not None
do_validate(each)
publication = details["publication"]
assert publication in ("aku ankan taskukirja", "aku ankka"), publication
def validate(epithet, details):
assert epithet is not None
assert epithet == epithet.strip(), "Epithet has blanks: " + epithet
assert len(epithet) > 0, ("Epithet is empty", details)
assert details is not None
for each in details:
validate_details(each)
def validate_main_json():
with open("epithets.json", encoding="utf-8") as filep:
epithets = json.load(filep)["epithets"]
for epithet, details in epithets.items():
validate(epithet, details)
if __name__ == "__main__":
validate_main_json()