Add train and ferry support to location tracking
- Add helper functions for train and ferry location extraction - Update get_location_for_date to consider trains and ferries alongside flights - Parse stations.yaml and ferry_terminals.yaml for location data - Handle UK vs international locations consistently for all transport modes - Add comprehensive tests for new train and ferry location helpers - Format code with black for consistent style Now tracks complete travel history including flights, trains, ferries, and accommodation for accurate location determination. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
f89d984623
commit
e370049bcb
2 changed files with 302 additions and 6 deletions
|
|
@ -178,6 +178,68 @@ def test_parse_datetime_field():
|
|||
assert parsed_dt.day == 1
|
||||
|
||||
|
||||
def test_train_location_helpers():
|
||||
"""Test the train location helper functions."""
|
||||
from agenda.busy import _get_train_location
|
||||
|
||||
# Mock station data
|
||||
stations = [
|
||||
{"name": "London St Pancras", "country": "gb"},
|
||||
{"name": "Brussels Midi", "country": "be"},
|
||||
{"name": "Edinburgh Waverley", "country": "gb"},
|
||||
]
|
||||
|
||||
# Test UK station when not on trip (should return None for home)
|
||||
train_leg = {"to": "London St Pancras"}
|
||||
location = _get_train_location(train_leg, stations, on_trip=False)
|
||||
assert location[0] is None # Should be home
|
||||
assert location[1].alpha_2 == "GB"
|
||||
|
||||
# Test UK station when on trip (should return city name)
|
||||
location = _get_train_location(train_leg, stations, on_trip=True)
|
||||
assert location[0] == "London St Pancras"
|
||||
assert location[1].alpha_2 == "GB"
|
||||
|
||||
# Test non-UK station
|
||||
train_leg = {"to": "Brussels Midi"}
|
||||
location = _get_train_location(train_leg, stations, on_trip=False)
|
||||
assert location[0] == "Brussels Midi"
|
||||
assert location[1].alpha_2 == "BE"
|
||||
|
||||
|
||||
def test_ferry_location_helpers():
|
||||
"""Test the ferry location helper functions."""
|
||||
from agenda.busy import _get_ferry_location
|
||||
|
||||
# Mock terminal data
|
||||
terminals = [
|
||||
{"name": "Dover Eastern Docks", "country": "gb", "city": "Dover"},
|
||||
{"name": "Calais Ferry Terminal", "country": "fr", "city": "Calais"},
|
||||
{
|
||||
"name": "Portsmouth Continental Terminal",
|
||||
"country": "gb",
|
||||
"city": "Portsmouth",
|
||||
},
|
||||
]
|
||||
|
||||
# Test UK terminal when not on trip (should return None for home)
|
||||
ferry = {"to": "Dover Eastern Docks"}
|
||||
location = _get_ferry_location(ferry, terminals, on_trip=False)
|
||||
assert location[0] is None # Should be home
|
||||
assert location[1].alpha_2 == "GB"
|
||||
|
||||
# Test UK terminal when on trip (should return city name)
|
||||
location = _get_ferry_location(ferry, terminals, on_trip=True)
|
||||
assert location[0] == "Dover"
|
||||
assert location[1].alpha_2 == "GB"
|
||||
|
||||
# Test non-UK terminal
|
||||
ferry = {"to": "Calais Ferry Terminal"}
|
||||
location = _get_ferry_location(ferry, terminals, on_trip=False)
|
||||
assert location[0] == "Calais"
|
||||
assert location[1].alpha_2 == "FR"
|
||||
|
||||
|
||||
def test_get_busy_events(app_context, trips):
|
||||
"""Test get_busy_events function."""
|
||||
start_date = date(2023, 1, 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue