Show where a season came from; check it
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fbb43d9ff0
commit
03c2611036
7 files changed
+73
-3
No files matched your search
@@ -12,6 +12,8 @@ sys.dont_write_bytecode = True
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import season # noqa: E402
|
||||
import validate as V # noqa: E402
|
||||
import refresh # noqa: E402
|
||||
|
||||
|
||||
def src(publisher, facts=("season", "months"), url="https://example.org/trail"):
|
||||
@@ -105,6 +107,22 @@ class SeasonBasisTest(unittest.TestCase):
|
||||
errors = check(season=None, months=None, season_basis=None, season_method="Some method.")
|
||||
self.assertTrue(errors)
|
||||
|
||||
def test_every_record_with_a_season_passes_the_validator(self):
|
||||
errors = []
|
||||
for tid in refresh.trail_ids(V.ROOT):
|
||||
rec = refresh.load_toml(os.path.join(V.ROOT, tid, "trail.toml"))
|
||||
if (rec.get("hike") or {}).get("season"):
|
||||
V.check_hike(tid, rec, errors)
|
||||
self.assertEqual(errors, [])
|
||||
|
||||
def test_provenance_keys_need_no_source_fact(self):
|
||||
hike = {"season": "June to September", "months": [6, 7, 8, 9], "season_basis": "primary",
|
||||
"source": [src("Park Service", facts=("season", "months"))]}
|
||||
errors = []
|
||||
V.check_hike("t", {"hike": hike}, errors)
|
||||
self.assertFalse([e for e in errors if "not named in the facts" in e], errors)
|
||||
self.assertFalse([e for e in errors if "not a known field" in e], errors)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
+8
-2
@@ -17,6 +17,11 @@ import os
|
||||
import re
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"season", os.path.join(ROOT, "tools", "season.py"))
|
||||
season = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(season)
|
||||
MAX_BYTES = 50 * 1024 * 1024
|
||||
ALLOWED_LICENCES = {
|
||||
"us-gov-public-domain", "CC-BY-4.0", "CC-BY", "ODbL-1.0", "stated-permission",
|
||||
@@ -34,7 +39,7 @@ HIKE_FACTS = {"summary", "official_url", "start", "end", "shape", "days", "seaso
|
||||
"months", "travel", "start_lonlat", "end_lonlat"}
|
||||
LONLAT_BOUNDS = (-180.0, -50.0, 24.0, 75.0) # lon min, lon max, lat min, lat max
|
||||
HIKE_TRAVEL = {"trail", "trail-and-road", "some-cross-country", "mostly-cross-country"}
|
||||
HIKE_KEYS = HIKE_FACTS | {"checked"}
|
||||
HIKE_KEYS = HIKE_FACTS | {"checked"} | season.PROVENANCE_KEYS
|
||||
ELEVATION_KEYS = {"highest", "lowest", "ascent_m", "descent_m", "track_km", "published_km",
|
||||
"coverage", "parts", "orientation", "profile", "part_starts_km", "source"}
|
||||
ELEVATION_REQUIRED = ELEVATION_KEYS - {"part_starts_km"}
|
||||
@@ -366,9 +371,10 @@ def check_hike(tid, rec, errors):
|
||||
covered.update(("high_point", "high_point_m"))
|
||||
else:
|
||||
covered.add(fact)
|
||||
for name in sorted(set(hike) & HIKE_KEYS - {"checked"}) if sources else []:
|
||||
for name in sorted(set(hike) & HIKE_KEYS - {"checked"} - season.PROVENANCE_KEYS) if sources else []:
|
||||
if name not in covered:
|
||||
errors.append(f"{tid}: hike.{name} is not named in the facts of any hike source")
|
||||
season.check_season(tid, hike, errors)
|
||||
|
||||
|
||||
def check_elevation(tid, tdir, rec, errors):
|
||||
|
||||
Reference in new issue
Block a user