Let a place carry its own label and preposition, keep the count in every place title, and test that slugs follow names
A registry entry may now set label and prep. A plateau reads "Plateau" and "on the Colorado Plateau", the Mogollon Rim "Escarpment" and "along the Mogollon Rim", a national monument or a parkway its own word; the default is still "Mountain range" and "in the". Every national park, provincial park, monument, recreation area and parkway in the registry is labelled. A place title no longer gives up its ": N Trails" ending when it is long: it drops the state first and then keeps the count over the cap, and the state is left out where the name already holds it (Oregon Cascades, California Coast Ranges). A test checks that every slug is the slug of its display name, with the Arizona White Mountains as the one stated exception. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a97ea85093
commit
30d03b8069
10 files changed
+307
-43
No files matched your search
@@ -15,11 +15,12 @@ import tomllib
|
||||
|
||||
KINDS = ("park", "range", "wilderness")
|
||||
SOURCES = ("nps", "wilderness-connect", "cpcad", "gmba-v2")
|
||||
REGISTRY_KEYS = {"slug", "kind", "name", "where", "within", "source", "source_id",
|
||||
"source_version", "box"}
|
||||
REGISTRY_KEYS = {"slug", "kind", "name", "label", "prep", "where", "within", "source",
|
||||
"source_id", "source_version", "box"}
|
||||
REGISTRY_REQUIRED = ("slug", "kind", "name", "where", "source", "source_id",
|
||||
"source_version", "box")
|
||||
PLACE_KEYS = {"kind", "slug", "basis", "km", "source"}
|
||||
PREP_RE = re.compile(r"(in|on|at|along|across|near)( the)?")
|
||||
ID_RE = re.compile(r"[a-z0-9]+(-[a-z0-9]+)*")
|
||||
DATE_RE = re.compile(r"\d{4}-\d{2}-\d{2}")
|
||||
HASH_RE = re.compile(r"[0-9a-f]{16}")
|
||||
@@ -81,6 +82,11 @@ def check_registry(entries, errors):
|
||||
errors.append(f"{where} kind must be park, range or wilderness, not {kind!r}")
|
||||
if "name" in e:
|
||||
_text(e, "name", where, errors)
|
||||
if "label" in e:
|
||||
_text(e, "label", where, errors)
|
||||
if "prep" in e and not (isinstance(e["prep"], str) and PREP_RE.fullmatch(e["prep"])):
|
||||
errors.append(f"{where} prep must be a preposition such as \"in the\", \"on the\" "
|
||||
f"or \"along the\", not {e['prep']!r}")
|
||||
where_codes = e.get("where")
|
||||
if "where" in e and (not isinstance(where_codes, list) or not where_codes
|
||||
or not all(isinstance(c, str) and c for c in where_codes)):
|
||||
|
||||
@@ -1050,8 +1050,8 @@ def write_registry(root, entries):
|
||||
lines.pop()
|
||||
for e in sorted(entries, key=lambda e: (_KIND_ORDER.get(e["kind"], 9), e["slug"])):
|
||||
lines += ["", "[[place]]"]
|
||||
for key in ("slug", "kind", "name", "where", "within", "source", "source_id",
|
||||
"source_version", "box"):
|
||||
for key in ("slug", "kind", "name", "label", "prep", "where", "within", "source",
|
||||
"source_id", "source_version", "box"):
|
||||
if key in e and e[key] not in (None, [], ()):
|
||||
lines.append(f"{key} = {refresh._scalar(e[key])}")
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
@@ -1132,6 +1132,10 @@ def apply(proposal_path, root, today, exclude=frozenset()):
|
||||
"where": old.get("where") or v["where"],
|
||||
"source": v["source"], "source_id": v["source_id"],
|
||||
"source_version": versions.get(v["source"], ""), "box": v["box"]}
|
||||
# a reviewed label and preposition ("Plateau", "on the") are kept too
|
||||
for kept in ("label", "prep"):
|
||||
if old.get(kept):
|
||||
entry[kept] = old[kept]
|
||||
if v.get("within"):
|
||||
entry["within"] = list(v["within"])
|
||||
entries.append(entry)
|
||||
|
||||
@@ -605,6 +605,16 @@ class ApplyTest(unittest.TestCase):
|
||||
P.apply(self.pjson, self.root, "2026-12-01")
|
||||
self.assertEqual(read_toml(path)["place"][0]["where"], ["MT", "WY"])
|
||||
|
||||
def test_a_reviewed_label_and_preposition_survive_a_rerun(self):
|
||||
P.apply(self.pjson, self.root, "2026-11-20")
|
||||
path = os.path.join(self.root, "places.toml")
|
||||
text = open(path).read()
|
||||
open(path, "w").write(text.replace('name = "Alpha Park"',
|
||||
'name = "Alpha Park"\nlabel = "National park"\nprep = "along the"'))
|
||||
P.apply(self.pjson, self.root, "2026-12-01")
|
||||
entry = read_toml(path)["place"][0]
|
||||
self.assertEqual((entry["label"], entry["prep"]), ("National park", "along the"))
|
||||
|
||||
def test_stated_requires_an_http_source_a_quote_and_a_trackless_record(self):
|
||||
P.apply(self.pjson, self.root, "2026-11-20")
|
||||
with self.assertRaises(ValueError):
|
||||
|
||||
@@ -86,6 +86,45 @@ class RegistryTest(unittest.TestCase):
|
||||
self.assertTrue(any("box" in m for m in registry_errors([entry(box=bad)])), bad)
|
||||
|
||||
|
||||
class LabelAndPrepositionTest(unittest.TestCase):
|
||||
def test_a_label_and_a_preposition_are_allowed_and_checked(self):
|
||||
self.assertEqual(registry_errors([entry(label="Plateau", prep="on the")]), [])
|
||||
self.assertEqual(registry_errors([entry(label="Parkway", prep="along the", kind="park")]), [])
|
||||
self.assertTrue(any("label" in m for m in registry_errors([entry(label="")])))
|
||||
self.assertTrue(any("label" in m for m in registry_errors([entry(label=3)])))
|
||||
self.assertTrue(any("prep" in m for m in registry_errors([entry(prep="over the hills")])))
|
||||
self.assertTrue(any("prep" in m for m in registry_errors([entry(prep="")])))
|
||||
|
||||
def test_every_place_that_is_not_a_mountain_range_names_its_own_label(self):
|
||||
with open(os.path.join(ROOT, "places.toml"), "rb") as f:
|
||||
import tomllib
|
||||
reg = tomllib.load(f)["place"]
|
||||
for e in reg:
|
||||
if e["kind"] == "park":
|
||||
self.assertTrue(e.get("label"), f"{e['slug']} needs a label")
|
||||
by = {e["slug"]: e for e in reg if e["kind"] == "range"}
|
||||
for slug in ("colorado-plateau", "allegheny-plateau"):
|
||||
self.assertEqual((by[slug]["label"], by[slug]["prep"]), ("Plateau", "on the"))
|
||||
self.assertEqual(by["mogollon-rim"]["prep"], "along the")
|
||||
self.assertNotEqual(by["mogollon-rim"].get("label"), "Mountain range")
|
||||
|
||||
|
||||
class SlugTest(unittest.TestCase):
|
||||
EXCEPTIONS = {("range", "white-mountains-arizona"): "the White Mountains of Arizona share a "
|
||||
"display name with the ones of New Hampshire and Maine"}
|
||||
|
||||
def test_every_slug_is_the_slugified_display_name(self):
|
||||
import tomllib
|
||||
import place_trails
|
||||
with open(os.path.join(ROOT, "places.toml"), "rb") as f:
|
||||
reg = tomllib.load(f)["place"]
|
||||
bad = [f"{e['kind']}/{e['slug']} (name {e['name']!r})" for e in reg
|
||||
if (e["kind"], e["slug"]) not in self.EXCEPTIONS
|
||||
and e["slug"] != place_trails.slugify(e["name"])]
|
||||
self.assertEqual(bad, [])
|
||||
self.assertEqual(len(self.EXCEPTIONS), 1)
|
||||
|
||||
|
||||
class RecordTest(unittest.TestCase):
|
||||
def test_record_place_must_be_in_the_registry(self):
|
||||
rec = record(place=[{"kind": "range", "slug": "no-such", "basis": "stated",
|
||||
|
||||
Reference in new issue
Block a user