Put miles and feet first, and give the site a proper mark
Mirror to forge / mirror (push) Canceled after 0s
Validate / validate (push) Canceled after 0s
Validate / site (push) Canceled after 0s
Validate / deploy (push) Canceled after 0s

Units. Miles and feet now come first everywhere unless the reader
chooses kilometres and metres: paired figures, the time estimate, the
elevation profile, page descriptions and the map scale. The length
filter and the length scale use round mile steps (round kilometre steps
for a reader who chose them). The lists defined by length are now
"Under 100 miles" and "The longest" at 1,000 miles or more; the old
/lists/under-100-km/ address redirects. The records stay metric.

Branding. The tab icon was a bare red blaze that read as a red block;
it is now a mountain with a trail up it, with PNG sizes for browsers
and phones that need them. The home page opens with the mark, the name
and what the site offers. Link previews get a real 1200x630 image:
the old one was an SVG, which Reddit, Slack and iMessage do not draw.

The decorative contour lines now stay inside the content column and
thin out to nothing on every side, where they used to run to the right
edge of a wide window and stop dead at the bottom of the band.

Tests updated for the new trail counts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-14 20:37:14 -07:00
1 parent c7e8e58dce
commit 19fabadd49
27 files changed
+480 -189

No files matched your search

+21 -21
View File
@@ -77,15 +77,15 @@ def top_part(body):
class GlanceTest(unittest.TestCase):
def test_computed_rows_without_a_sourced_high_point(self):
t = text(glance_of(render(rec_with(elev()))))
self.assertIn("High point 2,000 m 6,562 ft Computed from the track.", t)
self.assertIn("Low point 500 m 1,640 ft Computed from the track.", t)
self.assertIn("High point 6,562 ft 2,000 m Computed from the track.", t)
self.assertIn("Low point 1,640 ft 500 m Computed from the track.", t)
# descent within a few percent of the climb is not shown
self.assertIn("Climb 3,000 m 9,843 ft Computed from the track, walking south to north.", t)
self.assertIn("Climb 9,843 ft 3,000 m Computed from the track, walking south to north.", t)
self.assertNotIn("Descent", t)
def test_descent_shown_when_it_differs(self):
t = text(glance_of(render(rec_with(elev(descent_m=1000)))))
self.assertIn("Descent: 1,000 m 3,281 ft", t)
self.assertIn("Descent: 3,281 ft 1,000 m", t)
self.assertIn("walking south to north", t)
self.assertFalse(elevation.show_descent(elev(ascent_m=1000, descent_m=951)))
self.assertTrue(elevation.show_descent(elev(ascent_m=1000, descent_m=949)))
@@ -93,11 +93,11 @@ class GlanceTest(unittest.TestCase):
def test_sourced_high_point_is_kept(self):
rec = rec_with(elev(), {"high_point": "Example Peak", "high_point_m": 2025, "checked": "2026-11-13"})
t = text(glance_of(render(rec)))
self.assertIn("High point Example Peak 2,025 m 6,644 ft", t)
self.assertIn("High point Example Peak 6,644 ft 2,025 m", t)
self.assertNotIn("2,000 m", t) # the computed highest does not replace it
# the computed low point and climb still appear, marked as computed
self.assertIn("Low point 500 m", t)
self.assertIn("Climb 3,000 m", t)
self.assertIn("Low point 1,640 ft 500 m", t)
self.assertIn("Climb 9,843 ft 3,000 m", t)
def test_sourced_name_without_an_elevation_stays_as_it_was(self):
rec = rec_with(elev(), {"high_point": "Example Peak", "checked": "2026-11-13"})
@@ -108,13 +108,13 @@ class GlanceTest(unittest.TestCase):
def test_sea_level_low_point(self):
data = elev(lowest={"m": 0, "lat": 43.0, "lon": -124.0})
t = text(glance_of(render(rec_with(data))))
self.assertIn("Low point 0 m 0 ft Sea level. Computed from the track.", t)
self.assertIn("Low point 0 ft 0 m Sea level. Computed from the track.", t)
self.assertIn("low point of sea level", elevation.summary_sentence(data))
def test_loop_climb_has_no_direction(self):
rec = rec_with(elev(), {"shape": "loop", "checked": "2026-11-13"})
t = text(glance_of(render(rec)))
self.assertIn("Climb 3,000 m 9,843 ft Computed from the track.", t)
self.assertIn("Climb 9,843 ft 3,000 m Computed from the track.", t)
self.assertNotIn("walking south to north", text(top_part(render(rec))))
@@ -148,7 +148,7 @@ class CaveatTest(unittest.TestCase):
self.assertIn("No profile is drawn", text(body))
self.assertIn(f"{parts} in the elevation sampling", text(body))
# the figures are still there
self.assertIn("Climb 3,000 m", text(glance_of(body)))
self.assertIn("Climb 9,843 ft 3,000 m", text(glance_of(body)))
class ProfileTest(unittest.TestCase):
@@ -170,8 +170,8 @@ class ProfileTest(unittest.TestCase):
def test_axes_in_both_units(self):
svg = str(elevation.profile_svg(elev()))
km = svg[svg.index('<g class="len__km">'):svg.index('<g class="len__mi">')]
mi = svg[svg.index('<g class="len__mi">'):]
mi = svg[svg.index('<g class="len__mi">'):svg.index('<g class="len__km">')]
km = svg[svg.index('<g class="len__km">'):]
self.assertIn("Distance along the track (km)", km)
self.assertIn("Elevation (m)", km)
self.assertIn("2,000", km) # a metre tick reaches the high point
@@ -181,15 +181,15 @@ class ProfileTest(unittest.TestCase):
# CSS shows one system, by the same data-units preference as lengths
with open(os.path.join(WEB, "assets", "style.css"), encoding="utf-8") as f:
css = f.read()
self.assertIn(".elev-profile .len__mi { display: none; }", css)
self.assertIn(':root[data-units="mi"] .elev-profile .len__mi { display: inline; }', css)
self.assertIn(':root[data-units="mi"] .elev-profile .len__km { display: none; }', css)
self.assertIn(".elev-profile .len__km { display: none; }", css)
self.assertIn(':root[data-units="km"] .elev-profile .len__km { display: inline; }', css)
self.assertIn(':root[data-units="km"] .elev-profile .len__mi { display: none; }', css)
def test_text_alternative_states_the_facts(self):
svg = str(elevation.profile_svg(elev()))
label = html.unescape(re.search(r'aria-label="([^"]*)"', svg).group(1))
for want in ("3,000 m (9,843 ft)", "100.0 km (62 mi)", "500 m (1,640 ft)",
"2,000 m (6,562 ft)", "walking south to north"):
for want in ("9,843 ft (3,000 m)", "62 mi (100.0 km)", "1,640 ft (500 m)",
"6,562 ft (2,000 m)", "walking south to north"):
self.assertIn(want, label, want)
# the same sentence is the visible caption
self.assertIn(label, text(render(rec_with(elev()))))
@@ -212,10 +212,10 @@ class AboutTest(unittest.TestCase):
for want in ("computed from the trail’s track and Example Model",
"A point was taken every 30 m along each part of the track",
"Example Model credit, as it gives it.",
"Highest point on the track 2,000 m", "At 40.00000, -105.00000",
"Lowest point on the track 500 m", "Total climb 3,000 m",
"Total descent 2,900 m", "Length sampled 100.0 km",
"Coverage 1.000", "Parts 2", "Part starts 50.0 km",
"Highest point on the track 6,562 ft 2,000 m", "At 40.00000, -105.00000",
"Lowest point on the track 1,640 ft 500 m", "Total climb 9,843 ft 3,000 m",
"Total descent 9,514 ft 2,900 m", "Length sampled 62.1 mi 100.0 km",
"Coverage 1.000", "Parts 2", "Part starts 31.1 mi 50.0 km",
"Computed 2026-11-13",
"Computed from a public elevation model, not measured on the ground."):
self.assertIn(want, t, want)
+20 -4
View File
@@ -59,7 +59,7 @@ class ExtraPagesTest(unittest.TestCase):
def test_all_routes_on_routes_page(self):
routes = [r for r in self.records if r["derived"]["kind"] == "route"]
self.assertEqual(len(routes), 34)
self.assertEqual(len(routes), 47)
page = read_out("routes/index.html")
import html as _html
text = _html.unescape(page)
@@ -140,6 +140,9 @@ class ExtraPagesTest(unittest.TestCase):
scale = re.search(r'<div class="list-head".*?</div>', results, re.S).group(0)
self.assertEqual(scale.count('class="len__km"'), 3, rel)
self.assertEqual(scale.count('class="len__mi"'), 3, rel)
# round in each unit, miles first
self.assertIn('<span class="len__mi">100</span><span class="len__km">100</span>', scale)
self.assertIn('<span class="len__mi">10,000 mi</span><span class="len__km">10,000 km</span>', scale)
for name in ("Length", "Time", "GPX", "Climb"):
self.assertIn(name, scale, rel)
for col in ("name", "length", "time", "climb"):
@@ -182,9 +185,22 @@ class ExtraPagesTest(unittest.TestCase):
# the map is in the tool, beside the list it filters
main = doc[doc.index('<div class="finder__main">'):]
self.assertLess(main.index('data-map="overview"'), main.index('<ol class="entries" id="entries">'))
steps = [int(v) for v in re.findall(r'<option value="(\d+)">', form[form.index('id="max"'):form.index("</select>", form.index('id="max"'))])]
self.assertGreaterEqual(steps[-1], max(r["length_km"] for r in self.records))
self.assertEqual(home.length_steps(self.records)[:11], list(home.LENGTH_STEPS))
longest_km = max(r["length_km"] for r in self.records)
maxsel = form[form.index('id="max"'):form.index("</select>", form.index('id="max"'))]
minsel = form[form.index('id="min"'):form.index("</select>", form.index('id="min"'))]
# the steps are round miles, miles first; the top step reaches the longest trail
steps = [int(v) for v in re.findall(r'<option value="(\d+)mi">', maxsel)]
self.assertGreaterEqual(steps[-1] * words.KM_PER_MI, longest_km)
self.assertEqual(steps, home.length_steps(self.records)[1:])
self.assertIn("100 mi &middot; 161 km", minsel)
self.assertEqual(home.length_steps(self.records)[:11], list(home.LENGTH_STEPS_MI))
# a reader who chose kilometres gets round kilometre steps (app.js builds them from data-steps-km)
km_steps = home.length_steps(self.records, "km")
self.assertEqual(km_steps[:11], list(home.LENGTH_STEPS_KM))
self.assertGreaterEqual(km_steps[-1], longest_km)
self.assertIn('data-steps-km="' + ",".join(map(str, km_steps)) + '"', form)
for n in home.LENGTH_STEPS_MI + home.LENGTH_STEPS_KM:
self.assertEqual(n % 5, 0, n)
def test_logos_page_shows_exactly_the_logo_files(self):
page = read_out("logos/index.html")
+7 -2
View File
@@ -109,12 +109,17 @@ class TimeTest(unittest.TestCase):
rec = fake(1, km=300) # 300 km at 20 to 30 km a day: 10 to 15 days
self.assertEqual(facets.time_days(rec), (10, 15, True))
self.assertEqual(facets.time_text(rec), "About 1 to 2 weeks")
self.assertEqual(facets.estimate_note(rec), "Estimated from the length, at 20 to 30 km (12 to 19 mi) a day.")
note = facets.estimate_note(rec) # miles first: both in the HTML, CSS orders them
self.assertTrue(note.startswith("Estimated from the length, at "))
self.assertLess(note.index('<span class="len__mi">12 to 19 mi</span>'),
note.index('<span class="len__km">20 to 30 km</span>'))
self.assertTrue(note.endswith(" a day."))
self.assertEqual(facets.time_band(rec), "two-weeks")
# cross-country is slower: 12 to 20 km a day
rec = fake(2, km=300, hike={"travel": "mostly-cross-country"})
self.assertEqual(facets.time_days(rec), (15, 25, True))
self.assertIn("12 to 20 km", facets.estimate_note(rec))
self.assertIn("7 to 12 mi", facets.estimate_note(rec))
self.assertEqual(facets.time_band(rec), "month")
def test_every_trail_has_a_time_and_its_label(self):
@@ -276,7 +281,7 @@ class BuiltVocabularyTest(unittest.TestCase):
n = len(re.findall(r'<li class="entry" ', doc))
self.assertEqual(n, len(records.load_records(ROOT)))
self.assertIn(f"<strong>{n}</strong> of {n} trails", doc)
self.assertIn(f"{n} long-distance trails", doc)
self.assertIn(f"{n} trails. Narrow them", doc)
def test_route_badges_link_to_the_routes_list(self):
for rel in ("index.html", "routes/index.html"):
+9 -8
View File
@@ -87,9 +87,10 @@ class FormatTest(unittest.TestCase):
def test_elevation_follows_the_unit_toggle(self):
e = str(words.elevation(2025))
# the same km/mi pair as lengths, so html[data-units] orders metres and feet too
# the same mi/km pair as lengths: feet first, and html[data-units="km"] puts metres first
self.assertIn('<span class="len__km">2,025 m</span>', e)
self.assertIn('<span class="len__mi">6,644 ft</span>', e)
self.assertLess(e.index("len__mi"), e.index("len__km"))
self.assertIn('class="len len--inline"', e)
def test_first_sentence(self):
@@ -109,7 +110,7 @@ class TrailPageTest(unittest.TestCase):
self.assertIn('href="https://trail.example/"', top)
self.assertIn("Official site", t)
for want in ("Time 5 to 7 months", "Season March to October", "Example Peak",
"2,025 m", "6,644 ft", "Shape End to end. South Gate, Arizona to North Gate, Utah",
"6,644 ft 2,025 m", "Shape End to end. South Gate, Arizona to North Gate, Utah",
"Terrain Forest, Alpine", "Permits A permit is needed for the national park section.",
"Not finished. Forty miles are still on roads."):
self.assertIn(want, t, want)
@@ -134,7 +135,7 @@ class TrailPageTest(unittest.TestCase):
for absent in ("Season March", "High point", "Terrain Alpine", "Permits", "Not finished", "Official site"):
self.assertNotIn(absent, t, absent)
# no summary: the lede is built from the record
self.assertIn("A trail of 100 km 62 mi in Arizona, United States.", t)
self.assertIn("A trail of 62 mi 100 km in Arizona, United States.", t)
about = render(rec)[render(rec).index('<details class="about-data"'):]
self.assertIn("The record names no page for these facts.", about)
@@ -143,11 +144,11 @@ class TrailPageTest(unittest.TestCase):
body = render(rec)
top = top_part(body)
t = text(top)
self.assertIn("A trail of 100 km 62 mi in Arizona, United States.", t)
self.assertIn("A trail of 62 mi 100 km in Arizona, United States.", t)
self.assertIn("Length", t)
self.assertIn("Where Arizona , United States", t)
# every trail has a time: here estimated from its 100 km, and labelled so
self.assertIn("Time About 4 to 5 days Estimated from the length, at 20 to 30 km (12 to 19 mi) a day.", t)
self.assertIn("Time About 4 to 5 days Estimated from the length, at 12 to 19 mi 20 to 30 km a day.", t)
self.assertIn("Season, terrain and walking are not on file for this trail yet.", t)
self.assertNotIn("Where the hiking facts come from", body)
# no track: the page says so plainly and points at the source
@@ -191,7 +192,7 @@ class TrailPageTest(unittest.TestCase):
# the partial warning above the buttons, and in the glance
self.assertLess(panel.index("notice--partial"), panel.index('<ul class="downloads">'))
self.assertIn("Partial GPX to download here", top)
self.assertIn("Track measures 60.0 km of 100 km published", text(top))
self.assertIn("Track measures 37.3 mi 60.0 km of 62 mi 100 km published", text(top))
def test_report_a_problem_stays_in_view(self):
top = top_part(render(sample_record("X Trail")))
@@ -232,8 +233,8 @@ class ListTest(unittest.TestCase):
cases = {
"national-scenic-trails": (fake(1, tier="national"), fake(2)),
"routes": (route, fake(2)),
"longest": (fake(1, km=2000), fake(2, km=1999)),
"under-100-km": (fake(1, km=99), fake(2, km=100)),
"longest": (fake(1, km=1609.35), fake(2, km=1609.3)),
"under-100-miles": (fake(1, km=160.9), fake(2, km=161)),
# by Time: stated, or estimated from the length
"a-week-or-less": (fake(1, hike={"days": [4, 7]}), fake(2, hike={"days": [20, 35]})),
"one-to-two-weeks": (fake(1, km=250), fake(2, km=100)),
+1 -1
View File
@@ -394,7 +394,7 @@ class RealDocumentsTest(unittest.TestCase):
counter = TableCounter()
counter.feed(md.render(read_doc("README.md")))
counter.close()
self.assertEqual(counter.counts, [104, 34])
self.assertEqual(counter.counts, [131, 47])
def test_readme_num_class_present(self):
self.assertIn('class="num"', md.render(read_doc("README.md")))
+5 -5
View File
@@ -90,7 +90,7 @@ class BuiltSiteTest(unittest.TestCase):
def test_one_detail_page_per_record(self):
found = [d for d in os.listdir(os.path.join(OUT, "trails"))
if os.path.isfile(os.path.join(OUT, "trails", d, "index.html"))]
self.assertEqual(len(self.records), 138)
self.assertEqual(len(self.records), 178)
self.assertEqual(sorted(found), sorted(r["id"] for r in self.records))
self.assertTrue(os.path.isfile(os.path.join(OUT, "index.html")))
@@ -175,7 +175,7 @@ class BuiltSiteTest(unittest.TestCase):
v = raw.get("verification", {})
if raw["source"].get("line_file") and v.get("verified") and abs(v.get("difference_percent", 0)) > 15:
expected.add(rec["id"])
self.assertEqual(len(expected), 15)
self.assertEqual(len(expected), 17)
self.assertIn("voyageur", expected)
for rec in self.records:
page = self.pages[rec["id"]]
@@ -186,8 +186,8 @@ class BuiltSiteTest(unittest.TestCase):
self.assertLess(panel.index("notice--partial"), panel.index('<ul class="downloads">'), rec["id"])
v = rec["verification"]
text = page_text(panel[:panel.index('<ul class="downloads">')])
self.assertIn(f"measures {v['measured_km']:,.1f} km against a published "
f"{rec['length_km']:,} km ({words.fmt_percent(v['difference_percent'])})", text)
self.assertIn(f"{v['measured_km']:,.1f} km against a published", text)
self.assertIn(f"{rec['length_km']:,} km ({words.fmt_percent(v['difference_percent'])})", text)
self.assertIn(re.sub(r"\s+", " ", rec["source"]["length_gap_note"]), text, rec["id"])
short = rec["id"] in expected and rec["verification"]["difference_percent"] < 0
glance = page[page.index('<section class="glance'):page.index("</section>", page.index('<section class="glance'))]
@@ -208,7 +208,7 @@ class BuiltSiteTest(unittest.TestCase):
self.assertEqual(row.count('class="entry__partial"'), 1 if tid in expected else 0, f"{rel}: {tid}")
if tid in expected:
rows_seen.add(tid)
self.assertRegex(page_text(row), r"Track measures [\d,.]+ km (of|against) [\d,]+ km published")
self.assertRegex(page_text(row), r"Track measures [\d,.]+ mi [\d,.]+ km (of|against) [\d,]+ mi [\d,.]+ km published")
entries = len(re.findall(r'<li class="entry" ', doc))
partial_rows = len(re.findall(r'<li class="entry" [^>]*data-partial="yes"', doc))
self.assertEqual(doc.count('class="entry__partial"'), partial_rows, rel)
+4 -4
View File
@@ -13,10 +13,10 @@ class RecordsTest(unittest.TestCase):
cls.recs = records.load_records()
def test_counts(self):
self.assertEqual(len(self.recs), 138)
self.assertEqual(sum(r["derived"]["kind"] == "route" for r in self.recs), 34)
self.assertEqual(sum(r["derived"]["kind"] == "designated" for r in self.recs), 104)
self.assertEqual(sum(r["derived"]["has_line"] for r in self.recs), 85)
self.assertEqual(len(self.recs), 178)
self.assertEqual(sum(r["derived"]["kind"] == "route" for r in self.recs), 47)
self.assertEqual(sum(r["derived"]["kind"] == "designated" for r in self.recs), 131)
self.assertEqual(sum(r["derived"]["has_line"] for r in self.recs), 97)
def test_sorted_by_id(self):
ids = [r["id"] for r in self.recs]
+2 -2
View File
@@ -134,7 +134,7 @@ class SortKeysTest(unittest.TestCase):
class ListDefaultsTest(unittest.TestCase):
def test_only_four_lists_open_in_another_order(self):
special = {lst.key: lst.sort for lst in browse.LISTS if lst.sort != "name"}
self.assertEqual(special, {"longest": "length-desc", "under-100-km": "length-asc",
self.assertEqual(special, {"longest": "length-desc", "under-100-miles": "length-asc",
"a-week-or-less": "time-asc", "one-to-two-weeks": "time-asc"})
for lst in browse.LISTS:
self.assertIn(lst.sort, facets.SORT_LABEL, lst.key)
@@ -143,7 +143,7 @@ class ListDefaultsTest(unittest.TestCase):
def test_members_come_in_the_list_order(self):
recs = [make("short", "Short", km=3000), make("long", "Long", km=5000), make("mid", "Mid", km=100)]
self.assertEqual(ids(browse.members(browse.by_key("longest"), recs)), ["long", "short"])
self.assertEqual(ids(browse.members(browse.by_key("under-100-km"),
self.assertEqual(ids(browse.members(browse.by_key("under-100-miles"),
[make("a", "A", km=90), make("b", "B", km=10)])), ["b", "a"])
+131
View File
@@ -0,0 +1,131 @@
"""Miles and feet come first, everywhere, until a reader chooses kilometres and metres.
These read the markup writers, the stylesheet and prefs.js; they do not need the built site.
"""
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 browse, home, words # noqa: E402
from test_hike import fake, render, top_part # noqa: E402
def read(*parts):
with open(os.path.join(WEB, *parts), encoding="utf-8") as f:
return f.read()
class DefaultOrderTest(unittest.TestCase):
def test_lengths_and_elevations_are_written_miles_and_feet_first(self):
for html_ in (words.length(1287), words.length(1287, "stack"), words.length(2.0, measured=True),
words.elevation(2025)):
self.assertLess(html_.index("len__mi"), html_.index("len__km"))
def test_trail_page_at_a_glance_reads_miles_first(self):
top = top_part(render(fake(1, km=100)))
self.assertLess(top.index('<span class="len__mi">62 mi</span>'),
top.index('<span class="len__km">100 km</span>'))
def test_list_row_reads_miles_first(self):
row = home.entry(fake(1, km=100))
self.assertLess(row.index('<span class="len__mi">62 mi</span>'),
row.index('<span class="len__km">100 km</span>'))
self.assertIn('data-km="100"', row) # sorting and filtering stay in kilometres
def test_footer_switch_lists_miles_first_and_selects_it(self):
src = read("olt", "layout.py")
self.assertIn('value="mi" checked><span>mi and ft first</span>', src)
self.assertLess(src.index("mi and ft first"), src.index("km and m first"))
self.assertIn('value="mi" checked><span>mi</span>', home.UNITS_TOGGLE)
self.assertLess(home.UNITS_TOGGLE.index(">mi<"), home.UNITS_TOGGLE.index(">km<"))
class StoredChoiceTest(unittest.TestCase):
def test_prefs_js_knows_only_km_as_the_opt_in(self):
js = read("assets", "prefs.js")
self.assertIn("units === 'km'", js)
self.assertIn("root.dataset.units = 'km'", js)
self.assertNotIn("=== 'mi'", js) # an old stored "mi" is simply miles
def test_app_js_treats_no_value_as_miles(self):
js = read("assets", "app.js")
self.assertIn("root.dataset.units !== 'km'", js)
self.assertIn("writePref('lh-units', value === 'km' ? 'km' : null)", js)
def test_css_flips_on_km_and_never_on_mi(self):
css = read("assets", "style.css")
self.assertNotIn('data-units="mi"', css)
self.assertIn(':root[data-units="km"] .len__km { order: -1; }', css)
self.assertIn(':root[data-units="km"] .len--short .len__km { display: inline; }', css)
self.assertIn(".len--short .len__km { display: none; }", css)
self.assertIn(':root[data-units="km"] .list-head__scale .len__km { display: inline; }', css)
self.assertIn(':root[data-units="km"] .loglen {', css)
# the length strip's ticks sit at 100, 1,000 and 10,000 miles by default, kilometres when chosen
self.assertIn("log(100 * 1.609344 / 50)", css)
self.assertIn(':root[data-units="km"] .list-head__scale > span:nth-child(1) { inset-inline-start: 10.8%; }', css)
def test_tick_positions_match_the_strip_scale(self):
import math
css = read("assets", "style.css")
pos = lambda km: math.log(km / 50) / math.log(600) * 100
for nth, mi in enumerate(home.SCALE_TICKS, 1):
m = re.search(r'\.list-head__scale > span:nth-child\(%d\) \{ inset-inline-start: ([\d.]+)%%' % nth, css)
self.assertAlmostEqual(float(m.group(1)), pos(mi * words.KM_PER_MI), delta=0.1)
m = re.search(r':root\[data-units="km"\] \.list-head__scale > span:nth-child\(%d\) \{ inset-inline-start: ([\d.]+)%%' % nth, css)
self.assertAlmostEqual(float(m.group(1)), pos(mi), delta=0.1)
class LengthListsTest(unittest.TestCase):
def test_renamed_lists(self):
under = browse.by_key("under-100-miles")
self.assertEqual(under.title, "Under 100 miles")
self.assertEqual(browse.path(under), "/lists/under-100-miles/")
self.assertNotIn("under-100-km", [lst.key for lst in browse.LISTS])
self.assertIn("100 miles (161 km)", under.blurb)
longest = browse.by_key("longest")
self.assertIn("1,000 miles (1,609 km) or more", longest.blurb)
def test_membership_is_by_the_mile_figure(self):
under, longest = browse.by_key("under-100-miles"), browse.by_key("longest")
edge = 100 * words.KM_PER_MI
self.assertTrue(under.test(fake(1, km=edge - 0.01)))
self.assertFalse(under.test(fake(1, km=edge)))
self.assertTrue(under.test(fake(1, km=120))) # 75 miles: under 100 miles, though over 100 km
edge = 1000 * words.KM_PER_MI
self.assertTrue(longest.test(fake(1, km=edge)))
self.assertFalse(longest.test(fake(1, km=edge - 0.01)))
self.assertFalse(longest.test(fake(1, km=1500))) # 932 miles
def test_the_hide_rule_is_kept(self):
self.assertFalse(browse.is_shown(3, 100))
self.assertFalse(browse.is_shown(80, 100))
self.assertTrue(browse.is_shown(4, 100))
class RoundStepsTest(unittest.TestCase):
def test_steps_are_round_in_their_own_unit(self):
for unit, steps in (("mi", home.LENGTH_STEPS_MI), ("km", home.LENGTH_STEPS_KM)):
self.assertEqual(list(steps), sorted(steps))
for n in steps:
self.assertEqual(n % 5, 0, (unit, n))
recs = [fake(1, km=60), fake(2, km=10945)]
self.assertEqual(home.length_steps(recs, "mi")[-1], 8000) # 6,801 miles
self.assertEqual(home.length_steps(recs, "km")[-1], 20000) # above 10,945 km
self.assertEqual(home.step_value(100, "mi"), "100mi")
self.assertEqual(home.step_label(100, "mi"), "100 mi &middot; 161 km")
self.assertEqual(home.step_label(100, "km"), "100 km &middot; 62 mi")
def test_filter_script_reads_steps_in_both_units(self):
js = read("assets", "app.js")
self.assertIn("(mi|km)", js)
self.assertIn("data-steps-' + unit", js)
self.assertIn("dataset.km", js) # rows are still compared in kilometres
if __name__ == "__main__":
unittest.main()