From 38792a1721dc11b907180adaa3cc5b9d1d87a769 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Tue, 22 Oct 2024 21:19:11 +0100 Subject: [PATCH] =?UTF-8?q?Enhance=20YAML=20validation=20=F0=9F=9B=A0?= =?UTF-8?q?=EF=B8=8F:=20Add=20airline=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes: #186 --- validate_yaml.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/validate_yaml.py b/validate_yaml.py index 4b01804..68df0f9 100755 --- a/validate_yaml.py +++ b/validate_yaml.py @@ -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__":