"""A trail with an abbreviation shows it, shared or not; a trail without one shows the site's mark. Fixtures only; no real trail's abbreviation is pinned. """ import copy import os import re import sys import unittest WEB = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, WEB) sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from olt import common, home, site, trail # noqa: E402 from test_pages import sample_record # noqa: E402 def rec(tid, abbr="PCT", *, tier="regional", kind="designated", km=100, name=None): r = copy.deepcopy(sample_record(name or tid)) r.update(id=tid, tier=tier, length_km=km) r["derived"]["kind"] = kind r["derived"]["length_mi"] = round(km / 1.609344) if abbr is None: del r["short_name"] else: r["short_name"] = abbr r["short_name_url"] = f"https://www.example.org/{tid}" return r class PageTest(unittest.TestCase): def setUp(self): self.a = rec("a", name="Big Trail") self.b = rec("b", name="Small Trail") # shares the abbreviation: both show it self.none = rec("none", None, name="Plain Trail") self.site = site.Site("N", "T") def page(self, r): return trail.render(r, self.site)[2] def test_trail_page_shows_it_for_every_trail_that_has_it(self): for r in (self.a, self.b): self.assertRegex(self.page(r), r'