Name the exact book or guide for every route, and link to it
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
68fc0961b2
commit
1601f7c755
50 files changed
+814
-69
No files matched your search
@@ -38,6 +38,21 @@ class GuideTest(unittest.TestCase):
|
||||
self.assertTrue(check([dict(GOOD, price="$5")]))
|
||||
self.assertEqual(check([dict(GOOD, price="$5", price_checked="2026-11-16")]), [])
|
||||
|
||||
def test_new_fields_are_checked(self):
|
||||
self.assertEqual(check([dict(GOOD, edition="9th edition, 2021", where="Trip 25, page 149", link_is="author")]), [])
|
||||
self.assertTrue(check([dict(GOOD, edition=" ")]))
|
||||
self.assertTrue(check([dict(GOOD, where=3)]))
|
||||
self.assertTrue(check([dict(GOOD, link_is="shop")]))
|
||||
for kind in ("publisher", "author", "library", "seller"):
|
||||
self.assertEqual(check([dict(GOOD, link_is=kind)]), [])
|
||||
|
||||
def test_a_purchase_must_say_what_it_is(self):
|
||||
bought = dict(GOOD, access="purchase")
|
||||
self.assertTrue(check([bought]))
|
||||
for field, value in (("isbn", "978-0-89997-884-0"), ("edition", "2nd edition"), ("link_is", "seller")):
|
||||
self.assertEqual(check([dict(bought, **{field: value})]), [], field)
|
||||
self.assertEqual(check([dict(GOOD)]), []) # a free guide needs none
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -186,6 +186,10 @@ def check_shield(tid, shield, tdir, errors):
|
||||
errors.append(f"{tid}: declared logo file {logo_file} does not exist")
|
||||
|
||||
|
||||
# What a guide's url points at (the `link_is` field).
|
||||
GUIDE_LINK_IS = ("publisher", "author", "library", "seller")
|
||||
|
||||
|
||||
def check_guides(tid, guides, errors):
|
||||
"""[[guide]]: a route needs at least one (checked with the route); any trail may have its holder's own."""
|
||||
if guides is None:
|
||||
@@ -203,6 +207,18 @@ def check_guides(tid, guides, errors):
|
||||
f"not {g.get('access')!r}")
|
||||
if not str(g.get("url", "")).startswith(("https://", "http://")):
|
||||
errors.append(f"{tid}: guide {i} url must be an http(s) URL")
|
||||
for field in ("edition", "where"):
|
||||
if field in g and (not isinstance(g[field], str) or not g[field].strip()):
|
||||
errors.append(f"{tid}: guide {i} {field} must be a non-empty string")
|
||||
if "link_is" in g and g["link_is"] not in GUIDE_LINK_IS:
|
||||
errors.append(
|
||||
f"{tid}: guide {i} link_is must be one of {', '.join(GUIDE_LINK_IS)}, "
|
||||
f"not {g['link_is']!r}")
|
||||
if (g.get("access") == "purchase"
|
||||
and not any(str(g.get(f, "")).strip() for f in ("isbn", "edition", "link_is"))):
|
||||
errors.append(
|
||||
f"{tid}: guide {i} is a purchase but says nothing of what it is: "
|
||||
"give an isbn, an edition or link_is, so a visitor knows exactly what to get")
|
||||
if (str(g.get("price", "")).strip()
|
||||
and not DATE_RE.match(str(g.get("price_checked", "")))):
|
||||
errors.append(
|
||||
|
||||
Reference in new issue
Block a user