Make the monthly season check offline: it compares each estimate's recorded track and location with the trail's current one and downloads nothing; fix the audit so every command runs as written (packets needs --out, the places tool runs in its venv), with places and seasons steps under their own headings

This commit is contained in:
swaits committed 2026-11-20 14:45:42 -07:00
1 parent e6c2f371fc
commit f91c7dbc20
9 files changed
+328 -194

No files matched your search

+34 -47
View File
@@ -711,64 +711,52 @@ def estimates(root):
if (rec.get("hike") or {}).get("season_basis") == "estimate"]
def check(root, fetch):
"""Rerun the machine estimate for every estimated season and the
leave-one-out fit. Returns (ok, lines): not ok when an estimate's
inputs have changed since they were recorded in
tools/season_inputs.json (the machine estimate, the climate at the
trail, or the sourced trails it is compared with), when the
leave-one-out match share has fallen by more than 0.02 from
tools/season_fit.json, or when the blind test of the judged method
(tools/season_blind_test.json) is missing, or is below the bar on its
ends-only measure (the strict measure is recorded beside it). A changed
def points_signature(root, rec):
"""A short digest of where a trail's season was estimated: the kind of sample points and their
coordinates and elevations, from the trail's current track (or its ends, or its place). It reads
only files in the repository, so the monthly check can compare it with no network."""
points, kind = sample_points(root, rec)
material = json.dumps(
{"kind": kind,
"points": [[round(p.lat, 4), round(p.lon, 4),
None if p.elev_m is None else round(p.elev_m)] for p in points]},
sort_keys=True)
return hashlib.sha256(material.encode()).hexdigest()[:16]
def check(root, fetch=None):
"""The monthly check, offline. For every estimated season, compares the digest of the trail's
current track and location (points_signature) with the one recorded in
tools/season_inputs.json when the season was set, and returns (ok, lines): not ok when an
estimate has no recorded inputs, when its track or location has changed, when inputs are
recorded for a trail that is no longer an estimate, or when the blind test of the judged method
(tools/season_blind_test.json) is missing, or is below the bar on its ends-only measure (the
strict measure is recorded beside it). The climate normals are a fixed published dataset
(CHELSA, 1981 to 2010), so they are not read again; `fetch` is accepted and unused. A changed
estimate is a flag for a person to look at, not a rewrite."""
import season_judge
try:
fit = load_fit(root)
except OSError:
return False, ["tools/season_fit.json is missing: run "
"python3 tools/estimate_season.py fit"]
params = load_params(root)
ok, lines, checked = True, [], 0
refs = references(root, fetch)
recorded = load_inputs(root)
for tid, rec in _records(root):
hike = rec.get("hike") or {}
if hike.get("season_basis") != "estimate":
continue
checked += 1
sig = inputs_signature(estimate(root, dict(rec, id=tid), params, fetch, refs))
then = recorded.get(tid)
if then is None:
now = points_signature(root, dict(rec, id=tid))
then = (recorded.get(tid) or {}).get("points")
if tid not in recorded or then is None:
ok = False
lines.append(f"{tid}: no inputs are recorded for this estimate: run "
"python3 tools/season_judge.py inputs")
elif sig["machine"] != then["machine"]:
"python3 tools/season_judge.py inputs --points " + tid)
elif now != then:
ok = False
lines.append(f"{tid}: inputs changed: the machine estimate was {then['machine']}, "
f"now {sig['machine']}; the season is {sorted(hike.get('months') or [])}")
elif sig["digest"] != then["digest"]:
ok = False
lines.append(f"{tid}: inputs changed: the climate or the similar sourced trails differ "
f"(machine estimate still {sig['machine']}); the season is "
lines.append(f"{tid}: inputs changed: the trail's track or location is no longer the one the "
f"season was estimated for ({then}, now {now}); the season is "
f"{sorted(hike.get('months') or [])}")
for tid in sorted(set(recorded) - set(estimates(root))):
ok = False
lines.append(f"{tid}: has recorded inputs but is no longer an estimate: remove it "
"from tools/season_inputs.json")
sourced = sourced_trails(root, fetch)
if any(s[1] is not None for s in sourced):
_p, now, _loo = fit_sourced(sourced)
stored = fit.get("loo") or {}
if stored.get("n"):
was_share = stored["within1"] / stored["n"]
now_share = now["within1"] / now["n"] if now["n"] else 0.0
if was_share - now_share > 0.02:
ok = False
lines.append(
f"fit got worse: leave-one-out matches "
f"{now['within1']}/{now['n']} ({now_share:.2f}), "
f"was {stored['within1']}/{stored['n']} ({was_share:.2f})")
try:
blind = season_judge.load_blind_test(os.path.join(root, "tools", "season_blind_test.json"))
problems = season_judge.check_blind_test(blind)
@@ -784,7 +772,8 @@ def check(root, fetch):
ok = False
lines.append("tools/season_blind_test.json is missing or unreadable")
if ok:
lines.append(f"check passed: {checked} estimated seasons rest on the same inputs")
lines.append(f"check passed: {checked} estimated seasons are still on the track or location "
"they were estimated for")
return ok, lines
@@ -870,8 +859,7 @@ def cmd_estimates(args):
def cmd_check(args):
fetch = _fetch_with_cache(args.cache)
ok, lines = check(ROOT, fetch)
ok, lines = check(ROOT)
for line in lines:
print(line)
return 0 if ok else 1
@@ -907,9 +895,8 @@ def main(argv=None):
"estimates", help="list the trails whose season is an estimate")
estimates_parser.set_defaults(func=cmd_estimates)
check_parser = sub.add_parser(
"check", help="rerun every estimate and the fit")
check_parser.add_argument("--cache", default=None,
help="climate cache directory")
"check", help="offline: compare each estimate's recorded inputs with the trail's "
"current track and location, and check the blind test")
check_parser.set_defaults(func=cmd_check)
argv = ["check" if a == "--check" else a
for a in (sys.argv[1:] if argv is None else argv)]
+147 -69
View File
@@ -6,7 +6,8 @@
6,
9,
10
]
],
"points": "5b3280ac815e9040"
},
"alpine-trail-7": {
"digest": "efd5e277fbf3b6c1",
@@ -14,7 +15,8 @@
7,
8,
9
]
],
"points": "66d1a158cf32328a"
},
"avon": {
"digest": "a9120a59a9a1907d",
@@ -25,7 +27,8 @@
8,
9,
10
]
],
"points": "a133f33fe3b019f9"
},
"batona": {
"digest": "3dbdb3e8b17d2b98",
@@ -35,7 +38,8 @@
9,
10,
11
]
],
"points": "560955c481df42f5"
},
"bay-circuit": {
"digest": "bdb128943b1900ae",
@@ -46,7 +50,8 @@
8,
9,
10
]
],
"points": "90eafebf6ec4f76a"
},
"bayou-state-trail": {
"digest": "c7c4147060628fa7",
@@ -57,7 +62,8 @@
4,
11,
12
]
],
"points": "a8467e9a59501dd8"
},
"boundary-trail-mount-st-helens": {
"digest": "01312d045fd17c20",
@@ -65,7 +71,8 @@
7,
8,
9
]
],
"points": "f54416dc9b67f3a3"
},
"boundary-trail-pasayten": {
"digest": "e97c07b0f68a15a9",
@@ -73,7 +80,8 @@
7,
8,
9
]
],
"points": "d95317240cb4b500"
},
"bristol-hills-trail": {
"digest": "a5fa7af7ebab8d67",
@@ -84,13 +92,15 @@
8,
9,
10
]
],
"points": "7a56b636555fa553"
},
"brooks-range-traverse": {
"digest": "8a3c5ef0f30bc7f8",
"machine": [
8
]
],
"points": "3e4bc0ab7ded98aa"
},
"bruce-trail": {
"digest": "ed62c99709c54267",
@@ -99,7 +109,8 @@
8,
9,
10
]
],
"points": "e6e985acbfb0c18a"
},
"california-coastal": {
"digest": "5c7fa4913f78b36c",
@@ -109,7 +120,8 @@
8,
9,
10
]
],
"points": "46d88fdd32b7c0c8"
},
"conestoga-trail": {
"digest": "31f1d48bf322e3a7",
@@ -118,7 +130,8 @@
5,
9,
10
]
],
"points": "8b710f69e6901943"
},
"conservation-trail": {
"digest": "21bfcf5403bcbfdf",
@@ -128,7 +141,8 @@
8,
9,
10
]
],
"points": "2ef8a2830d82f390"
},
"cranberry-lake-50": {
"digest": "87772fc46ebb73ca",
@@ -136,7 +150,8 @@
7,
8,
9
]
],
"points": "61231407b018812f"
},
"cross-vermont": {
"digest": "de8f9f0acea8bd21",
@@ -145,7 +160,8 @@
6,
9,
10
]
],
"points": "0cad6fec0d9afc44"
},
"deseret-hiking-route": {
"digest": "191f5e4f5cc698cb",
@@ -155,7 +171,8 @@
5,
10,
11
]
],
"points": "6079d15e9d183d7f"
},
"desert-trail": {
"digest": "132108d83a002b0d",
@@ -164,7 +181,8 @@
8,
9,
10
]
],
"points": "aa33dec22b7500b8"
},
"donut-hole": {
"digest": "dcc41463939e95a7",
@@ -174,7 +192,8 @@
6,
9,
10
]
],
"points": "284c0ef8512572a6"
},
"eastern-continental-trail": {
"digest": "d40390952a719154",
@@ -184,7 +203,8 @@
8,
9,
10
]
],
"points": "a6e0ee1c73858dcb"
},
"eastern-sierra-high-route": {
"digest": "34c0558ddeedd3f2",
@@ -192,7 +212,11 @@
7,
8,
9
]
],
"points": "55b8981509ad0893"
},
"finger-lakes": {
"points": "338c0f525d32224b"
},
"ganaraska": {
"digest": "b414a50c65a31b82",
@@ -203,7 +227,8 @@
8,
9,
10
]
],
"points": "2bdcc55e79a5f683"
},
"general-george-crook": {
"digest": "f2896d5fe13e417f",
@@ -212,7 +237,8 @@
5,
9,
10
]
],
"points": "64014e2e7644af9c"
},
"georgia-loop": {
"digest": "35f1d5133569d0c0",
@@ -224,7 +250,8 @@
10,
11,
12
]
],
"points": "441770b746069082"
},
"gila-centennial-loop": {
"digest": "08f4ed745b5d2560",
@@ -235,7 +262,8 @@
9,
10,
11
]
],
"points": "1bde178eb296427c"
},
"grand-valley-trail": {
"digest": "5f4505a160f8f245",
@@ -244,7 +272,8 @@
6,
9,
10
]
],
"points": "8d3f4d42f8553ba0"
},
"great-eastern": {
"digest": "b77ec5d870bbcc88",
@@ -252,7 +281,8 @@
4,
5,
10
]
],
"points": "f75851e040957980"
},
"great-western-divide-loop": {
"digest": "dd7b6f503f72081b",
@@ -261,7 +291,8 @@
8,
9,
10
]
],
"points": "64bab16e50d60757"
},
"high-country-pathway": {
"digest": "b59fdbbf3b1ac6f8",
@@ -271,7 +302,8 @@
8,
9,
10
]
],
"points": "0ea28ef5b9723b8d"
},
"highlands": {
"digest": "8212eeadd24218c3",
@@ -280,7 +312,8 @@
5,
9,
10
]
],
"points": "28d7e27072f8cc8b"
},
"hoosier-heritage-trail": {
"digest": "f550667eab910362",
@@ -290,7 +323,8 @@
5,
10,
11
]
],
"points": "27fe12298613e61c"
},
"horse-shoe": {
"digest": "aeff26cf6c7e0143",
@@ -299,7 +333,8 @@
5,
9,
10
]
],
"points": "ffe09d582ca7a623"
},
"hot-springs-trail": {
"digest": "fc73ad4cf711d615",
@@ -310,7 +345,8 @@
5,
10,
11
]
],
"points": "f64b708fe0a66d2a"
},
"iat-newfoundland-labrador": {
"digest": "91eadce2b4ef4c7f",
@@ -318,7 +354,11 @@
7,
8,
9
]
],
"points": "658a452a468fffd1"
},
"ice-age": {
"points": "6123e99c6a3082fe"
},
"international-appalachian-trail-maine": {
"digest": "8f488d4dc2b03636",
@@ -326,13 +366,15 @@
7,
8,
9
]
],
"points": "4cac64a291020a9a"
},
"koroc-palmer-loop": {
"digest": "e18e82c08b6dfd5d",
"machine": [
8
]
],
"points": "84ce0d6f0fd7b454"
},
"la-cloche": {
"digest": "61ce29ac5892d1b8",
@@ -340,7 +382,8 @@
7,
8,
9
]
],
"points": "32195bb88992a86c"
},
"lost-coast": {
"digest": "971c47b8714b706f",
@@ -350,7 +393,8 @@
8,
9,
10
]
],
"points": "46726fb00eebd4cf"
},
"loyalsock": {
"digest": "7e8067a31ec5da6c",
@@ -360,7 +404,8 @@
6,
9,
10
]
],
"points": "589a23f3e8bf86e0"
},
"mason-dixon": {
"digest": "54cad0c500a1e861",
@@ -369,7 +414,8 @@
5,
9,
10
]
],
"points": "b67b7d3e33ed925f"
},
"midland-to-mackinac-trail": {
"digest": "c5ed1765cac4534f",
@@ -377,7 +423,8 @@
7,
8,
9
]
],
"points": "3df8a157582012ce"
},
"midstate-ma": {
"digest": "edc133c6ae5007c7",
@@ -386,7 +433,8 @@
6,
9,
10
]
],
"points": "99a2fcf36b45e796"
},
"north-south": {
"digest": "86641545fa67fd0c",
@@ -396,7 +444,8 @@
6,
9,
10
]
],
"points": "b0c1b0a0708e708e"
},
"north-south-lbl": {
"digest": "25b3d5d788753ae6",
@@ -406,14 +455,16 @@
5,
10,
11
]
],
"points": "3d0f9ffedba5dd16"
},
"north-umpqua": {
"digest": "14231792880f7042",
"machine": [
5,
10
]
],
"points": "81a26b35ce4a2b65"
},
"oak-ridges": {
"digest": "0646d355131c000c",
@@ -423,7 +474,8 @@
8,
9,
10
]
],
"points": "ed723136e55593f2"
},
"ottawa-temiskaming-highland-trail": {
"digest": "77fbbe8137415f41",
@@ -431,7 +483,11 @@
7,
8,
9
]
],
"points": "89d2a7d8f17525e7"
},
"ozark-trail": {
"points": "48f5b65c51e0a605"
},
"paumanok-path": {
"digest": "588eea3017f04c4c",
@@ -440,7 +496,8 @@
8,
9,
10
]
],
"points": "803699c022c3c997"
},
"pfiffner-traverse": {
"digest": "61965112f0b75445",
@@ -448,7 +505,8 @@
7,
8,
9
]
],
"points": "d3eecf6f0442939d"
},
"rideau-trail": {
"digest": "55d2219b607959d1",
@@ -458,7 +516,8 @@
8,
9,
10
]
],
"points": "7a16758637f5c4fc"
},
"ring-the-peak": {
"digest": "858d219cc4ecd8f6",
@@ -466,7 +525,8 @@
7,
8,
9
]
],
"points": "f13e0b5aeec19a5c"
},
"sawtooth-wilderness-high-route": {
"digest": "0f4f2e2bf5e9bc6e",
@@ -474,7 +534,8 @@
7,
8,
9
]
],
"points": "986a243b2dec421d"
},
"sea-to-sea-route": {
"digest": "eb6dbcb347f7a83d",
@@ -482,7 +543,8 @@
6,
9,
10
]
],
"points": "18927e8fccda17e4"
},
"shawangunk-ridge-trail": {
"digest": "d3b38e00538fd900",
@@ -492,7 +554,8 @@
6,
9,
10
]
],
"points": "6fe7bf6b493b24a4"
},
"shenipsit-trail": {
"digest": "a713c4e4a679b6fa",
@@ -501,7 +564,8 @@
5,
9,
10
]
],
"points": "a4533e0f9dfca3b2"
},
"siskiyou-peaks-trail": {
"digest": "2b4dff26c8e71b80",
@@ -509,7 +573,8 @@
7,
8,
9
]
],
"points": "6ff6148206cdf66b"
},
"sky-islands-traverse": {
"digest": "eed4f15ecdf6114d",
@@ -520,7 +585,8 @@
9,
10,
11
]
],
"points": "840db2e4fcb1de1c"
},
"solitude-loop": {
"digest": "c091a7bb7336deb5",
@@ -528,7 +594,8 @@
7,
8,
9
]
],
"points": "3f2a5bcfbaf1ebe2"
},
"standing-stone": {
"digest": "cdc4f7ed39a2c205",
@@ -537,28 +604,32 @@
5,
9,
10
]
],
"points": "30d3a7085e711b49"
},
"stein-valley-traverse": {
"digest": "59cd7e9a35c5c732",
"machine": [
6,
9
]
],
"points": "4bf13dd8bff38e69"
},
"sunapee-ragged-kearsarge": {
"digest": "f5d7131d547be861",
"machine": [
8,
9
]
],
"points": "401dd7ea1ce18086"
},
"tahoe-yosemite-trail": {
"digest": "23aa94cfbefd3f86",
"machine": [
8,
9
]
],
"points": "e77f9a0b7900a3d1"
},
"tuscarora": {
"digest": "606d9fe137a8347d",
@@ -567,14 +638,16 @@
5,
9,
10
]
],
"points": "9e75f481d596079f"
},
"vagabond-loop": {
"digest": "33378ec42f73f8d5",
"machine": [
4,
10
]
],
"points": "b56fa26d9315370d"
},
"warrior-trail": {
"digest": "cecd19f5c7ba6ae4",
@@ -583,7 +656,8 @@
5,
9,
10
]
],
"points": "a1fa2f53436ddcbd"
},
"wasatch-traverse": {
"digest": "1582bd31f8f00ced",
@@ -592,7 +666,8 @@
6,
9,
10
]
],
"points": "5b3280ac815e9040"
},
"waskahegan": {
"digest": "d7993fbe810051fd",
@@ -600,7 +675,8 @@
7,
8,
9
]
],
"points": "3d85be5f038811c6"
},
"western-uplands": {
"digest": "464d6cd6bfe3257c",
@@ -608,7 +684,8 @@
7,
8,
9
]
],
"points": "57288e3504dc6d55"
},
"yosemite-high-route": {
"digest": "eee24b0c39473ab0",
@@ -616,6 +693,7 @@
7,
8,
9
]
],
"points": "10d56319fea3c478"
}
}
+38 -10
View File
@@ -20,8 +20,9 @@ Commands:
tools/season_blind_test.json)
proposals stage the judged seasons for the trails with no season, for
python3 tools/refresh.py collect and apply
inputs record the machine estimate and the inputs of every estimate,
so the monthly check can see when they change
inputs record what every estimate rests on (the digest of its track
and location, and the machine estimate), so the monthly check,
which runs offline, can see when a track or location changes
An answer file is tab separated, one trail a line, no header: id, months
(comma separated, 1 to 12), season phrase, confidence (high, medium or
@@ -608,13 +609,37 @@ def cmd_proposals(args):
def cmd_inputs(args):
fetch = E._fetch_with_cache(args.cache)
params = E.load_params(ROOT)
refs = E.references(ROOT, fetch)
doc = {}
for tid, rec in E._records(ROOT):
if (rec.get("hike") or {}).get("season_basis") == "estimate":
doc[tid] = E.inputs_signature(E.estimate(ROOT, dict(rec, id=tid), params, fetch, refs))
"""Record what each estimate rests on: the digest of the trail's track and location (offline,
all the monthly check compares) and, unless --points, the machine estimate and the digest of the
climate and similar trails at the time (which reads the climate, so it needs the network)."""
try:
with open(args.write, encoding="utf-8") as f:
doc = json.load(f)
except OSError:
doc = {}
params = refs = fetch = None
if not args.points:
fetch = E._fetch_with_cache(args.cache)
params = E.load_params(ROOT)
refs = E.references(ROOT, fetch)
estimates = {tid: rec for tid, rec in E._records(ROOT)
if (rec.get("hike") or {}).get("season_basis") == "estimate"}
unknown = [t for t in args.ids if t not in estimates]
if unknown:
print("not an estimate: " + ", ".join(unknown))
return 1
for tid in sorted(set(doc) - set(estimates)):
del doc[tid]
for tid, rec in estimates.items():
if args.ids and tid not in args.ids:
continue
entry = dict(doc.get(tid, {}))
if not args.points:
entry.update(E.inputs_signature(E.estimate(ROOT, dict(rec, id=tid), params, fetch, refs)))
entry["points"] = E.points_signature(ROOT, dict(rec, id=tid))
doc[tid] = entry
for tid, rec in estimates.items(): # every estimate has its digest, even when only some were asked for
doc.setdefault(tid, {"points": E.points_signature(ROOT, dict(rec, id=tid))})
with open(args.write, "w", encoding="utf-8") as f:
json.dump(doc, f, indent=1, sort_keys=True)
f.write("\n")
@@ -642,7 +667,10 @@ def main(argv=None):
p.add_argument("--pages", default=PAGES)
p.add_argument("--dir", default=None)
p.set_defaults(func=cmd_proposals)
p = sub.add_parser("inputs", help="record the inputs of every estimate")
p = sub.add_parser("inputs", help="record the inputs of every estimate (or of the trail ids named)")
p.add_argument("ids", nargs="*", help="only these estimates; default every estimate")
p.add_argument("--points", action="store_true",
help="record only the digest of the track and location (offline, quick)")
p.add_argument("--write", default=INPUTS)
p.add_argument("--cache", default=None)
p.set_defaults(func=cmd_inputs)
+47 -35
View File
@@ -403,10 +403,8 @@ class ProposeCheckTest(unittest.TestCase):
json.dump(doc, f)
def record_inputs(self, root, tid="aaa", **change):
params = E.load_params(root)
rec = E.refresh.load_toml(os.path.join(root, tid, "trail.toml"))
sig = E.inputs_signature(E.estimate(root, dict(rec, id=tid), params, mild_fetch,
E.references(root, mild_fetch)))
sig = {"points": E.points_signature(root, dict(rec, id=tid))}
sig.update(change)
with open(os.path.join(root, "tools", "season_inputs.json"), "w") as f:
json.dump({tid: sig}, f)
@@ -417,68 +415,82 @@ class ProposeCheckTest(unittest.TestCase):
self.blind_doc(root, **kw)
return root
def test_check_passes_when_nothing_changed(self):
@staticmethod
def no_network(lat, lon, elev):
raise AssertionError("the monthly check must not read the climate")
def test_check_passes_when_nothing_changed_and_reads_no_climate(self):
tmp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp, True)
root = self.checked_repo(tmp)
E._REFS.clear()
self.record_inputs(root)
ok, lines = E.check(root, mild_fetch)
ok, lines = E.check(root, self.no_network)
self.assertTrue(ok, lines)
ok, lines = E.check(root)
self.assertTrue(ok, lines)
def test_check_flags_an_estimate_whose_machine_estimate_changed(self):
def test_check_flags_an_estimate_whose_location_moved(self):
tmp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp, True)
root = self.checked_repo(tmp)
E._REFS.clear()
self.record_inputs(root, machine=[6, 7])
ok, lines = E.check(root, mild_fetch)
self.record_inputs(root)
path = os.path.join(root, "aaa", "trail.toml")
with open(path, encoding="utf-8") as f:
text = f.read()
with open(path, "w", encoding="utf-8") as f:
f.write(text.replace("end_lonlat = [-110.0, 43.2]", "end_lonlat = [-111.5, 44.2]"))
ok, lines = E.check(root, self.no_network)
self.assertFalse(ok)
self.assertTrue(any("aaa" in line and "inputs changed" in line and "[6, 7]" in line
self.assertTrue(any("aaa" in line and "inputs changed" in line and "track or location" in line
for line in lines), lines)
def test_check_flags_an_estimate_whose_climate_digest_changed(self):
def test_check_flags_an_estimate_whose_recorded_inputs_differ(self):
tmp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp, True)
root = self.checked_repo(tmp)
E._REFS.clear()
self.record_inputs(root, digest="0" * 16)
ok, lines = E.check(root, mild_fetch)
self.record_inputs(root, points="0" * 16)
ok, lines = E.check(root, self.no_network)
self.assertFalse(ok)
self.assertTrue(any("aaa" in line and "inputs changed" in line for line in lines), lines)
def test_the_points_signature_does_not_move_for_changes_that_are_not_the_location(self):
tmp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp, True)
root = self.checked_repo(tmp)
rec = E.refresh.load_toml(os.path.join(root, "aaa", "trail.toml"))
before = E.points_signature(root, dict(rec, id="aaa"))
rec["hike"]["summary"] = "Something else."
self.assertEqual(E.points_signature(root, dict(rec, id="aaa")), before)
def test_check_flags_an_estimate_with_no_recorded_inputs(self):
tmp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp, True)
root = self.checked_repo(tmp)
E._REFS.clear()
ok, lines = E.check(root, mild_fetch)
ok, lines = E.check(root, self.no_network)
self.assertFalse(ok)
self.assertTrue(any("aaa" in line and "no inputs are recorded" in line for line in lines), lines)
def test_check_fails_when_the_blind_test_is_under_the_bar(self):
def test_check_flags_inputs_recorded_for_a_trail_that_is_no_longer_an_estimate(self):
tmp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp, True)
root = self.checked_repo(tmp)
self.record_inputs(root)
with open(os.path.join(root, "tools", "season_inputs.json"), "w") as f:
json.dump({"aaa": {"points": E.points_signature(
root, dict(E.refresh.load_toml(os.path.join(root, "aaa", "trail.toml")), id="aaa"))},
"gone": {"points": "x"}}, f)
ok, lines = E.check(root)
self.assertFalse(ok)
self.assertTrue(any("gone" in line for line in lines), lines)
def test_check_fails_when_the_blind_test_is_under_the_bar_on_the_ends_only_measure(self):
tmp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp, True)
root = self.checked_repo(tmp, share=0.6)
E._REFS.clear()
self.record_inputs(root)
ok, lines = E.check(root, mild_fetch)
ok, lines = E.check(root)
self.assertFalse(ok)
self.assertTrue(any("blind test" in line for line in lines), lines)
def test_check_fails_when_the_fit_got_worse(self):
tmp = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp, True)
# one sourced trail that mild all-year normals cannot match
extra = ('season = "June"\nmonths = [6]\n'
'season_basis = "source"\n' + self.ENDS)
root = self.repo_with(tmp, [("only", "Only", {"extra_hike": extra})])
self.fit_doc(root, within1=4, n=4)
self.blind_doc(root)
E._REFS.clear()
ok, lines = E.check(root, mild_fetch)
self.assertFalse(ok)
self.assertTrue(any("fit got worse" in line for line in lines), lines)
self.assertTrue(any("blind test" in line and "ends-only" in line for line in lines), lines)
def test_the_estimates_command_lists_only_estimates(self):
tmp = tempfile.mkdtemp()
+27 -2
View File
@@ -35,7 +35,8 @@ class AuditChecklistTest(unittest.TestCase):
self.assertIn("estimate_season.py estimates", seasons)
self.assertIn("docs/season-research.md", seasons)
self.assertIn("search afresh for a page that states the season", seasons.lower().replace("\n", " "))
self.assertIn("re-run the machine estimate", seasons.lower())
self.assertIn("downloads nothing", seasons)
self.assertIn("fixed published dataset", seasons)
self.assertIn("1. ", seasons)
self.assertIn("2. ", seasons)
@@ -51,6 +52,27 @@ class AuditChecklistTest(unittest.TestCase):
self.assertEqual(stop.exception.code, 0, sub)
self.assertIn(f" {sub}", out.getvalue())
def test_every_command_in_the_audit_runs_as_written(self):
"""Each `python3 tools/<script>.py ...` the audit names must be accepted by that script's own
argument parser: the subcommand exists and the options and required arguments are given."""
import subprocess
doc = read("docs", "audit.md")
commands = re.findall(r"`((?:\.venv-places/bin/)?python3? (?:tools|web)/[^`]+)`", doc)
self.assertGreaterEqual(len(commands), 8)
for command in commands:
words = [w for w in command.split() if not w.startswith("<")][1:]
script, args = words[0], words[1:]
if script in ("web/build.py", "tools/validate.py", "tools/place_trails.py"):
continue # no argument parser to ask, or one that needs its own venv
# a placeholder trail id is replaced by a real one
args = ["finger-lakes" if a == "<id>" else a for a in args]
run = subprocess.run([sys.executable, os.path.join(ROOT, script), *args, "--help"],
capture_output=True, text=True, cwd=ROOT)
self.assertEqual(run.returncode, 0, (command, run.stderr[-300:]))
# the packets command has a required output directory
self.assertTrue(any(c.startswith("python3 tools/season_judge.py packets --out ") for c in commands))
self.assertFalse(any(c.endswith("season_judge.py packets") for c in commands))
def test_the_estimates_command_prints_one_id_a_line(self):
ids = E.estimates(ROOT)
self.assertEqual(len(ids), 72)
@@ -72,8 +94,11 @@ class AuditChecklistTest(unittest.TestCase):
class MonthlyWorkflowTest(unittest.TestCase):
def test_the_monthly_workflow_runs_the_check_on_a_schedule(self):
text = read(".github", "workflows", "season-check.yml")
for want in ("schedule", "workflow_dispatch", "estimate_season.py check", "cron:", "longhikes-climate"):
for want in ("schedule", "workflow_dispatch", "estimate_season.py check", "cron:"):
self.assertIn(want, text)
# offline: it downloads nothing and keeps no climate cache
self.assertNotIn("longhikes-climate", text)
self.assertNotIn("actions/cache", text)
if __name__ == "__main__":