Merge pull request 'Draw Madring's track: take upstream's GPS trace instead of a point' (#10) from fix/madring-trace into master
This commit was merged in pull request #10.
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user