"""The first screen: what the top of the trail page and the home page hold, the home page's lists
(read from data), the header's Lists item, the tables that stack on a phone, and the maps' static
drawings (olt/sketch.py) with the script's handover from them.
Pages are rendered one at a time; the site is not built. The sketch reads the track files of a
site directory, so those are written to a temporary one here. The behaviour of the script in a
browser was checked by driving the pages (see the changelog); these pin what its source promises.
"""
import json
import os
import re
import sys
import tempfile
import unittest
WEB = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ROOT = os.path.dirname(WEB)
sys.path.insert(0, WEB)
sys.path.insert(0, os.path.join(ROOT, "tools"))
from olt import browse, common, datafiles, home, layout, pagekit, records, site, sketch, trail # noqa: E402
SITE = site.load()
def read(*parts):
with open(os.path.join(*parts), encoding="utf-8") as f:
return f.read()
def load(tid):
return records.load_record(ROOT, tid)
class HomePageTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.recs = records.load_records(ROOT)
cls.body = home.render(cls.recs, SITE, ROOT)
def test_the_hero_no_longer_repeats_the_site_mark_or_the_strip_of_words(self):
hero = self.body[:self.body.index('class="container home"')]
self.assertNotIn("lockup", hero)
self.assertNotIn("hero__tags", hero)
self.assertNotIn("(.*?) ', row)
self.assertEqual(titles, [browse.by_key(k).title for k in keys])
self.assertTrue(row.rstrip().endswith(""))
self.assertIn('All lists', row)
self.assertNotIn("Hiking in", row)
# a different file gives a different row: the set is not a constant of the generator
other = home.home_picks([{"key": "loops", "home": 2}, {"key": "routes", "home": 1}, {"key": "canada"}])
self.assertEqual(other, ["routes", "loops"])
self.assertEqual(re.findall(r'