Show an estimated season as an estimate on the trail page, in lists and tables, and in the month filter; say how seasons are sourced and tested on the reference page
This commit is contained in:
1 parent
713fff78df
commit
e95131833b
20 files changed
+481
-103
No files matched your search
@@ -173,6 +173,59 @@ class PlaceTest(unittest.TestCase):
|
||||
self.assertIn('<a href="/regions/us-co/">Colorado</a>', crumbs)
|
||||
|
||||
|
||||
def est_hike(**kw):
|
||||
h = {"season": "June to September", "months": [6, 7, 8, 9], "season_basis": "estimate",
|
||||
"season_method": "Judged from the climate at the trail's elevation and from similar trails. "
|
||||
"Snow keeps the high passes closed until June. Confidence: medium."}
|
||||
h.update(kw)
|
||||
return h
|
||||
|
||||
|
||||
class SeasonTextTest(unittest.TestCase):
|
||||
def test_an_estimated_season_reads_about_and_has_a_note(self):
|
||||
rec = fake(1, hike=est_hike())
|
||||
self.assertTrue(facets.season_estimated(rec))
|
||||
self.assertEqual(facets.season_text(rec), "About June to September")
|
||||
note = facets.season_note(rec)
|
||||
for want in ("No page states a season", "estimated from the climate at the trail's elevation and from "
|
||||
"similar trails", "Snow keeps the high passes closed until June.", "Confidence: medium.",
|
||||
"People do walk it outside these months."):
|
||||
self.assertIn(want, note)
|
||||
self.assertNotIn("Judged from", note) # the standard lead is said once, in the note's own words
|
||||
|
||||
def test_a_stated_season_is_unchanged_and_has_no_note(self):
|
||||
rec = fake(1, hike={"season": "June to September", "months": [6, 7, 8, 9], "season_basis": "primary"})
|
||||
self.assertFalse(facets.season_estimated(rec))
|
||||
self.assertEqual(facets.season_text(rec), "June to September")
|
||||
self.assertEqual(facets.season_note(rec), "")
|
||||
|
||||
def test_an_estimated_all_year_season_reads_about_all_year(self):
|
||||
rec = fake(1, hike=est_hike(season="All year", months=list(range(1, 13))))
|
||||
self.assertEqual(facets.season_text(rec), "About all year")
|
||||
|
||||
def test_it_is_not_estimated_without_a_basis_or_a_method(self):
|
||||
self.assertFalse(facets.season_estimated(fake(1, hike={"season": "May", "months": [5]})))
|
||||
self.assertFalse(facets.season_estimated(fake(1)))
|
||||
self.assertEqual(facets.season_kind(fake(1)), "")
|
||||
|
||||
def test_a_season_judged_from_pages_that_differ_says_so(self):
|
||||
rec = fake(1, hike=est_hike(season_basis="sources", season_method=(
|
||||
"The pages differ: one gives May to October and one gives June to November. It was set by "
|
||||
"judgement from both and from the climate. Confidence: medium.")))
|
||||
self.assertTrue(facets.season_estimated(rec))
|
||||
self.assertEqual(facets.season_kind(rec), "judged")
|
||||
self.assertEqual(facets.season_text(rec), "About June to September")
|
||||
note = facets.season_note(rec)
|
||||
self.assertIn("No one page states this season.", note)
|
||||
self.assertIn("The pages differ", note)
|
||||
self.assertNotIn("estimated from the climate at the trail's elevation", note)
|
||||
self.assertIn("It is a judgement", facets.season_basis_line(rec))
|
||||
|
||||
def test_the_basis_line_gives_the_method_for_an_estimate(self):
|
||||
line = facets.season_basis_line(fake(1, hike=est_hike()))
|
||||
self.assertTrue(line.endswith("Confidence: medium. No page states a season."), line)
|
||||
|
||||
|
||||
class MissingValuesTest(unittest.TestCase):
|
||||
def recs(self, n_with, n_without):
|
||||
return ([fake(i, hike={"months": [7, 8], "season": "July and August", "terrain": ["alpine"]})
|
||||
@@ -189,22 +242,24 @@ class MissingValuesTest(unittest.TestCase):
|
||||
self.assertIn('name="terrain"', form)
|
||||
|
||||
def test_missing_count_is_said(self):
|
||||
# the generic mechanism, shown with terrain: no real trail lacks a season any more
|
||||
form = home.finder_form(self.recs(10, 12))
|
||||
self.assertIn('data-missing="season" hidden>12 trails have no season on file.', form)
|
||||
self.assertIn('data-missing="terrain" hidden>12 trails have no terrain on file.', form)
|
||||
self.assertEqual(facets.missing_text(1, "season"), "1 trail has no season on file.")
|
||||
self.assertEqual(facets.missing_text(0, "season"), "")
|
||||
self.assertEqual(facets.missing_text(1, "terrain"), "1 trail has no terrain on file.")
|
||||
self.assertEqual(facets.missing_text(0, "terrain"), "")
|
||||
# full coverage: no note
|
||||
self.assertNotIn('data-missing="season"', home.finder_form(self.recs(5, 0)))
|
||||
self.assertNotIn('data-missing="terrain"', home.finder_form(self.recs(5, 0)))
|
||||
|
||||
def test_rows_without_a_value_carry_none(self):
|
||||
# the script leaves out a row whose data-months is empty while a month is chosen
|
||||
row = home.entry(fake(1))
|
||||
self.assertIn('data-months=""', row)
|
||||
self.assertIn('data-terrain=""', row)
|
||||
row = home.entry(fake(1, hike={"months": [7, 8, 9]}))
|
||||
self.assertIn('data-months="7 8 9"', row)
|
||||
|
||||
def test_every_real_trail_has_months(self):
|
||||
for rec in records.load_records(ROOT):
|
||||
self.assertTrue(facets.months(rec), rec["id"])
|
||||
|
||||
def test_script_leaves_out_missing_values(self):
|
||||
with open(os.path.join(WEB, "assets", "app.js"), encoding="utf-8") as f:
|
||||
js = f.read()
|
||||
@@ -287,6 +342,31 @@ class BuiltVocabularyTest(unittest.TestCase):
|
||||
self.maxDiff = None
|
||||
self.assertEqual(bad[:40], [])
|
||||
|
||||
def test_no_page_says_only_some_trails_have_a_season(self):
|
||||
found = []
|
||||
for dirpath, _dirs, files in os.walk(OUT):
|
||||
for name in files:
|
||||
if name.endswith(".html") and "changelog" not in dirpath: # its old entries say what was
|
||||
path = os.path.join(dirpath, name)
|
||||
with open(path, encoding="utf-8") as f:
|
||||
doc = f.read()
|
||||
for phrase in ("Only some trails have a season", "season on file", "Not on file</td>",
|
||||
"data-unseasoned", "Show them"):
|
||||
if phrase in doc:
|
||||
found.append((os.path.relpath(path, OUT), phrase))
|
||||
self.assertEqual(found[:10], [])
|
||||
|
||||
def test_an_estimated_season_reads_about_on_its_page_and_a_stated_one_does_not(self):
|
||||
est = [r for r in records.load_records(ROOT) if facets.season_estimated(r)]
|
||||
stated = [r for r in records.load_records(ROOT) if not facets.season_estimated(r)]
|
||||
self.assertEqual(len(est) + len(stated), 223)
|
||||
for rec in est[:10]:
|
||||
doc = self.read(f"trails/{rec['id']}/index.html")
|
||||
self.assertIn(facets.season_text(rec), html.unescape(doc), rec["id"])
|
||||
self.assertIn("People do walk it outside these months.", html.unescape(doc), rec["id"])
|
||||
for rec in stated[:10]:
|
||||
self.assertNotIn("People do walk it outside these months.", html.unescape(self.read(f"trails/{rec['id']}/index.html")))
|
||||
|
||||
def test_navigation_has_four_sections_and_saved(self):
|
||||
doc = self.read("index.html")
|
||||
nav = re.search(r'<nav class="site-nav" aria-label="Main"><ul class="nav">(.*?)</ul></nav>', doc).group(1)
|
||||
|
||||
@@ -235,13 +235,13 @@ def rows_of(body):
|
||||
d = {k: html.unescape(v) for k, v in re.findall(r' data-([a-z]+)="([^"]*)"', attrs)}
|
||||
split = lambda v: [x for x in v.split(" ") if x] # noqa: E731
|
||||
out.append({"id": d["id"], "search": [" " + t + " " for t in d["search"].split("|")], "where": split(d["where"]), "km": float(d["km"]),
|
||||
"time": d["time"], "months": split(d["months"]), "terrain": split(d["terrain"]),
|
||||
"time": d["time"], "months": split(d["months"]), "estimate": d.get("estimate") == "yes", "terrain": split(d["terrain"]),
|
||||
"kind": d["kind"], "walking": d["walking"], "shape": d["shape"], "gpx": d["gpx"]})
|
||||
return out
|
||||
|
||||
|
||||
def state(**kw):
|
||||
s = {"words": [], "where": "", "min": 0, "max": None, "month": "", "kind": "",
|
||||
s = {"words": [], "where": "", "min": 0, "max": None, "month": "", "stated": False, "kind": "",
|
||||
"time": [], "terrain": [], "walking": [], "shape": [], "gpx": []}
|
||||
s.update(kw)
|
||||
return s
|
||||
@@ -366,45 +366,75 @@ class PanelInTheFlowTest(unittest.TestCase):
|
||||
self.assertIn("if (window.location.hash === '#filters') showPanels(true);", js)
|
||||
|
||||
|
||||
class UnseasonedNoteTest(unittest.TestCase):
|
||||
"""A month filter says how many trails it leaves out for having no season on file."""
|
||||
class LeaveOutEstimatesTest(unittest.TestCase):
|
||||
"""The month filter can leave estimated seasons out, and says nothing about trails with no season."""
|
||||
|
||||
def test_a_finder_list_has_the_note_and_it_starts_hidden(self):
|
||||
def test_the_month_field_has_the_checkbox_and_it_starts_disabled(self):
|
||||
recs = recordsmod.load_records(ROOT)
|
||||
body = str(home.results(recs, finder=True))
|
||||
self.assertIn('<p class="results-note" data-unseasoned hidden>', body)
|
||||
self.assertIn('data-unseasoned-show>Show them</button>', body)
|
||||
self.assertNotIn("data-unseasoned", str(home.results(recs)))
|
||||
form = home.finder_form(recs)
|
||||
field = form[form.index('data-facet="month"'):]
|
||||
field = field[:field.index("</div>")]
|
||||
self.assertIn('<input type="checkbox" name="stated" value="1" disabled>', field)
|
||||
self.assertIn("Leave out estimated seasons", field)
|
||||
|
||||
def test_the_script_counts_it_over_the_rows_of_the_list_and_show_them_clears_the_month(self):
|
||||
def test_there_is_no_checkbox_where_no_trail_has_an_estimated_season(self):
|
||||
recs = [r for r in recordsmod.load_records(ROOT) if not facets.season_estimated(r)]
|
||||
self.assertNotIn('name="stated"', home.finder_form(recs))
|
||||
|
||||
def test_the_results_have_no_unseasoned_note(self):
|
||||
recs = recordsmod.load_records(ROOT)
|
||||
for body in (str(home.results(recs, finder=True)), str(home.results(recs))):
|
||||
self.assertNotIn("data-unseasoned", body)
|
||||
self.assertNotIn("Show them", body)
|
||||
self.assertNotIn("no season on file", body)
|
||||
js = read(WEB, "assets", "app.js")
|
||||
self.assertIn("if (!d.months.length && FacetCount.passes(d, s, 'month')) noSeason++;", js)
|
||||
self.assertIn("' trails with no season on file are not shown.'", js)
|
||||
self.assertIn("el.month.value = '';", js)
|
||||
self.assertNotIn("unseasoned", js.lower())
|
||||
self.assertNotIn("no season on file", js)
|
||||
|
||||
def test_a_row_carries_whether_its_season_is_an_estimate(self):
|
||||
est = next(r for r in recordsmod.load_records(ROOT) if facets.season_estimated(r))
|
||||
stated = next(r for r in recordsmod.load_records(ROOT) if not facets.season_estimated(r))
|
||||
self.assertIn('data-estimate="yes"', str(home.entry(est)))
|
||||
self.assertNotIn("data-estimate", str(home.entry(stated)))
|
||||
|
||||
def test_the_script_reads_the_checkbox_and_writes_it_in_the_address(self):
|
||||
js = read(WEB, "assets", "app.js")
|
||||
self.assertIn("if (s.month && s.stated && d.estimate) return false;", js)
|
||||
self.assertIn("if (s.month && s.stated) p.set('stated', '1');", js)
|
||||
self.assertIn("estimate: d.estimate === 'yes'", js)
|
||||
|
||||
@unittest.skipUnless(NODE, "node is not installed")
|
||||
def test_the_number_is_the_trails_that_pass_everything_else_and_have_no_season(self):
|
||||
recs = recordsmod.load_records(ROOT)
|
||||
rows = rows_of(home.render(recs, SITE, ROOT))
|
||||
def test_with_stated_on_estimated_rows_leave_the_month_and_the_counts_follow(self):
|
||||
def row(i, months, estimate):
|
||||
return {"id": f"t{i}", "search": [" ", " ", " ", " "], "where": [], "km": 100.0, "time": "week",
|
||||
"months": [str(m) for m in months], "estimate": estimate, "terrain": [], "kind": "trail", "walking": "",
|
||||
"shape": "", "gpx": "none"}
|
||||
rows = [row(1, [7], True), row(2, [7], False), row(3, [7, 8], False), row(4, [8], True)]
|
||||
off = run_counts(rows, state(month="7"))
|
||||
on = run_counts(rows, state(month="7", stated=True))
|
||||
self.assertEqual((off["total"], off["month"]["7"], off["month"]["8"]), (3, 3, 2))
|
||||
self.assertEqual((on["total"], on["month"]["7"], on["month"]["8"]), (2, 2, 1))
|
||||
# with no month chosen it does nothing
|
||||
self.assertEqual(run_counts(rows, state(stated=True))["total"], 4)
|
||||
# and the shown number is the rows that pass
|
||||
prog = facet_count_source() + """
|
||||
var input = JSON.parse(require('fs').readFileSync(0, 'utf8'));
|
||||
input.s.max = Infinity;
|
||||
var n = 0, shown = 0;
|
||||
input.rows.forEach(function (d) {
|
||||
if (FacetCount.passes(d, input.s, '')) shown++;
|
||||
else if (!d.months.length && FacetCount.passes(d, input.s, 'month')) n++;
|
||||
});
|
||||
process.stdout.write(JSON.stringify([shown, n]));
|
||||
process.stdout.write(JSON.stringify(input.rows.filter(function (d) { return FacetCount.passes(d, input.s, ''); }).length));
|
||||
"""
|
||||
for s in (state(month="8"), state(month="8", kind="route"), state(month="8", where="US-CA")):
|
||||
out = subprocess.run([NODE, "-e", prog], input=json.dumps({"rows": rows, "s": s}),
|
||||
capture_output=True, text=True, check=True)
|
||||
shown, n = json.loads(out.stdout)
|
||||
def base(r):
|
||||
return ((not s["kind"] or facets.kind(r) == s["kind"])
|
||||
and (not s["where"] or s["where"] in facets.where_tokens(r)))
|
||||
self.assertEqual(shown, sum(1 for r in recs if base(r) and 8 in facets.months(r)))
|
||||
self.assertEqual(n, sum(1 for r in recs if base(r) and not facets.months(r)))
|
||||
out = subprocess.run([NODE, "-e", prog], input=json.dumps({"rows": rows, "s": state(month="7", stated=True)}),
|
||||
capture_output=True, text=True, check=True)
|
||||
self.assertEqual(json.loads(out.stdout), on["total"])
|
||||
|
||||
@unittest.skipUnless(NODE, "node is not installed")
|
||||
def test_on_the_real_trails_the_counts_leave_out_exactly_the_estimates(self):
|
||||
recs = recordsmod.load_records(ROOT)
|
||||
rows = rows_of(home.render(recs, SITE, ROOT))
|
||||
for month in (1, 7):
|
||||
c = run_counts(rows, state(month=str(month), stated=True))
|
||||
want = sum(1 for r in recs if month in facets.months(r) and not facets.season_estimated(r))
|
||||
self.assertEqual(c["total"], want)
|
||||
self.assertEqual(c["month"][str(month)], want)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+25
-2
@@ -137,6 +137,29 @@ class TrailPageTest(unittest.TestCase):
|
||||
self.assertNotIn("The season comes from", trail.hike_sources_block(rec))
|
||||
self.assertEqual(facets.season_basis(rec), "")
|
||||
|
||||
def test_an_estimated_season_row_carries_the_note(self):
|
||||
rec = sample_record("X Trail")
|
||||
rec["hike"] = dict(FULL_HIKE, season="April to October", months=[4, 5, 6, 7, 8, 9, 10],
|
||||
season_basis="estimate",
|
||||
season_method="Judged from the climate at the trail's elevation and from similar "
|
||||
"trails. Snow and mud last into March. Confidence: high.")
|
||||
t = text(top_part(render(rec)))
|
||||
self.assertIn("Season About April to October", t)
|
||||
self.assertIn("No page states a season.", t)
|
||||
self.assertIn("Confidence: high.", t)
|
||||
self.assertIn("People do walk it outside these months.", t)
|
||||
self.assertIn("No source gives a season; the climate suggests about April to October.", t)
|
||||
self.assertNotIn("The usual season is", t)
|
||||
block = html.unescape(trail.hike_sources_block(rec))
|
||||
self.assertIn("Snow and mud last into March. Confidence: high. No page states a season.", block)
|
||||
|
||||
def test_a_stated_season_row_has_no_note(self):
|
||||
rec = sample_record("X Trail")
|
||||
rec["hike"] = dict(FULL_HIKE, season_basis="primary")
|
||||
t = text(top_part(render(rec)))
|
||||
self.assertIn("Season March to October", t)
|
||||
self.assertNotIn("No page states a season", t)
|
||||
|
||||
def test_partial_hike_table(self):
|
||||
rec = sample_record("X Trail")
|
||||
rec["hike"] = {"shape": "loop", "start": "Lake Camp", "days": [4, 6], "checked": "2026-11-13"}
|
||||
@@ -144,7 +167,7 @@ class TrailPageTest(unittest.TestCase):
|
||||
t = text(top)
|
||||
self.assertIn("Shape Loop. Starts and ends at Lake Camp", t)
|
||||
self.assertIn("Time 4 to 6 days", t)
|
||||
self.assertIn("Season, terrain, walking and permits are not on file for this trail yet.", t)
|
||||
self.assertIn("Terrain, walking and permits are not on file for this trail yet.", t)
|
||||
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
|
||||
@@ -175,7 +198,7 @@ class TrailPageTest(unittest.TestCase):
|
||||
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 12 to 19 mi 20 to 30 km a day.", t)
|
||||
self.assertIn("Season, terrain, walking and permits are not on file for this trail yet.", t)
|
||||
self.assertIn("Terrain, walking and permits 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
|
||||
self.assertIn("No GPX here", t)
|
||||
|
||||
@@ -201,6 +201,17 @@ class JsonLdTest(unittest.TestCase):
|
||||
count += 1
|
||||
self.assertEqual(count, len(self.records))
|
||||
|
||||
def test_no_estimated_season_appears_in_structured_data(self):
|
||||
seen = 0
|
||||
for rec in self.records:
|
||||
h = rec.get("hike", {})
|
||||
if not (h.get("season_basis") == "estimate" or h.get("season_method")):
|
||||
continue
|
||||
seen += 1
|
||||
page = self.pages[f"trails/{rec['id']}/index.html"]
|
||||
self.assertNotIn("Usual season", page, rec["id"])
|
||||
self.assertGreater(seen, 0)
|
||||
|
||||
def test_a_trail_states_only_what_its_record_holds(self):
|
||||
built_derived = {r["id"]: r["derived"] for r in json.loads(read("data/trails.json"))}
|
||||
for rec in self.records:
|
||||
@@ -211,7 +222,9 @@ class JsonLdTest(unittest.TestCase):
|
||||
self.assertEqual(props[("Published length", "KMT")]["value"], rec["length_km"], rec["id"])
|
||||
h = rec.get("hike", {})
|
||||
self.assertEqual(("Start", None) in props, bool(h.get("start")), rec["id"])
|
||||
self.assertEqual(("Usual season", None) in props, bool(h.get("season")), rec["id"])
|
||||
self.assertEqual(("Usual season", None) in props,
|
||||
bool(h.get("season") and h.get("season_basis") != "estimate" and not h.get("season_method")),
|
||||
rec["id"])
|
||||
self.assertEqual(any(k[0] == "Highest point" for k in props),
|
||||
bool(h.get("high_point_m") or h.get("high_point")), rec["id"])
|
||||
if h.get("official_url"):
|
||||
|
||||
+25
-4
@@ -16,7 +16,7 @@ WEB = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
ROOT = os.path.dirname(WEB)
|
||||
sys.path.insert(0, WEB)
|
||||
|
||||
from olt import common, docs, hike, records, seo, site, trail # noqa: E402
|
||||
from olt import common, docs, facets, hike, records, seo, site, trail # noqa: E402
|
||||
|
||||
SITE = site.load()
|
||||
|
||||
@@ -160,6 +160,21 @@ class InBrief(unittest.TestCase):
|
||||
("range", "The usual season is spring and fall"))
|
||||
self.assertIsNone(season("Best travelled " + "in the later part of the summer " * 5))
|
||||
|
||||
def test_an_estimated_season_sentence_says_no_source_gives_one(self):
|
||||
rec = sparse_record()
|
||||
rec["hike"] = {"season": "June to September", "months": [6, 7, 8, 9], "season_basis": "estimate",
|
||||
"season_method": "Judged from the climate. Snow. Confidence: low."}
|
||||
self.assertEqual(trail.season_sentence(rec),
|
||||
("estimate", "No source gives a season; the climate suggests about June to September"))
|
||||
rec["hike"]["season_basis"] = "sources"
|
||||
self.assertEqual(trail.season_sentence(rec),
|
||||
("estimate", "The pages differ on the season; it is judged to be about June to September"))
|
||||
rec["hike"].update(season="All year", months=list(range(1, 13)), season_basis="estimate")
|
||||
self.assertEqual(trail.season_sentence(rec)[1], "No source gives a season; the climate suggests about all year")
|
||||
# the sentence stands alone: it is never joined to the GPX clause with "and"
|
||||
paragraph = " ".join(trail.brief_sentences(rec))
|
||||
self.assertIn("No source gives a season; the climate suggests about all year.", paragraph)
|
||||
|
||||
def test_a_permit_is_said_only_when_it_is_short(self):
|
||||
short = sparse_record()
|
||||
short["hike"] = {"permit": "No permit is needed to hike it."}
|
||||
@@ -217,7 +232,8 @@ class InBrief(unittest.TestCase):
|
||||
s = self.sentences(rec)
|
||||
paragraph = " ".join(s)
|
||||
self.assertGreaterEqual(len(s), 2, rec["id"])
|
||||
self.assertLessEqual(len(s), 4, rec["id"])
|
||||
# four sentences, and a fifth where the season is an estimate, which is always said
|
||||
self.assertLessEqual(len(s), 4 + facets.season_estimated(rec), rec["id"])
|
||||
self.assertIn("GPX", paragraph, rec["id"])
|
||||
self.assertNotRegex(paragraph, r"\b(Season|Permits are noted)\b", rec["id"])
|
||||
for bad in ("None", "{", "}", " ", " ,", " .", "unknown", "not known", "n/a"):
|
||||
@@ -232,8 +248,13 @@ class InBrief(unittest.TestCase):
|
||||
self.assertIn("usually takes", paragraph, rec["id"])
|
||||
else:
|
||||
self.assertNotIn("usually takes", paragraph, rec["id"])
|
||||
if not (h.get("season") or h.get("months")):
|
||||
self.assertNotRegex(paragraph, r"usual season|walked all year|Northbound|season", rec["id"])
|
||||
self.assertTrue(h.get("season"), rec["id"])
|
||||
if facets.season_estimated(rec):
|
||||
self.assertIn("No source gives a season" if not facets.season_pages_differ(rec)
|
||||
else "The pages differ on the season", paragraph, rec["id"])
|
||||
self.assertNotIn("The usual season is", paragraph, rec["id"])
|
||||
else:
|
||||
self.assertNotIn("No source gives a season", paragraph, rec["id"])
|
||||
if "No permit" in paragraph or "permit" in paragraph.lower():
|
||||
self.assertIn(common.sentence(h.get("permit", "")), paragraph, rec["id"])
|
||||
self.assertEqual("highest point" in paragraph,
|
||||
|
||||
+58
-2
@@ -8,6 +8,7 @@ These do not need the built site.
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
from html import unescape as html_unescape
|
||||
import shutil
|
||||
import tempfile
|
||||
import sys
|
||||
@@ -117,7 +118,7 @@ class MonthListTest(unittest.TestCase):
|
||||
self.assertEqual(keys(recs, "hike-in-july"), ["t1"])
|
||||
self.assertEqual(keys(recs, "hike-in-august"), ["t2"])
|
||||
|
||||
def test_a_month_needs_eight_trails_and_says_how_many_have_a_season(self):
|
||||
def test_a_month_needs_eight_trails(self):
|
||||
july = browse.by_key("hike-in-july")
|
||||
self.assertEqual(july.min_size, 8)
|
||||
self.assertFalse(browse.is_shown(7, 100, july.min_size))
|
||||
@@ -126,8 +127,35 @@ class MonthListTest(unittest.TestCase):
|
||||
shown = {lst.key for lst, _ in browse.shown(recs)}
|
||||
self.assertIn("hike-in-july", shown)
|
||||
self.assertNotIn("hike-in-august", shown)
|
||||
|
||||
def est(self, i, months=(7,)):
|
||||
return fake(i, hike={"months": list(months), "season": "July", "season_basis": "estimate",
|
||||
"season_method": "Judged. Confidence: low."})
|
||||
|
||||
def test_a_month_note_counts_stated_and_estimated_exactly(self):
|
||||
july = browse.by_key("hike-in-july")
|
||||
recs = [fake(i, hike={"months": [7], "season": "July", "season_basis": "primary"}) for i in range(10)] \
|
||||
+ [self.est(20 + i) for i in range(5)]
|
||||
note = july.note(browse.members(july, recs), recs)
|
||||
self.assertIn("Only 10 of the 20 trails have a season on file", note)
|
||||
self.assertEqual(note, "A source states the season for 10 of these. For the other 5 it is estimated "
|
||||
"from climate, and marked.")
|
||||
|
||||
def test_a_month_list_with_no_estimates_says_so(self):
|
||||
july = browse.by_key("hike-in-july")
|
||||
recs = [fake(i, hike={"months": [7], "season": "July", "season_basis": "primary"}) for i in range(10)]
|
||||
self.assertEqual(july.note(browse.members(july, recs), recs), "A source states the season for all 10.")
|
||||
recs = [self.est(i) for i in range(3)]
|
||||
self.assertEqual(july.note(browse.members(july, recs), recs),
|
||||
"No source states the season for these, so each is estimated from climate.")
|
||||
|
||||
def test_the_month_blurb_no_longer_says_only_some_trails(self):
|
||||
group = {key: blurb for key, _title, blurb in browse.GROUPS}["month"]
|
||||
self.assertEqual(group, "Trails normally hiked in the month. Estimated seasons are marked.")
|
||||
self.assertEqual(browse.by_key("hike-in-july").blurb,
|
||||
"Trails normally hiked in July. Estimated seasons are marked.")
|
||||
for lst in browse.LISTS:
|
||||
self.assertNotIn("Only some trails", lst.blurb)
|
||||
self.assertNotIn("season on file", lst.blurb)
|
||||
|
||||
def test_every_list_has_a_group_and_every_group_a_heading(self):
|
||||
headings = {k for k, _, _ in browse.GROUPS}
|
||||
@@ -628,6 +656,34 @@ class RealDataTest(unittest.TestCase):
|
||||
n_ver = len(reference.verified(self.records))
|
||||
self.assertIn(f"{n_ver} of the {len(self.records)} trails have a track", str(body))
|
||||
|
||||
def method_text(self):
|
||||
title, desc, body = reference.method_page(self.records, SITE, ROOT)
|
||||
return re.sub(r"\s+", " ", html_unescape(re.sub(r"<[^>]+>", " ", str(body))))
|
||||
|
||||
def test_the_reference_page_counts_stated_and_estimated_seasons(self):
|
||||
text = self.method_text()
|
||||
kinds = {k: sum(1 for r in self.records if facets.season_kind(r) == k) for k in ("stated", "judged", "estimated")}
|
||||
self.assertEqual(sum(kinds.values()), len(self.records))
|
||||
self.assertIn(f"A season a page states Records with it {kinds['stated']} Records without {len(self.records) - kinds['stated']}", text)
|
||||
self.assertIn(f"A season estimated from climate Records with it {kinds['estimated']} Records without {len(self.records) - kinds['estimated']}", text)
|
||||
self.assertIn(f"A season set from pages that differ Records with it {kinds['judged']} Records without {len(self.records) - kinds['judged']}", text)
|
||||
self.assertIn(f"All trails Trails {len(self.records)}", text)
|
||||
|
||||
def test_the_reference_page_gives_the_blind_test_from_its_file(self):
|
||||
blind = datafiles.blind_test(ROOT)
|
||||
text = self.method_text()
|
||||
self.assertIn(f"the method was run blind on {blind['tested']} trails whose seasons a page does state", text)
|
||||
self.assertIn(f"It matched {blind['matched']} of them ({round(blind['share'] * 100)} percent) within one month at "
|
||||
"each end", text)
|
||||
for name, v in blind["by_confidence"].items():
|
||||
self.assertIn(f"{name} {v['matched']} of {v['tested']} ({round(v['share'] * 100)} percent)", text)
|
||||
self.assertIn("not a promise for any one trail", text)
|
||||
|
||||
def test_the_glossary_no_longer_says_only_some_records_state_a_season(self):
|
||||
season = next(t for t in reference.terms(ROOT) if t["id"] == "season")
|
||||
self.assertNotIn("Only some", season["definition"])
|
||||
self.assertIn("estimated", season["definition"])
|
||||
|
||||
def test_every_place_page_has_a_summary_paragraph(self):
|
||||
by_slug, _ = regions.collect_regions(self.records)
|
||||
for slug in by_slug:
|
||||
|
||||
Reference in new issue
Block a user