Tidy accommodation validation

This commit is contained in:
Edward Betts 2024-10-22 18:55:57 +01:00
parent ef624f83dd
commit aec1d0e140

View file

@ -57,31 +57,25 @@ def check_events() -> None:
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:
"""Check accommodation."""
filepath = os.path.join(data_dir, "accommodation.yaml")
accommodation_list = yaml.safe_load(open(filepath))
required_fields = ["type", "name", "country", "location", "trip", "from", "to"]
for stay in accommodation_list:
try:
assert all(
field in 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")
)
assert all(field in stay for field in required_fields)
check_coordinates(stay)
except AssertionError:
pprint(stay)
raise