diff --git a/merge-check.sh b/merge-check.sh index 9d75e6c..828c819 100644 --- a/merge-check.sh +++ b/merge-check.sh @@ -10,8 +10,8 @@ # What the image ships, compiled before the merge: every Python file the service's image copies, and the # models it imports. Then the tests in tests/, which need the standard library only: every circuit in # circuits/circuits.json carries one unique ergastId, and a race's circuit resolves by that id, never by -# its name; a failed Jolpica fetch is never kept, a season that is over is read from disk, a throttled -# request is asked again; a poster's options, keys, cache headers and store cap, its satellite source, credits and +# its name; every layout a race from 2020 on draws has a traced line, never a point; a failed Jolpica +# fetch is never kept, a season that is over is read from disk, a throttled request is asked again; a poster's options, keys, cache headers and store cap, its satellite source, credits and # licence (poster_options.py and poster_sources.py, standard library only). # # **Said, never passed silently**: the service's dependencies (service/requirements.txt) are the image's to diff --git a/tests/test_traces.py b/tests/test_traces.py new file mode 100644 index 0000000..ffb529c --- /dev/null +++ b/tests/test_traces.py @@ -0,0 +1,43 @@ +"""Every layout a race from 2020 on draws has a traced line: a layout whose trace is a point or empty is drawn without +a track (docs/posters.md, Layers), so such a trace for a current race fails the merge check. + +The layouts are the ones the service picks for a season (CircuitService.find_layout_slug_for_year), read from +circuits.json, never from Jolpica's schedules. Standard library only, so the merge check runs it as it is. +""" +import json +import unittest +from datetime import date +from pathlib import Path + +from circuits_service import CircuitService + +ROOT = Path(__file__).resolve().parent.parent +FIRST_SEASON = 2020 +MIN_POINTS = 10 # more than a few: a point, an empty line or a stub of a line fails + + +class TraceTest(unittest.TestCase): + def test_every_layout_raced_from_2020_on_has_a_traced_line(self): + service = CircuitService(str(ROOT / "circuits" / "circuits.json")) + drawn = set() + # This season and the next: a layout added for next season's calendar is held from the day it is added. + for season in range(FIRST_SEASON, date.today().year + 2): + for country in service.circuit_data.values(): + for locality in country.localities.values(): + for circuit in locality.circuits.values(): + slug = service.find_layout_slug_for_year(circuit, season) + if slug is not None: + drawn.add(circuit.layouts[slug].relative_geojson_filepath) + self.assertIn(Path("spain/madrid/madring/2026-.geo.json"), drawn) # the newest layout is among them + for path in sorted(drawn): + with self.subTest(layout=str(path)): + geometry = json.loads((ROOT / "circuits" / path).read_text(encoding="utf-8"))["features"][0]["geometry"] + line = geometry["type"] == "LineString" + points = len(geometry["coordinates"]) if line else 0 + found = f"a LineString of {points} points" if line else f"a {geometry['type']}" + self.assertGreater(points, MIN_POINTS, f"{path} is {found}, not a traced line of more than " + f"{MIN_POINTS} points") + + +if __name__ == "__main__": + unittest.main()