Initial commit - Trekker V2 source
This commit is contained in:
commit
d71faf19e3
65 files changed
+3615
No files matched your search
@@ -0,0 +1,67 @@
|
||||
import pytest
|
||||
|
||||
from app.generators import GENERATORS
|
||||
from app.generators.base import GeneratorError
|
||||
from app.generators.elevation_map import grade_color
|
||||
from app.generators.trail_card import TrailCardGenerator
|
||||
from app.generators.weather_overlay import WeatherOverlayGenerator
|
||||
from app.ingest.gpx_parser import parse_gpx
|
||||
from app.models.trail_guide import TrailGuide
|
||||
|
||||
WEATHER = {
|
||||
"days": 7,
|
||||
"segments": {
|
||||
"0": {"daily": [{"date": "2026-06-10", "temp_min_f": 60, "temp_max_f": 85,
|
||||
"precip_prob_max": 70, "precip_sum_in": 0.4,
|
||||
"wind_max_kmh": 45, "lightning_risk": True}]},
|
||||
"1": {"daily": [{"date": "2026-06-10", "temp_min_f": 60, "temp_max_f": 85,
|
||||
"precip_prob_max": 10, "precip_sum_in": 0.0,
|
||||
"wind_max_kmh": 10, "lightning_risk": False}]},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_registry_names():
|
||||
assert set(GENERATORS) == {"trail_card", "elevation_map", "weather_overlay"}
|
||||
|
||||
|
||||
def test_trail_card_degrades_without_guide(fixtures):
|
||||
route = parse_gpx((fixtures / "gaia.gpx").read_bytes())
|
||||
asset = TrailCardGenerator().generate(route, None, None)
|
||||
assert asset.data["guide"] is None
|
||||
assert len(asset.data["segments"]) == 2
|
||||
assert asset.data["segments"][0]["weather_today"] is None
|
||||
|
||||
|
||||
def test_trail_card_with_guide_and_weather(fixtures):
|
||||
route = parse_gpx((fixtures / "gaia.gpx").read_bytes())
|
||||
guide = TrailGuide(name="WG", difficulty="difficult", gate_codes=["1234"])
|
||||
asset = TrailCardGenerator().generate(route, guide, WEATHER)
|
||||
assert asset.data["guide"]["gate_codes"] == ["1234"]
|
||||
assert asset.data["segments"][0]["difficulty"] == "difficult"
|
||||
assert asset.data["segments"][0]["weather_today"]["precip_prob_max"] == 70
|
||||
|
||||
|
||||
def test_weather_overlay_requires_weather(fixtures):
|
||||
route = parse_gpx((fixtures / "gaia.gpx").read_bytes())
|
||||
with pytest.raises(GeneratorError):
|
||||
WeatherOverlayGenerator().generate(route, None, None)
|
||||
asset = WeatherOverlayGenerator().generate(route, None, WEATHER)
|
||||
segs = asset.data["segments"]
|
||||
assert segs[0]["wind_advisory"] is True
|
||||
assert segs[0]["lightning_risk"] is True
|
||||
assert segs[1]["wind_advisory"] is False
|
||||
|
||||
|
||||
def test_elevation_map(fixtures):
|
||||
route = parse_gpx((fixtures / "gaia.gpx").read_bytes())
|
||||
asset = GENERATORS["elevation_map"]().generate(route, None, None)
|
||||
assert len(asset.data["segments"]) == 2
|
||||
assert {c["type"] for c in asset.data["callouts"]} == {"summit", "low_point"}
|
||||
summit = next(c for c in asset.data["callouts"] if c["type"] == "summit")
|
||||
assert summit["ele_m"] == 460.0
|
||||
|
||||
|
||||
def test_grade_colors():
|
||||
assert grade_color(2) == "#2ecc71"
|
||||
assert grade_color(30) == "#e74c3c"
|
||||
Reference in new issue
Block a user