Add 19 trails and 20 tracks, record stated permission, and remove the C&O Canal Towpath
A deeper, region-by-region search of the web added 14 official trails and 4 routes. The Hoosier Heritage Trail was added at its association's request (issue 2) with the association's own track, shared by written permission. - New licence value `stated-permission`, with the quoted words, who gave them, when and where as fields of the record, shown on the trail page and carried in the GPX description. - Tracks from OpenStreetMap or the Forest Service's open trail data for eleven of the new trails and seven existing ones. `tools/osm_track.py` can join several relations and leave ways out by name. - The C&O Canal Towpath is removed: the rule leaves out canal towpaths. - The Grand Enchantment Trail is recorded as a route by its author, with no track. - Corrections to the Finger Lakes, Ozark Highlands, Eastern Continental and Knobstone records, checked against the pages they cite. - Site: the list pages' own units switch is gone in favour of the header one; the map switch and a swapped length range stay in step with the page. - CHANGELOG.md brought up to date from the site's opening to today. 204 trails: 147 official trails and 57 routes; 126 have a track. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
c11a72a7dd
commit
d34a9617cd
127 files changed
+2612
-358
No files matched your search
+13
-3
@@ -53,7 +53,7 @@
|
||||
if (value === 'km') root.dataset.units = 'km';
|
||||
else delete root.dataset.units;
|
||||
writePref('lh-units', value === 'km' ? 'km' : null);
|
||||
syncRadios('input[name="units"], input[name="units-list"]', value === 'km' ? 'km' : 'mi');
|
||||
syncRadios('input[name="units"]', value === 'km' ? 'km' : 'mi');
|
||||
document.dispatchEvent(new Event('olt:units'));
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
|
||||
function syncPrefControls() {
|
||||
syncRadios('input[name="theme"]', root.dataset.theme || 'auto');
|
||||
syncRadios('input[name="units"], input[name="units-list"]', milesFirst() ? 'mi' : 'km');
|
||||
syncRadios('input[name="units"]', milesFirst() ? 'mi' : 'km');
|
||||
}
|
||||
|
||||
/* Bring the page back in step with the stored choices, and the switches in
|
||||
@@ -105,7 +105,7 @@
|
||||
document.querySelectorAll('input[name="theme"]').forEach(function (input) {
|
||||
input.addEventListener('change', function () { if (input.checked) setTheme(input.value); });
|
||||
});
|
||||
document.querySelectorAll('input[name="units"], input[name="units-list"]').forEach(function (input) {
|
||||
document.querySelectorAll('input[name="units"]').forEach(function (input) {
|
||||
input.addEventListener('change', function () { if (input.checked) setUnits(input.value); });
|
||||
});
|
||||
darkQuery.addEventListener('change', function () {
|
||||
@@ -1033,6 +1033,9 @@
|
||||
if (base) {
|
||||
switcher = basemapControl();
|
||||
map.addControl(switcher, 'top-left');
|
||||
/* The choice may have changed while the map was loading (another tab,
|
||||
or Back): the change event came before the map was ready to follow it. */
|
||||
applyBasemap();
|
||||
}
|
||||
mapCorners();
|
||||
});
|
||||
@@ -1544,6 +1547,13 @@
|
||||
var v = p.get(name) || '';
|
||||
el[name].value = hasOption(el[name], v) ? v : nearestStep(el[name], stepKm(v));
|
||||
});
|
||||
/* An address that gives them the wrong way round is rewritten by apply()
|
||||
with the shorter one first: the controls say the same. */
|
||||
if (stepKm(el.min.value) > stepKm(el.max.value) && stepKm(el.max.value)) {
|
||||
var low = el.max.value, high = el.min.value;
|
||||
el.min.value = hasOption(el.min, low) ? low : nearestStep(el.min, stepKm(low));
|
||||
el.max.value = hasOption(el.max, high) ? high : nearestStep(el.max, stepKm(high));
|
||||
}
|
||||
if (el.month) {
|
||||
var month = p.get('month') || '';
|
||||
el.month.value = hasOption(el.month, month) ? month : '';
|
||||
|
||||
@@ -1137,8 +1137,6 @@ html:not(.js) .js-only { display: none !important; }
|
||||
}
|
||||
.key li { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
|
||||
.results-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
|
||||
.results-units { margin: 0; padding: 0; border: 0; }
|
||||
.seg--small span { min-block-size: 2.75rem; min-inline-size: 2.75rem; }
|
||||
.field__label--sub { margin-block-start: var(--space-2); }
|
||||
|
||||
/* Without JavaScript the list is complete and readable; the controls that need it are hidden. */
|
||||
|
||||
+3
-1
@@ -218,7 +218,9 @@ def build_trail(rec, out_dir, code_mtime, force, stats):
|
||||
stats.processed += 1
|
||||
gpx_args = dict(url=src.get("url", ""), attribution=src.get("attribution", ""),
|
||||
licence=src.get("licence", ""), licence_text=src.get("licence_text", ""),
|
||||
creator=gpx_creator())
|
||||
creator=gpx_creator(),
|
||||
permission=({k: src[k] for k in ("permission_quote", "permission_by", "permission_date", "permission_url")
|
||||
if k in src} if src.get("licence") == "stated-permission" else None))
|
||||
maps = []
|
||||
if "line" in files:
|
||||
built = build_set(tid, "line", os.path.join(ROOT, files["line"]), tid,
|
||||
|
||||
+4
-1
@@ -411,12 +411,15 @@ def line_licence_rows(records, repo_root):
|
||||
recs = by_licence[lic]
|
||||
label = words.label(words.LICENCES, lic)
|
||||
n = len(recs)
|
||||
what = f"Tracks licensed {esc(label)}: {n} record{'s' if n != 1 else ''}"
|
||||
what = (f"Tracks shared with permission: {n} record{'s' if n != 1 else ''}" if lic == "stated-permission"
|
||||
else f"Tracks licensed {esc(label)}: {n} record{'s' if n != 1 else ''}")
|
||||
if n <= 3:
|
||||
links = ", ".join(f'<a href="{esc(common.trail_path(r))}">{common.name(r)}</a>' for r in recs)
|
||||
what += f" ({links})"
|
||||
what = Markup(what)
|
||||
terms = Markup(f'{esc(label)} <code class="raw">{esc(lic)}</code>; credit as named in each record and its release.txt')
|
||||
if lic in words.LICENCE_NOTES:
|
||||
terms = Markup(f'{esc(words.LICENCE_NOTES[lic])} <code class="raw">{esc(lic)}</code>; credit as named in each record and its release.txt')
|
||||
rows.append((what, terms, _licence_text_url(lic, repo_root)))
|
||||
return rows
|
||||
|
||||
|
||||
+15
-2
@@ -265,13 +265,26 @@ def _num(v):
|
||||
|
||||
|
||||
def gpx_text(parts, name, url="", attribution="", licence="", licence_text="",
|
||||
creator="long-trails dataset"):
|
||||
"""GPX 1.1 with one <trk> and one <trkseg> per part."""
|
||||
creator="long-trails dataset", permission=None):
|
||||
"""GPX 1.1 with one <trk> and one <trkseg> per part.
|
||||
|
||||
`permission` is the source's stated-permission fields (permission_quote, permission_by,
|
||||
permission_date, permission_url) when the licence is stated-permission."""
|
||||
desc = []
|
||||
if attribution:
|
||||
desc.append(f"Attribution: {attribution}")
|
||||
if licence_text:
|
||||
desc.append(f"Licence: {licence_text}")
|
||||
if permission and permission.get("permission_quote"):
|
||||
said = f'Permission: "{permission["permission_quote"]}"'
|
||||
if permission.get("permission_by"):
|
||||
said += f" Said by {permission['permission_by']}"
|
||||
if permission.get("permission_date"):
|
||||
said += f" on {permission['permission_date']}"
|
||||
said += "."
|
||||
if permission.get("permission_url"):
|
||||
said += f" Read at {permission['permission_url']}"
|
||||
desc.append(said)
|
||||
elif licence:
|
||||
desc.append(f"Licence: {licence}")
|
||||
out = [
|
||||
|
||||
+1
-9
@@ -371,14 +371,6 @@ def list_head(sort_key="name"):
|
||||
</div>"""
|
||||
|
||||
|
||||
UNITS_TOGGLE = """<fieldset class="results-units">
|
||||
<legend class="vh">Lengths</legend>
|
||||
<div class="seg seg--small">
|
||||
<label><input type="radio" name="units-list" value="mi" checked><span>mi</span></label>
|
||||
<label><input type="radio" name="units-list" value="km"><span>km</span></label>
|
||||
</div>
|
||||
</fieldset>"""
|
||||
|
||||
# The order a saved list was made in: offered first on the Saved page only,
|
||||
# where app.js numbers the rows (data-order) in the order they were saved.
|
||||
SAVED_ORDER = ("saved", "Order saved")
|
||||
@@ -470,7 +462,7 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_
|
||||
else:
|
||||
count = f'<p class="results-count"><strong>{total}</strong> {noun}</p>'
|
||||
empty = ""
|
||||
tools = sort_select(default_sort, saved=saved) + "\n " + UNITS_TOGGLE
|
||||
tools = sort_select(default_sort, saved=saved)
|
||||
dflt = SAVED_ORDER[0] if saved else default_sort
|
||||
return Markup(f"""<div class="results" data-sortable data-default-sort="{esc(dflt)}">
|
||||
<div class="results-head">
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ THEMES = (("auto", "Auto"), ("light", "Light"), ("dark", "Dark"))
|
||||
def prefs():
|
||||
"""The reader's two display choices, at the right of the header on every page.
|
||||
|
||||
Units: a two-way switch, mi or km first (radios named "units", as every
|
||||
Units: a two-way switch, mi or km first (radios named "units", the only
|
||||
units switch on the site; app.js keeps them in step and fires olt:units).
|
||||
Theme: a small menu built from <details>, its button showing the theme in
|
||||
use (its icon, and its name where there is room); the menu holds the three
|
||||
|
||||
+15
-2
@@ -575,6 +575,8 @@ def downloads_panel(rec):
|
||||
licence_html = Markup(f'{licence_html}; OpenStreetMap parts {ext_link(words.LICENCE_URLS["ODbL-1.0"], "ODbL 1.0")}')
|
||||
osm_note = ("<p class=\"note\">Tracks from OpenStreetMap need the credit “© OpenStreetMap contributors” "
|
||||
"and stay under the ODbL (share-alike).</p>") if "ODbL" in src.get("attribution", "") + licence else ""
|
||||
licence_note = (f'<p class="note">{esc(words.LICENCE_NOTES[licence])}</p>'
|
||||
if licence in words.LICENCE_NOTES else "")
|
||||
release = (f'<p class="note"><a href="/trails/{esc(rec["id"])}/release.txt">release.txt</a>: '
|
||||
f"the source, licence and date the track files came from.</p>"
|
||||
if rec["derived"].get("release") else "")
|
||||
@@ -592,7 +594,7 @@ def downloads_panel(rec):
|
||||
<button class="button button--quiet" type="button" data-copy="#credit-text" data-copy-status="#credit-done" aria-describedby="credit-label" hidden>Copy credit</button>
|
||||
</div>
|
||||
<p class="credit__done" id="credit-done" role="status"></p>
|
||||
{osm_note}
|
||||
{osm_note}{licence_note}
|
||||
</div>
|
||||
{release}
|
||||
</div>
|
||||
@@ -971,7 +973,18 @@ def source_block(rec):
|
||||
]
|
||||
if src.get("decision") or src.get("decision_text"):
|
||||
rows.append(fact("Decision", src.get("decision_text", "") or words.DECISIONS.get(src.get("decision", ""), src.get("decision", ""))))
|
||||
licence_text = (f'<h3 class="block__sub">What the source says</h3>{record_text(src["licence_text"])}'
|
||||
licence_note = (f'<p>{esc(words.LICENCE_NOTES[licence])}</p>' if licence in words.LICENCE_NOTES else "")
|
||||
permission = ""
|
||||
if licence == "stated-permission" and src.get("permission_quote"):
|
||||
url = src.get("permission_url", "")
|
||||
permission = f"""<figure class="quote">
|
||||
<blockquote{f' cite="{esc(url)}"' if url else ""}><p>{esc(src["permission_quote"])}</p></blockquote>
|
||||
<figcaption>
|
||||
<p class="quote__who">Said by {esc(src.get("permission_by", ""))} on {esc(src.get("permission_date", ""))}.</p>
|
||||
{f'<p>Read at {ext_link(url)}.</p>' if url else ""}
|
||||
</figcaption>
|
||||
</figure>"""
|
||||
licence_text = (f'<h3 class="block__sub">What the source says</h3>{licence_note}{Markup(permission)}{record_text(src["licence_text"])}'
|
||||
'<p class="note">With the page it was read on. Not legal advice.</p>') if src.get("licence_text") else ""
|
||||
return block("source-title", "Source and licence", facts(*rows) + Markup(licence_text))
|
||||
|
||||
|
||||
@@ -64,11 +64,17 @@ LICENCES = {
|
||||
"CC-BY-4.0": "CC BY 4.0",
|
||||
"CC-BY": "CC BY",
|
||||
"ODbL-1.0": "ODbL 1.0",
|
||||
"stated-permission": "Shared with permission",
|
||||
"CC-BY-NC-ND-4.0": "CC BY-NC-ND 4.0",
|
||||
"none-stated": "None stated",
|
||||
"restricted": "Restricted",
|
||||
"unknown": "Unknown",
|
||||
}
|
||||
LICENCE_NOTES = {
|
||||
"stated-permission": ("Shared with permission. The holder has said in writing that this track may be "
|
||||
"shared; the statement is quoted below. It is not public domain and not a "
|
||||
"Creative Commons licence."),
|
||||
}
|
||||
LICENCE_URLS = {
|
||||
"us-gov-public-domain": "https://www.usa.gov/government-works",
|
||||
"CC-BY-4.0": "https://creativecommons.org/licenses/by/4.0/",
|
||||
|
||||
@@ -60,7 +60,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), 52)
|
||||
self.assertEqual(len(routes), 57)
|
||||
page = read_out("routes/index.html")
|
||||
import html as _html
|
||||
text = _html.unescape(page)
|
||||
@@ -137,8 +137,9 @@ class ExtraPagesTest(unittest.TestCase):
|
||||
doc = read_out(rel)
|
||||
results = doc[doc.index('<div class="results"'):]
|
||||
for part in ('<div class="list-head" aria-hidden="true">', '<ol class="entries"',
|
||||
'name="units-list"', '<ul class="key"', "Sort by", 'data-sort-select'):
|
||||
'<ul class="key"', "Sort by", 'data-sort-select'):
|
||||
self.assertIn(part, results, f"{rel}: {part}")
|
||||
self.assertNotIn('name="units-list"', doc, rel) # the header's switch is the only one
|
||||
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)
|
||||
@@ -232,7 +233,9 @@ class ExtraPagesTest(unittest.TestCase):
|
||||
for lic in {r["source"]["licence"] for r in lines}:
|
||||
n = sum(1 for r in lines if r["source"]["licence"] == lic)
|
||||
label = html.escape(words.label(words.LICENCES, lic), quote=True)
|
||||
self.assertIn(f"Tracks licensed {label}: {n} record", page, lic)
|
||||
what = (f"Tracks shared with permission: {n} record" if lic == "stated-permission"
|
||||
else f"Tracks licensed {label}: {n} record")
|
||||
self.assertIn(what, page, lic)
|
||||
for name in ("trails.json", "overview.geojson"):
|
||||
self.assertRegex(page, rf'<a href="/data/{re.escape(name)}">')
|
||||
for name in ("all-gpx.zip", "all-geojson.zip"):
|
||||
|
||||
@@ -394,7 +394,7 @@ class RealDocumentsTest(unittest.TestCase):
|
||||
counter = TableCounter()
|
||||
counter.feed(md.render(read_doc("README.md")))
|
||||
counter.close()
|
||||
self.assertEqual(counter.counts, [134, 52])
|
||||
self.assertEqual(counter.counts, [147, 57])
|
||||
|
||||
def test_readme_num_class_present(self):
|
||||
self.assertIn('class="num"', md.render(read_doc("README.md")))
|
||||
|
||||
@@ -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), 186)
|
||||
self.assertEqual(len(self.records), 204)
|
||||
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), 20)
|
||||
self.assertEqual(len(expected), 25)
|
||||
self.assertIn("voyageur", expected)
|
||||
for rec in self.records:
|
||||
page = self.pages[rec["id"]]
|
||||
|
||||
@@ -13,10 +13,10 @@ class RecordsTest(unittest.TestCase):
|
||||
cls.recs = records.load_records()
|
||||
|
||||
def test_counts(self):
|
||||
self.assertEqual(len(self.recs), 186)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "route" for r in self.recs), 52)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "designated" for r in self.recs), 134)
|
||||
self.assertEqual(sum(r["derived"]["has_line"] for r in self.recs), 107)
|
||||
self.assertEqual(len(self.recs), 204)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "route" for r in self.recs), 57)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "designated" for r in self.recs), 147)
|
||||
self.assertEqual(sum(r["derived"]["has_line"] for r in self.recs), 126)
|
||||
|
||||
def test_sorted_by_id(self):
|
||||
ids = [r["id"] for r in self.recs]
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
"""The wording for the stated-permission licence on trail pages and the sources page."""
|
||||
import html
|
||||
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__)))
|
||||
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from olt import docs, geo, site, trail, words # noqa: E402
|
||||
from test_hike import with_line # noqa: E402
|
||||
from test_pages import sample_record # noqa: E402
|
||||
|
||||
S = site.Site("N", "T", repo_url="https://github.com/o/r")
|
||||
QUOTE = "It's completely public and free to share."
|
||||
|
||||
|
||||
def permission_record():
|
||||
rec = with_line(sample_record("Example Trail"))
|
||||
rec["source"].update({"licence": "stated-permission", "attribution": "Example Trail Association",
|
||||
"licence_text": "The association's president answered a form on the issue tracker.",
|
||||
"permission_quote": QUOTE, "permission_by": "the association's president",
|
||||
"permission_date": "2026-11-16",
|
||||
"permission_url": "https://github.com/o/r/issues/2"})
|
||||
return rec
|
||||
|
||||
|
||||
def flat(html_text):
|
||||
return re.sub(r"\s+", " ", html.unescape(re.sub(r"<[^>]+>", " ", html_text)))
|
||||
|
||||
|
||||
class StatedPermissionWordsTest(unittest.TestCase):
|
||||
def test_label_and_note(self):
|
||||
self.assertEqual(words.LICENCES["stated-permission"], "Shared with permission")
|
||||
note = words.LICENCE_NOTES["stated-permission"]
|
||||
self.assertTrue(note.startswith("Shared with permission. The holder has said in writing"))
|
||||
self.assertIn("not a Creative Commons licence", note)
|
||||
|
||||
def test_trail_page_says_it_in_plain_words(self):
|
||||
body = flat(trail.render(permission_record(), S)[2])
|
||||
self.assertGreaterEqual(body.count("Shared with permission. The holder has said in writing"), 2)
|
||||
self.assertIn("Licence: Shared with permission", body)
|
||||
self.assertIn(QUOTE, body)
|
||||
for wrong in ("CC BY", "Public domain", "US public domain", "ODbL"):
|
||||
self.assertNotIn(wrong, body)
|
||||
|
||||
def test_trail_page_shows_the_quotation_who_when_and_a_link(self):
|
||||
raw = trail.render(permission_record(), S)[2]
|
||||
self.assertIn('<blockquote cite="https://github.com/o/r/issues/2"><p>It's completely public and free to share.</p></blockquote>', raw)
|
||||
self.assertIn("Said by the association's president on 2026-11-16.", raw)
|
||||
self.assertIn('<a href="https://github.com/o/r/issues/2">https://github.com/o/r/issues/2</a>', raw)
|
||||
|
||||
def test_no_quotation_for_other_licences(self):
|
||||
rec = permission_record()
|
||||
rec["source"]["licence"] = "CC-BY-4.0"
|
||||
raw = trail.render(rec, S)[2]
|
||||
self.assertNotIn("Said by", raw)
|
||||
self.assertNotIn("<blockquote", raw)
|
||||
|
||||
def test_gpx_description_carries_the_quote_and_address(self):
|
||||
src = permission_record()["source"]
|
||||
fields = {k: src[k] for k in ("permission_quote", "permission_by", "permission_date", "permission_url")}
|
||||
text = geo.gpx_text([[[0, 0], [1, 1]]], "N", licence=src["licence"], licence_text=src["licence_text"],
|
||||
permission=fields)
|
||||
desc = ET.fromstring(text).find("{http://www.topografix.com/GPX/1/1}metadata/"
|
||||
"{http://www.topografix.com/GPX/1/1}desc").text
|
||||
self.assertIn(f'Permission: "{QUOTE}"', desc)
|
||||
self.assertIn("Said by the association's president on 2026-11-16.", desc)
|
||||
self.assertIn("https://github.com/o/r/issues/2", desc)
|
||||
plain = ET.fromstring(geo.gpx_text([[[0, 0], [1, 1]]], "N", licence="ODbL-1.0", licence_text="ODbL"))
|
||||
self.assertNotIn("Permission", plain.find("{http://www.topografix.com/GPX/1/1}metadata/"
|
||||
"{http://www.topografix.com/GPX/1/1}desc").text)
|
||||
|
||||
def test_other_licences_get_no_note(self):
|
||||
rec = permission_record()
|
||||
rec["source"]["licence"] = "CC-BY-4.0"
|
||||
self.assertNotIn("has said in writing", flat(trail.render(rec, S)[2]))
|
||||
|
||||
def test_data_page_row(self):
|
||||
rows = docs.line_licence_rows([permission_record()], os.path.dirname(WEB))
|
||||
what, terms, url = rows[0]
|
||||
self.assertIn("Tracks shared with permission: 1 record", str(what))
|
||||
self.assertIn("The holder has said in writing", str(terms))
|
||||
self.assertEqual(url, "/sources/")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,40 @@
|
||||
"""The page's controls, its address, the stored choices and what is drawn must
|
||||
say the same thing. These pin the script's answers to the faults found by
|
||||
driving the pages in a browser (the script itself has no unit tests)."""
|
||||
import os
|
||||
import re
|
||||
import unittest
|
||||
|
||||
WEB = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
def read(*parts):
|
||||
with open(os.path.join(WEB, *parts), encoding="utf-8") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
class ScriptSyncTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.js = read("assets", "app.js")
|
||||
|
||||
def test_basemap_follows_a_choice_made_while_the_map_loaded(self):
|
||||
# Another tab, or Back, may change the base map before the map is ready; the
|
||||
# change event is then ignored, so the map catches up once it is ready and
|
||||
# the switch (which shows the choice) is added.
|
||||
self.assertRegex(self.js, re.compile(r"map\.addControl\(switcher, 'top-left'\);\s*/\*.*?\*/\s*applyBasemap\(\);", re.S))
|
||||
|
||||
def test_lengths_the_wrong_way_round_in_the_address_show_in_order(self):
|
||||
# apply() writes the shorter length first; the controls must say the same.
|
||||
self.assertIn("if (stepKm(el.min.value) > stepKm(el.max.value) && stepKm(el.max.value)) {", self.js)
|
||||
|
||||
def test_the_header_switch_is_the_only_units_switch(self):
|
||||
css = read("assets", "style.css")
|
||||
for text in (self.js, css, read("olt", "home.py")):
|
||||
self.assertNotIn("units-list", text)
|
||||
self.assertNotIn("results-units", text)
|
||||
self.assertNotIn("UNITS_TOGGLE", read("olt", "home.py"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -42,8 +42,6 @@ class DefaultOrderTest(unittest.TestCase):
|
||||
self.assertIn('value="mi" checked><span aria-hidden="true">mi</span><span class="vh">Miles and feet</span>', prefs)
|
||||
self.assertLess(prefs.index('value="mi"'), prefs.index('value="km"'))
|
||||
self.assertNotIn('value="km" checked', prefs)
|
||||
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):
|
||||
|
||||
Reference in new issue
Block a user