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>
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
"""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()
|