diff --git a/validate_yaml.py b/validate_yaml.py index 4533034..4b01804 100755 --- a/validate_yaml.py +++ b/validate_yaml.py @@ -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