Make the monthly place check compare like with like, fail loudly on a bad outline download, and bring twelve placements up to date
The 2026-12-01 run reported 440 differences, but the outlines had not changed: a fresh download on 2026-12-03 matched the 2026-11-20 files byte for byte. The check counted every new download date as a difference, counted stated placements of trails with no track before but not after (so Zion, Arches and others read as "down to 0 trails"), and let the Montana and British Columbia Glacier parks push each other to suffixed slugs. A download date alone is no longer a difference; both sides of the 3-trail line count stated placements; Glacier National Park, Montana keeps the plain slug. An ArcGIS download now asks the service for its count and must bring exactly that many features, a service error body is raised, a source that yields no outlines is an error, and a registered place whose outline is gone stops the check naming it (exit 3), never "0 trails". The twelve real differences left are applied: ten trails gain a place the tool measures (Sheltowee Trace in Big South Fork; nine trails in the parent range left when a child range was dropped on 2026-11-20), and two wilderness twins of a same-named park are taken off the Brooks Range Traverse and the Guadalupe Ridge Trail and out of places.toml. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
05284f87a1
commit
41019c81e1
16 files changed
+402
-78
No files matched your search
@@ -670,7 +670,9 @@ class ApplyTest(unittest.TestCase):
|
||||
records=records)
|
||||
text = "\n".join(diffs)
|
||||
self.assertIn("measurement changed", text) # the moved boundary
|
||||
gone = outline("park", "P9", "Elsewhere Park",
|
||||
# The same outline, redrawn away from every track (a missing outline is an error:
|
||||
# FailedSourceTest).
|
||||
gone = outline("park", "P1", "Alpha Park",
|
||||
Polygon([(-100, 43), (-99, 43), (-99, 44), (-100, 44)]), hint=["WY"])
|
||||
diffs = P.check(self.root, None, outlines=[gone], versions={"nps": "2026-11-20"},
|
||||
records=records)
|
||||
@@ -693,5 +695,104 @@ class ApplyTest(unittest.TestCase):
|
||||
self.assertEqual(errors, [])
|
||||
|
||||
|
||||
@unittest.skipUnless(HAVE, "shapely (the .venv-places venv) is not installed")
|
||||
class FailedSourceTest(unittest.TestCase):
|
||||
"""The 2026-12-01 monthly check: a missing outline or a stated placement must never
|
||||
read as a park with no trails, and a fresh download date alone is no difference."""
|
||||
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.root = self.tmp.name
|
||||
make_repo(self.root)
|
||||
self.park = outline("park", "P1", "Alpha Park",
|
||||
Polygon([(-110, 43), (-109, 43), (-109, 44), (-110, 44)]), hint=["WY"])
|
||||
track = LineString([(-109.5, 43.2), (-109.5, 43.29)])
|
||||
p = P.propose([rec(r, ["WY"], track) for r in ("aa", "bb", "cc")] + [rec("zz", ["WY"], None)],
|
||||
[self.park])
|
||||
p.versions = {"nps": "2026-11-20"}
|
||||
pdir = os.path.join(self.root, "out")
|
||||
P.render_proposal(p, os.path.join(pdir, "proposal.md"))
|
||||
P.apply(os.path.join(pdir, "proposal.json"), self.root, "2026-11-20")
|
||||
self.records = P.load_records(self.root)
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
|
||||
def test_an_outline_missing_from_the_sources_fails_naming_it_instead_of_zero_trails(self):
|
||||
elsewhere = outline("park", "P9", "Elsewhere Park",
|
||||
Polygon([(-100, 43), (-99, 43), (-99, 44), (-100, 44)]), hint=["WY"])
|
||||
with self.assertRaises(P.SourceError) as e:
|
||||
P.check(self.root, None, outlines=[elsewhere], records=self.records)
|
||||
self.assertIn("park/alpha-park (nps P1)", str(e.exception))
|
||||
|
||||
def test_an_empty_source_file_fails_naming_the_source(self):
|
||||
with tempfile.TemporaryDirectory() as cache:
|
||||
src = P.SOURCES["nps"]
|
||||
with open(os.path.join(cache, src.filename), "w") as f:
|
||||
json.dump({"type": "FeatureCollection", "features": []}, f)
|
||||
with self.assertRaises(P.SourceError) as e:
|
||||
P.catalogue(cache, {"park": [], "range": []})
|
||||
self.assertIn("nps", str(e.exception))
|
||||
|
||||
def test_a_short_or_failed_arcgis_download_fails(self):
|
||||
def feats(n):
|
||||
return [{"type": "Feature", "properties": {"UNIT_CODE": "X"},
|
||||
"geometry": {"type": "Point", "coordinates": [0, 0]}}] * n
|
||||
real = P._arcgis_get
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
dest = os.path.join(d, "out.geojson")
|
||||
try:
|
||||
# The service caps a page at 600 though 1000 were asked: all 1500 still come.
|
||||
pages = iter([{"count": 1500}, {"features": feats(600)},
|
||||
{"features": feats(600)}, {"features": feats(300)}])
|
||||
P._arcgis_get = lambda url, params: next(pages)
|
||||
P._arcgis_geojson("u", "1=1", "*", dest)
|
||||
with open(dest) as f:
|
||||
self.assertEqual(len(json.load(f)["features"]), 1500)
|
||||
# The service stops answering features partway: an error, not a short file.
|
||||
pages = iter([{"count": 1500}, {"features": feats(1000)}, {"features": []}])
|
||||
P._arcgis_get = lambda url, params: next(pages)
|
||||
with self.assertRaises(P.SourceError):
|
||||
P._arcgis_geojson("u", "1=1", "*", dest + "2")
|
||||
self.assertFalse(os.path.exists(dest + "2"))
|
||||
finally:
|
||||
P._arcgis_get = real
|
||||
|
||||
def test_stated_placements_count_on_both_sides_of_the_three_trail_line(self):
|
||||
# Alpha Park holds two measured trails and one stated (cc has no track): three, a page.
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
make_repo(root)
|
||||
cc = os.path.join(root, "cc", "trail.toml")
|
||||
with open(cc) as f:
|
||||
text = f.read()
|
||||
with open(cc, "w") as f:
|
||||
f.write(text.replace('line_file = "line.geojson"', 'line_file = ""'))
|
||||
track = LineString([(-109.5, 43.2), (-109.5, 43.29)])
|
||||
p = P.propose([rec("aa", ["WY"], track), rec("bb", ["WY"], track),
|
||||
rec("cc", ["WY"], None), rec("zz", ["WY"], None)], [self.park])
|
||||
p.versions = {"nps": "2026-11-20"}
|
||||
P.render_proposal(p, os.path.join(root, "out", "proposal.md"))
|
||||
P.apply(os.path.join(root, "out", "proposal.json"), root, "2026-11-20")
|
||||
P.add_stated(root, "cc", "park", "alpha-park", "https://example.org/cc",
|
||||
"The trail runs through Alpha Park.", "2026-11-20")
|
||||
records = P.load_records(root)
|
||||
self.assertEqual(P.check(root, None, outlines=[self.park],
|
||||
versions={"nps": "2026-11-20"}, records=records), [])
|
||||
|
||||
def test_a_new_download_date_alone_is_no_difference(self):
|
||||
self.assertEqual(P.check(self.root, None, outlines=[self.park],
|
||||
versions={"nps": "2026-12-01"}, records=self.records), [])
|
||||
|
||||
def test_montanas_glacier_keeps_the_plain_slug_beside_canadas(self):
|
||||
geom = Polygon([(-110, 43), (-109, 43), (-109, 44), (-110, 44)])
|
||||
mt = outline("park", "GLAC", "Glacier National Park", geom,
|
||||
slug="glacier-national-park", hint=["MT"])
|
||||
bc = outline("park", "713700000", "Glacier National Park", geom, slug="", hint=["BC"])
|
||||
bc.slug = ""
|
||||
bc.source = "cpcad"
|
||||
P.assign_slugs([mt, bc])
|
||||
self.assertEqual((mt.slug, bc.slug), ("glacier-national-park", "glacier-national-park-bc"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user