Files
longhikes/tools/tests/test_length_facts.py
T
swaitsandClaude Fable 5.2 8637181a2b
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
Make a trail's length one end-to-end walk, and put the map and the trails in the first screen
Lengths and what belongs:
- A trail's length is now the end-to-end length of its canonical path: one
  branch at a split, no side trails, no system totals. A holder's larger
  figure and the built length of an unfinished trail are separate fields
  (`system_km`, `system_note`, `built_km`), shown under the length.
- Corrected: Florida Trail 1,500 to 1,130 mi, American Discovery Trail
  6,800 to 5,008 mi, Ozark Trail to 230 mi, General Crook Trail to 138 mi,
  Sheltowee Trace to 343 mi, Allegheny Trail to 316 mi, Great Eastern
  Trail to 1,800 mi.
- The Florida Trail's and the Ice Age Trail's main tracks are re-cut as
  one walk; the other branches are alternates.
- A trail must be walkable from end to end today. Nine trails that are
  not, are a network, or fall under the floor move to the "Considered and
  left out" list. The Bayou State Trail is added. 196 trails.

Pages:
- The trail page puts the map and At a glance directly under the title;
  the home page drops its oversized hero and shows the trails and the map
  at once. Place and list pages put the list beside the map.
- Every map starts by itself once the page is ready, over a drawing of
  the tracks that is in the page from the first paint.
- Lists is in the header. The home page shows ten lists chosen in
  `collections.toml`. Tables have equal columns and stack on a phone.

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

101 lines
3.6 KiB
Python

"""Tests for system_km, system_note and built_km in tools/validate.py.
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 trail_history as H # noqa: E402
import validate as V # noqa: E402
def check(**fields):
rec = {"length_km": 1818, "hike": {"unfinished": "About 290 miles are built."}}
rec.update(fields)
errors = []
V.check_length_facts("t", rec, errors)
return errors
class SystemFigureTest(unittest.TestCase):
def test_a_larger_figure_with_its_note_passes(self):
self.assertEqual(check(system_km=2549, system_note="both corridors and the connectors"), [])
def test_a_record_without_them_passes(self):
self.assertEqual(check(), [])
def test_the_figure_must_be_larger_than_the_length(self):
for km in (1818, 1000):
errors = check(system_km=km, system_note="the whole system")
self.assertEqual(len(errors), 1, km)
self.assertIn("greater than length_km", errors[0])
def test_the_figure_needs_its_note(self):
for note in (None, "", " "):
fields = {"system_km": 2549}
if note is not None:
fields["system_note"] = note
errors = check(**fields)
self.assertEqual(len(errors), 1, repr(note))
self.assertIn("system_note", errors[0])
def test_a_note_alone_is_refused(self):
errors = check(system_note="the whole system")
self.assertEqual(len(errors), 1)
self.assertIn("system_km is not", errors[0])
def test_the_note_does_not_repeat_the_word_the_page_adds(self):
errors = check(system_km=2549, system_note="Counting both corridors")
self.assertEqual(len(errors), 1)
self.assertIn("counting", errors[0])
def test_the_figure_is_a_whole_number_of_kilometres(self):
for bad in (2549.5, "2549", True, 0, -5):
errors = check(system_km=bad, system_note="the whole system")
self.assertEqual(len(errors), 1, repr(bad))
self.assertIn("whole number", errors[0])
class BuiltFigureTest(unittest.TestCase):
def test_a_built_length_on_an_unfinished_trail_passes(self):
self.assertEqual(check(built_km=467), [])
def test_it_cannot_exceed_the_length(self):
errors = check(built_km=1819)
self.assertEqual(len(errors), 1)
self.assertIn("cannot exceed length_km", errors[0])
self.assertEqual(check(built_km=1818), [])
def test_it_belongs_only_on_an_unfinished_trail(self):
for hike in ({}, {"unfinished": " "}):
errors = check(built_km=467, hike=hike)
self.assertEqual(len(errors), 1)
self.assertIn("hike.unfinished", errors[0])
rec = {"length_km": 500, "built_km": 400}
errors = []
V.check_length_facts("t", rec, errors)
self.assertEqual(len(errors), 1)
def test_it_is_a_whole_number_of_kilometres(self):
for bad in (290.5, "290", False, 0):
errors = check(built_km=bad)
self.assertEqual(len(errors), 1, repr(bad))
self.assertIn("whole number", errors[0])
class HistoryFieldsTest(unittest.TestCase):
def test_the_new_fields_are_known_to_the_history_and_are_facts(self):
for name in ("system_km", "system_note", "built_km"):
self.assertIn(name, H.SCHEMA_FIELDS)
self.assertTrue(H.is_fact(name), name)
self.assertIn(name, H.FACTS_TEXT)
if __name__ == "__main__":
unittest.main()