Files
longhikes/tools/tests/test_common_name.py
swaitsandClaude Fable 5.2 5b80fccd1e
Mirror to forge / mirror (push) Canceled after 0s
Validate / validate (push) Canceled after 0s
Validate / history (push) Canceled after 0s
Validate / site (push) Canceled after 0s
Validate / deploy (push) Canceled after 0s
Say what each page is in the words people search with, and mark up the facts
A whole-site search audit found clean foundations and three gaps: titles
without the words people search for, no structured data on trail pages,
and trails that did not link to each other.

- Trail titles carry the name hikers use, the abbreviation, the length
  and what the page offers; "GPX" only where the page has one. A new
  optional `common_name` field holds the name hikers use (13 records).
- Descriptions are built from each record, at most 155 characters.
- Place and list pages are titled for what they are; heading levels no
  longer jump.
- Trail pages link to similar and related trails and to the lists they
  belong to. Every trail has at least three links from other trails.
- JSON-LD on every page: a Place for each trail, breadcrumbs, item lists
  on list and place pages, WebSite and Organization on the home page, a
  fuller Dataset on the data page.
- A social card per trail, a changelog feed, `lastmod` in the sitemap from
  record dates, `noindex` on the 404 and on raw per-trail files, a
  favicon and an `llms.txt` listing the data files and licences.
- The "Considered and left out" page has its spacing fixed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 14:57:30 -07:00

46 lines
1.4 KiB
Python

"""Tests for the common_name check 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
import trail_history as H # noqa: E402
def check(rec):
errors = []
V.check_common_name("t", rec, errors)
return errors
class CommonNameTest(unittest.TestCase):
def test_none_is_valid(self):
self.assertEqual(check({"name": "Appalachian National Scenic Trail"}), [])
def test_a_different_name_is_valid(self):
self.assertEqual(check({"name": "Appalachian National Scenic Trail", "common_name": "Appalachian Trail"}), [])
def test_must_be_a_clean_string(self):
for bad in ("", " ", " Appalachian Trail", "Appalachian Trail ", 7, ["AT"]):
self.assertTrue(check({"name": "x", "common_name": bad}), repr(bad))
def test_must_differ_from_name(self):
errors = check({"name": "Long Trail", "common_name": "Long Trail"})
self.assertEqual(len(errors), 1)
self.assertIn("repeats name", errors[0])
def test_is_a_field_that_needs_history(self):
self.assertIn("common_name", H.SCHEMA_FIELDS)
self.assertNotIn("common_name", H.NOT_FACTS)
if __name__ == "__main__":
unittest.main()