Keep a trail's abbreviation only where one is in real use
Every record had an abbreviation because the schema required one, so
where a trail had none one was made up. Nineteen were shared by 49
trails and many were inventions nobody uses ("TCT-WY", "BT-ON").
The rule now:
- An abbreviation is recorded only where the trail's holder or author
uses it, or it is in established use among hikers. The new field
short_name_url names the page where it was seen.
- None is made up. short_name is optional, and a trail nobody
abbreviates has none.
- It is written without full stops: "AT", not "A.T.".
- Two trails may truthfully share one. The City of Prescott calls the
Prescott Circle Trail "the PCT", so its record says so.
Each of the 182 abbreviations was checked against the trail's own
pages. 104 are kept with their source page, 13 of them corrected to
the form in use (for example "MST" for both the Mountains-to-Sea and
Mid State trails, "FT" for the Florida Trail). 78 are removed.
The validator enforces the rule.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
94015cd86b
commit
ae86d5c3cc
186 files changed
+200
-94
No files matched your search
@@ -0,0 +1,59 @@
|
||||
"""Tests for the short_name and short_name_url checks in tools/validate.py: no network, no numpy.
|
||||
|
||||
Run from the repository root:
|
||||
python3 -m unittest discover tools/tests
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import validate as V # noqa: E402
|
||||
|
||||
URL = "https://www.pcta.org/"
|
||||
|
||||
|
||||
def check(rec):
|
||||
errors = []
|
||||
V.check_short_name("t", rec, errors)
|
||||
return errors
|
||||
|
||||
|
||||
class ShortNameTest(unittest.TestCase):
|
||||
def test_none_is_valid(self):
|
||||
self.assertEqual(check({}), [])
|
||||
|
||||
def test_abbreviation_with_page_is_valid(self):
|
||||
self.assertEqual(check({"short_name": "PCT", "short_name_url": URL}), [])
|
||||
self.assertEqual(check({"short_name": "PCT", "short_name_url": "http://example.org/a"}), [])
|
||||
|
||||
def test_abbreviation_needs_a_page(self):
|
||||
errors = check({"short_name": "PCT"})
|
||||
self.assertEqual(len(errors), 1)
|
||||
self.assertIn("needs short_name_url", errors[0])
|
||||
|
||||
def test_page_needs_an_abbreviation(self):
|
||||
errors = check({"short_name_url": URL})
|
||||
self.assertEqual(len(errors), 1)
|
||||
self.assertIn("without short_name", errors[0])
|
||||
|
||||
def test_page_must_be_http(self):
|
||||
for bad in ("www.pcta.org", "ftp://example.org/", "", 5):
|
||||
self.assertTrue(any("http(s)" in e for e in check({"short_name": "PCT", "short_name_url": bad})), bad)
|
||||
|
||||
def test_no_full_stops(self):
|
||||
errors = check({"short_name": "A.T.", "short_name_url": URL})
|
||||
self.assertEqual(len(errors), 1)
|
||||
self.assertIn("full stops", errors[0])
|
||||
self.assertEqual(check({"short_name": "M-DT", "short_name_url": URL}), [])
|
||||
self.assertEqual(check({"short_name": "L2H", "short_name_url": URL}), [])
|
||||
|
||||
def test_abbreviation_must_be_a_clean_string(self):
|
||||
for bad in ("", " ", " PCT", "PCT ", 7, ["PCT"]):
|
||||
self.assertTrue(check({"short_name": bad, "short_name_url": URL}), repr(bad))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
+20
-1
@@ -355,6 +355,24 @@ def check_elevation(tid, tdir, rec, errors):
|
||||
errors.append(f"{where}: source.computed must be a date (YYYY-MM-DD)")
|
||||
|
||||
|
||||
def check_short_name(tid, rec, errors):
|
||||
"""short_name is optional; where present it needs short_name_url, the page where it was seen in use."""
|
||||
name, url = rec.get("short_name"), rec.get("short_name_url")
|
||||
if "short_name" in rec:
|
||||
if not isinstance(name, str) or not name.strip():
|
||||
errors.append(f"{tid}: short_name must be a non-empty string (leave it out when no abbreviation is in use)")
|
||||
elif name != name.strip():
|
||||
errors.append(f"{tid}: short_name has a leading or trailing space")
|
||||
elif "." in name:
|
||||
errors.append(f"{tid}: short_name must be written without full stops (\"AT\", not \"A.T.\")")
|
||||
if "short_name_url" not in rec:
|
||||
errors.append(f"{tid}: short_name needs short_name_url, the page where it was seen in use")
|
||||
elif "short_name_url" in rec:
|
||||
errors.append(f"{tid}: short_name_url without short_name")
|
||||
if "short_name_url" in rec and not (isinstance(url, str) and url.startswith(("https://", "http://"))):
|
||||
errors.append(f"{tid}: short_name_url must be an http(s) URL")
|
||||
|
||||
|
||||
LINK_FIELDS = ("title", "publisher", "url")
|
||||
LINK_KEYS = {"title", "publisher", "url", "note"}
|
||||
|
||||
@@ -415,10 +433,11 @@ def main():
|
||||
continue
|
||||
trails.append(rec)
|
||||
|
||||
for field in ("id", "name", "short_name", "country", "regions",
|
||||
for field in ("id", "name", "country", "regions",
|
||||
"length_km", "tier", "designation"):
|
||||
if field not in rec or rec[field] in ("", None, []):
|
||||
errors.append(f"{tid}: missing required field {field}")
|
||||
check_short_name(tid, rec, errors)
|
||||
if rec.get("id") != tid:
|
||||
errors.append(f"{tid}: id {rec.get('id')!r} does not match directory name")
|
||||
if rec.get("country") not in ("US", "CA"):
|
||||
|
||||
Reference in new issue
Block a user