Tidy accommodation validation
This commit is contained in:
parent
ef624f83dd
commit
aec1d0e140
|
@ -57,31 +57,25 @@ def check_events() -> None:
|
||||||
print(len(events), "events")
|
print(len(events), "events")
|
||||||
|
|
||||||
|
|
||||||
|
def check_coordinates(item: agenda.types.StrDict) -> None:
|
||||||
|
"""Check coordinate are valid."""
|
||||||
|
if "latitude" not in item and "longitude" not in item:
|
||||||
|
return
|
||||||
|
assert "latitude" in item and "longitude" in item
|
||||||
|
assert all(isinstance(item[key], (int, float)) for key in ("latitude", "longitude"))
|
||||||
|
|
||||||
|
|
||||||
def check_accommodation() -> None:
|
def check_accommodation() -> None:
|
||||||
"""Check accommodation."""
|
"""Check accommodation."""
|
||||||
filepath = os.path.join(data_dir, "accommodation.yaml")
|
filepath = os.path.join(data_dir, "accommodation.yaml")
|
||||||
accommodation_list = yaml.safe_load(open(filepath))
|
accommodation_list = yaml.safe_load(open(filepath))
|
||||||
|
|
||||||
|
required_fields = ["type", "name", "country", "location", "trip", "from", "to"]
|
||||||
|
|
||||||
for stay in accommodation_list:
|
for stay in accommodation_list:
|
||||||
try:
|
try:
|
||||||
assert all(
|
assert all(field in stay for field in required_fields)
|
||||||
field in stay
|
check_coordinates(stay)
|
||||||
for field in (
|
|
||||||
"type",
|
|
||||||
"name",
|
|
||||||
"country",
|
|
||||||
"location",
|
|
||||||
"trip",
|
|
||||||
"from",
|
|
||||||
"to",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if "latitude" in stay or "longitude" in stay:
|
|
||||||
assert "latitude" in stay and "longitude" in stay
|
|
||||||
assert all(
|
|
||||||
isinstance(stay[key], (int, float))
|
|
||||||
for key in ("latitude", "longitude")
|
|
||||||
)
|
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
pprint(stay)
|
pprint(stay)
|
||||||
raise
|
raise
|
||||||
|
|
Loading…
Reference in a new issue