Add car journeys to trips

This commit is contained in:
Edward Betts 2026-07-08 09:09:48 +01:00
parent bc7a2e89d0
commit c6cb06b71e
9 changed files with 430 additions and 10 deletions

View file

@ -1,5 +1,7 @@
"""Tests for trip map coordinate assembly."""
import json
import pathlib
from datetime import date
import agenda.trip
@ -167,3 +169,72 @@ def test_get_trip_routes_assumes_unbooked_paris_trip_is_by_train(
"geojson_filename": "train_routes/London_St_Pancras_to_Paris_Gare_du_Nord",
}
]
def test_load_cars_infers_route_labels_and_home_marker(tmp_path: pathlib.Path) -> None:
"""Car journeys should load direct GeoJSON routes and endpoint markers."""
(tmp_path / "car_routes").mkdir()
(tmp_path / "car_journeys.yaml").write_text("""---
- trip: 2026-07-16
depart: 2026-07-16
arrive: 2026-07-16
route: PCH_to_EMF.geojson
""")
(tmp_path / "car_routes" / "PCH_to_EMF.geojson").write_text(
json.dumps(
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [[-2.60283, 51.44083], [-1.2, 52.0]],
},
}
)
)
cars = agenda.trip.load_cars(str(tmp_path))
assert len(cars) == 1
assert cars[0]["type"] == "car"
assert cars[0]["from"] == "PCH"
assert cars[0]["to"] == "EMF"
assert cars[0]["geojson_filename"] == "PCH_to_EMF"
assert cars[0]["distance"] > 0
assert cars[0]["from_location"] == {
"name": "PCH",
"type": "home",
"latitude": 51.44083,
"longitude": -2.60283,
}
assert cars[0]["to_location"] == {
"name": "EMF",
"type": "car_stop",
"latitude": 52.0,
"longitude": -1.2,
}
def test_get_trip_routes_includes_car_geojson() -> None:
"""Car routes should render from the car_routes directory."""
trip = Trip(
start=date(2026, 7, 16),
travel=[
{
"type": "car",
"from": "PCH",
"to": "EMF",
"geojson_filename": "PCH_to_EMF",
}
],
)
routes = agenda.trip.get_trip_routes(trip, "/tmp/personal-data")
assert routes == [
{
"type": "car",
"key": "car_PCH_EMF_PCH_to_EMF",
"geojson_filename": "car_routes/PCH_to_EMF",
}
]