Use None in place of "Bristol" for home

Also fix some more location bugs.
This commit is contained in:
Edward Betts 2025-07-16 07:55:20 +02:00
parent eb65f720bf
commit 02350ef4db
3 changed files with 60 additions and 46 deletions

View file

@ -1,4 +1,4 @@
from datetime import date, datetime
from datetime import date, datetime, timedelta
import agenda.busy
import agenda.travel as travel
@ -26,54 +26,43 @@ def test_get_location_for_date() -> None:
for weekend in weekends:
for day in "saturday", "sunday":
assert weekend[day + "_location"][0] == "Bristol" or bool(
weekend[day]
)
# When free (no events), should be home (None)
# When traveling (events), should be away (City name)
assert bool(weekend[day + "_location"][0]) == bool(weekend[day])
# Debug the April 29 issue
# Test some specific cases
april_29_location = agenda.busy.get_location_for_date(
date(2023, 4, 29), trips, bookings, accommodations, airports
)
print(f"\nDirect call for April 29: {april_29_location}")
assert not april_29_location[0] # Should be home (None)
# Check what the foss-north trip looks like
foss_north_trip = None
for trip in trips:
if trip.title == "foss-north" and trip.start == date(2023, 4, 22):
foss_north_trip = trip
print(f"foss-north trip: {trip.start} to {trip.end}")
print(f"foss-north locations: {trip.locations()}")
break
l1 = agenda.busy.get_location_for_date(
l = agenda.busy.get_location_for_date(
date(2025, 2, 15), trips, bookings, accommodations, airports
)
assert l1[0] == "Hackettstown"
assert l[0] == "Hackettstown"
l2 = agenda.busy.get_location_for_date(
l = agenda.busy.get_location_for_date(
date(2025, 7, 1), trips, bookings, accommodations, airports
)
assert l2[0] == "Bristol"
assert not l[0]
l2 = agenda.busy.get_location_for_date(
l = agenda.busy.get_location_for_date(
date(2023, 12, 2), trips, bookings, accommodations, airports
)
assert l2[0] == "Bristol"
assert not l[0]
l2 = agenda.busy.get_location_for_date(
l = agenda.busy.get_location_for_date(
date(2023, 10, 7), trips, bookings, accommodations, airports
)
assert l2[0] == "Bristol"
assert not l[0]
l2 = agenda.busy.get_location_for_date(
l = agenda.busy.get_location_for_date(
date(2023, 2, 18), trips, bookings, accommodations, airports
)
assert l2[0] == "Bristol"
assert not l[0]
l2 = agenda.busy.get_location_for_date(
l = agenda.busy.get_location_for_date(
date(2025, 8, 2), trips, bookings, accommodations, airports
)
assert l2[0] == "Bristol"
assert not l[0]
# Fix the April 29 case
assert april_29_location[0] == "Bristol"