Enhance YAML validation 🛠️: Add airline checks

Closes: #186
This commit is contained in:
Edward Betts 2024-10-22 21:19:11 +01:00
parent aec1d0e140
commit 38792a1721

View file

@ -29,10 +29,12 @@ def check_trips() -> None:
print(len(routes), "routes")
def check_flights() -> None:
def check_flights(airlines: set[str]) -> None:
"""Check flights."""
flights = agenda.travel.parse_yaml("flights", data_dir)
print(len(flights), "flights")
bookings = agenda.travel.parse_yaml("flights", data_dir)
for booking in bookings:
assert all(flight["airline"] in airlines for flight in booking["flights"])
print(len(bookings), "flights")
def check_trains() -> None:
@ -103,25 +105,29 @@ def check_stations() -> None:
assert agenda.get_country(station["country"])
def check_airlines() -> None:
def check_airlines() -> list[agenda.types.StrDict]:
"""Check airlines."""
airlines = agenda.travel.parse_yaml("airlines", data_dir)
print(len(airlines), "airlines")
for airline in airlines:
assert airline.keys() == {"icao", "iata", "name"}
assert len(airline["icao"]) == 3
assert len(airline["iata"]) == 2
return airlines
def check() -> None:
"""Validate personal data YAML files."""
airlines = check_airlines()
check_trips()
check_flights()
check_flights({airline["iata"] for airline in airlines})
check_trains()
check_conferences()
check_events()
check_accommodation()
check_airports()
check_stations()
check_airlines()
if __name__ == "__main__":