More tests

This commit is contained in:
Edward Betts 2025-07-16 06:51:18 +02:00
parent 9dd033ba77
commit 3ad11b070a

View file

@ -1,4 +1,4 @@
from datetime import date, datetime, timedelta from datetime import date, datetime
import agenda.busy import agenda.busy
import agenda.travel as travel import agenda.travel as travel
@ -10,29 +10,32 @@ def test_get_location_for_date() -> None:
app.config["SERVER_NAME"] = "test" app.config["SERVER_NAME"] = "test"
with app.app_context(): with app.app_context():
today = datetime.now().date() today = datetime.now().date()
start = date(2023, 1, 1)
trips = agenda.trip.build_trip_list() trips = agenda.trip.build_trip_list()
data_dir = app.config["PERSONAL_DATA"]
busy_events = agenda.busy.get_busy_events(start, app.config, trips) data_dir = app.config["PERSONAL_DATA"]
weekends = agenda.busy.weekends(start, busy_events, trips, data_dir)
# Parse YAML files once for the test # Parse YAML files once for the test
bookings = travel.parse_yaml("flights", data_dir) bookings = travel.parse_yaml("flights", data_dir)
accommodations = travel.parse_yaml("accommodation", data_dir) accommodations = travel.parse_yaml("accommodation", data_dir)
airports = travel.parse_yaml("airports", data_dir) airports = travel.parse_yaml("airports", data_dir)
for weekend in weekends: for year in range(2023, 2025):
for day in "saturday", "sunday": start = date(2023, 1, 1)
assert weekend[day + "_location"][0] == "Bristol" or bool(weekend[day]) busy_events = agenda.busy.get_busy_events(start, app.config, trips)
weekends = agenda.busy.weekends(start, busy_events, trips, data_dir)
for weekend in weekends:
for day in "saturday", "sunday":
assert weekend[day + "_location"][0] == "Bristol" or bool(
weekend[day]
)
# Debug the April 29 issue # Debug the April 29 issue
april_29_location = agenda.busy.get_location_for_date( april_29_location = agenda.busy.get_location_for_date(
date(2023, 4, 29), trips, bookings, accommodations, airports date(2023, 4, 29), trips, bookings, accommodations, airports
) )
print(f"\nDirect call for April 29: {april_29_location}") print(f"\nDirect call for April 29: {april_29_location}")
# Check what the foss-north trip looks like # Check what the foss-north trip looks like
foss_north_trip = None foss_north_trip = None
for trip in trips: for trip in trips:
@ -71,6 +74,6 @@ def test_get_location_for_date() -> None:
date(2025, 8, 2), trips, bookings, accommodations, airports date(2025, 8, 2), trips, bookings, accommodations, airports
) )
assert l2[0] == "Bristol" assert l2[0] == "Bristol"
# Fix the April 29 case # Fix the April 29 case
assert april_29_location[0] == "Bristol" assert april_29_location[0] == "Bristol"