Merge branch 'main' into seasons-ship-3

This commit is contained in:
swaits committed 2026-11-20 11:35:19 -07:00
commit 072d568977
53 files changed
+811 -19

No files matched your search

+16 -5
View File
@@ -41,20 +41,31 @@ def check_season(tid, hike, errors):
errors.append(
f"{tid}: hike.season_basis must be one of {', '.join(BASES)}, not {basis!r}")
if basis == "estimate":
if has_method:
method = hike.get("season_method")
if not isinstance(method, str) or not method.strip():
errors.append(f"{tid}: hike.season_method is required with season_basis \"estimate\"")
if basis not in ("estimate", "sources"):
errors.append(
f"{tid}: hike.season_method is only given with season_basis \"estimate\" "
"or \"sources\"")
elif not isinstance(method, str) or not method.strip():
errors.append(f"{tid}: hike.season_method must not be empty")
elif len(method) >= 400:
errors.append(f"{tid}: hike.season_method must be under 400 characters")
elif has_method:
errors.append(f"{tid}: hike.season_method is only given with season_basis \"estimate\"")
elif basis == "estimate":
errors.append(f"{tid}: hike.season_method is required with season_basis \"estimate\"")
naming_season = _naming(sources, "season")
if basis in ("primary", "source"):
if not naming_season:
errors.append(
f"{tid}: hike.season_basis \"{basis}\" needs a [[hike.source]] naming season")
elif basis == "source":
publishers = {str(s.get("publisher", "")).strip().casefold()
for s in naming_season}
if len(publishers) != 1:
errors.append(
f"{tid}: hike.season_basis \"source\" needs exactly one publisher "
"naming season (two or more is \"sources\")")
elif basis == "sources":
publishers = {str(s.get("publisher", "")).strip().casefold()
for s in naming_season if str(s.get("publisher", "")).strip()}
+67
View File
@@ -476,6 +476,57 @@ asked_by = "the dataset's own check"
'''
SEASON_PROPOSAL = '''
[[proposal]]
kind = "change"
id = "aaa"
date = "2026-11-30"
summary = "A season from the club's page."
[[proposal.edit]]
field = "hike.season"
new = "Late June to mid-September"
page = "https://example.org/aaa/season"
quote = "Hike it from late June through mid-September."
[[proposal.edit]]
field = "hike.months"
new = [7, 8, 9]
page = "https://example.org/aaa/season"
quote = "Hike it from late June through mid-September."
[[proposal.edit]]
field = "hike.season_basis"
new = "primary"
page = "https://example.org/aaa/season"
quote = "Hike it from late June through mid-September."
[[proposal.edit]]
field = "hike.checked"
old = "2026-11-13"
new = "2026-11-30"
page = "https://example.org/aaa/season"
quote = "Hike it from late June through mid-September."
[[proposal.append]]
table = "hike.source"
page = "https://example.org/aaa/season"
quote = "Hike it from late June through mid-September."
[proposal.append.entry]
url = "https://example.org/aaa/season"
publisher = "Example Club"
facts = ["season", "months"]
[proposal.history]
change = "The record gained a season."
basis = "The club's page says: Hike it from late June through mid-September."
basis_url = "https://example.org/aaa/season"
fields = ["hike.season", "hike.months", "hike.season_basis"]
asked_by = "the dataset's own check"
'''
class CollectTest(Tmp):
def collect(self):
code, out = main(self.root, "--dir", self.d, "collect")
@@ -731,6 +782,22 @@ class ApplyTest(Tmp):
H.check_entries("aaa", rec, errors)
self.assertEqual(errors, [])
def test_a_researched_season_proposal_collects_and_applies(self):
import validate as V
propose(self.d, "season-01", "aaa", SEASON_PROPOSAL)
self.collect_accept_all()
code, out = self.apply()
self.assertEqual(code, 0, out)
rec = self.rec("aaa")
self.assertEqual(rec["hike"]["season"], "Late June to mid-September")
self.assertEqual(rec["hike"]["months"], [7, 8, 9])
self.assertEqual(rec["hike"]["season_basis"], "primary")
self.assertEqual(rec["hike"]["source"][-1]["facts"], ["season", "months"])
errors = []
V.season.check_season("aaa", rec["hike"], errors)
H.check_entries("aaa", rec, errors)
self.assertEqual(errors, [])
def test_only_accepted_proposals_apply(self):
propose(self.d, "trails-01", "aaa", PERMIT_CHANGE)
main(self.root, "--dir", self.d, "collect")
+21
View File
@@ -73,6 +73,27 @@ class SeasonBasisTest(unittest.TestCase):
errors = check(season_basis="source", source=[src("Guide A", facts=("days",))])
self.assertTrue(errors)
def test_source_basis_needs_exactly_one_publisher(self):
two = [src("Park Service"), src("Blog", url="https://example.org/b")]
errors = check(season_basis="source", source=two)
self.assertTrue(any("exactly one publisher" in e for e in errors), errors)
same = [src("Park Service"), src("Park Service", url="https://example.org/b")]
self.assertEqual(check(season_basis="source", source=same), [])
def test_method_is_allowed_with_sources_only_besides_estimate(self):
two = [src("Park Service"), src("Blog", url="https://example.org/b")]
ok = check(season_basis="sources", source=two,
season_method="The pages differ; set from both and the climate estimate.")
self.assertEqual(ok, [])
self.assertEqual(check(season_basis="sources", source=two), [])
for basis in ("primary", "source"):
errors = check(season_basis=basis, season_method="Some sentence.")
self.assertTrue(any("season_method" in e for e in errors), (basis, errors))
long = check(season_basis="sources", source=two, season_method="x" * 401)
self.assertTrue(any("400" in e for e in long), long)
blank = check(season_basis="sources", source=two, season_method=" ")
self.assertTrue(any("season_method" in e for e in blank), blank)
def test_primary_needs_a_naming_source(self):
errors = check(source=[src("Park Service", facts=("days",))])
self.assertTrue(errors)
+1 -1
View File
@@ -95,7 +95,7 @@ class TableTest(unittest.TestCase):
r = refresh.load_toml(os.path.join(V.ROOT, tid, "trail.toml"))
if (r.get("hike") or {}).get("season"):
expected += 1
self.assertEqual(expected, 109)
self.assertGreaterEqual(expected, 109)
self.assertEqual(len(rows), expected)
for row in rows:
self.assertIn(row["suggested"], season.BASES)