Files
longhikes/web/tests/test_left_out.py
T
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

107 lines
3.7 KiB
Python

"""Tests for the Considered and left out page (web/olt/leftout.py).
Run from the repository root:
python3 -m unittest discover -s web/tests
"""
import os
import sys
import unittest
WEB = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ROOT = os.path.dirname(WEB)
sys.path.insert(0, WEB)
from olt import leftout, seo, site # noqa: E402
ENTRIES = [
{
"id": "waiting-trail",
"name": "Waiting Trail",
"country": "US",
"regions": ["KY"],
"length_mi": 120,
"length_km": 193,
"length_note": "120 miles planned",
"reason": "waiting",
"note": "Only part of it is built.",
"source_url": "https://example.org/waiting",
"decided": "2026-11-16",
"was_listed": False,
"waiting_for": "Enough of it is built to walk through.",
},
{
"id": "example-trail",
"name": "Example & Trail",
"country": "US",
"regions": ["PA", "MD"],
"length_mi": 42.0,
"length_km": 68,
"reason": "below-floor",
"note": "The holder gives it as 42 miles.",
"source_url": "https://example.org/example?a=1&b=2",
"decided": "2026-11-14",
"was_listed": True,
},
]
class PageTest(unittest.TestCase):
def setUp(self):
self.site = site.Site(name="Long Hikes", tagline="Tagline",
base_url="https://example.org",
repo_url="https://github.com/swaits/longhikes")
self.title, self.description, self.body = leftout.left_out_page(
ENTRIES, self.site, ROOT)
self.text = str(self.body)
def test_title(self):
self.assertEqual(self.title, "Trails Considered and Left Out, and Why")
def test_opening_is_generated_from_the_entries(self):
self.assertIn("lists 2 trails and routes", self.text)
self.assertIn("1 of them was listed here once", self.text)
self.assertIn("open an issue", self.text)
def test_grouped_by_reason_in_order(self):
self.assertLess(self.text.index("Below the 50 mile floor"),
self.text.index("Waiting"))
def test_entry_facts_and_escaping(self):
self.assertIn("Example &amp; Trail", self.text)
self.assertIn("Pennsylvania", self.text)
self.assertIn("Maryland", self.text)
self.assertIn("42 mi", self.text)
self.assertIn("68 km", self.text)
self.assertIn("The holder gives it as 42 miles.", self.text)
self.assertIn('datetime="2026-11-14"', self.text)
self.assertIn('href="https://example.org/example?a=1&amp;b=2"', self.text)
def test_once_listed_mark(self):
self.assertIn("Once listed here", self.text)
self.assertEqual(self.text.count("Once listed here"), 1)
def test_waiting_shows_what_would_change_it(self):
self.assertIn("Enough of it is built to walk through.", self.text)
self.assertIn("120 miles planned", self.text)
def test_no_length_shows_nothing_made_up(self):
entries = [dict(ENTRIES[1])]
del entries[0]["length_mi"], entries[0]["length_km"]
_, _, body = leftout.left_out_page(entries, self.site, ROOT)
self.assertNotIn("len__mi", str(body))
def test_sitemap_includes_the_page(self):
self.assertIn("/left-out/", seo.all_paths([], []))
def test_the_real_file_loads_sorted(self):
entries = leftout.load_entries(ROOT)
self.assertGreaterEqual(len(entries), 30)
names = [e["name"].lower() for e in entries]
self.assertEqual(names, sorted(names))
reasons = {e["reason"] for e in entries}
self.assertTrue(reasons <= set(leftout.REASON_ORDER))
if __name__ == "__main__":
unittest.main()