| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- """Navigation checks for the wiki pages in docs/wiki/.
- A page nobody links to is a page nobody reads. These tests keep Contents (every page),
- the Reading-Order page and the "Next:" lines honest as pages are added.
- """
- import re
- import sys
- import tempfile
- from pathlib import Path
- ROOT = Path(__file__).resolve().parent.parent
- sys.path.insert(0, str(ROOT / "scripts"))
- import gen_wiki_nav as gwn
- WIKI = Path(__file__).resolve().parent.parent / "docs" / "wiki"
- PAGE_LINK = re.compile(r"\]\(([A-Za-z0-9_-]+)\.md(?:#[^)]*)?\)")
- EXEMPT = {"_Sidebar", "_Footer", "Home"}
- def pages() -> set[str]:
- return {p.stem for p in WIKI.glob("*.md")}
- def linked(name: str) -> list[str]:
- return PAGE_LINK.findall((WIKI / f"{name}.md").read_text())
- def test_every_page_is_in_contents_or_reading_order():
- reachable = set(linked("Contents")) | set(linked("Reading-Order"))
- missing = sorted(pages() - EXEMPT - reachable)
- assert not missing, f"not in Contents or Reading-Order: {missing}"
- def test_every_page_the_sidebar_links_exists():
- missing = sorted(set(linked("_Sidebar")) - pages())
- assert not missing, f"sidebar links to missing pages: {missing}"
- def test_every_page_named_in_a_next_line_exists():
- """The Next: lines are written by the publish step (issue #521), so they are read from its output."""
- problems, lines = [], 0
- with tempfile.TemporaryDirectory() as out:
- gwn.publish_pages(ROOT, Path(out))
- for page in sorted(Path(out).glob("*.md")):
- for line in page.read_text().splitlines():
- if "Next:" not in line:
- continue
- lines += 1
- for target in PAGE_LINK.findall(line):
- if target not in pages():
- problems.append(f"{page.name}: {target}")
- assert lines >= 200, f"the guard saw only {lines} Next lines"
- assert not problems, f"Next lines name missing pages: {problems}"
- def test_the_guard_for_next_lines_bites_on_a_missing_page():
- assert PAGE_LINK.findall("Previous: [A](A.md) / Next: [B](No-Such-Page-Here.md)") == ["A", "No-Such-Page-Here"]
- assert "No-Such-Page-Here" not in pages()
- def test_reading_order_lists_no_page_twice_within_one_path():
- text = (WIKI / "Reading-Order.md").read_text()
- sections = re.split(r"^## ", text, flags=re.MULTILINE)[1:]
- checked = 0
- for section in sections:
- title = section.splitlines()[0]
- rows = [
- line
- for line in section.splitlines()
- if re.match(r"\|\s*\d+\s*\|", line)
- ]
- if not rows:
- continue
- checked += 1
- targets = [PAGE_LINK.search(row).group(1) for row in rows if PAGE_LINK.search(row)]
- dupes = sorted({t for t in targets if targets.count(t) > 1})
- assert not dupes, f"{title}: listed twice: {dupes}"
- assert checked >= 5, "expected the core path and at least four tracks"
- def test_reading_order_pages_all_exist():
- missing = sorted(set(linked("Reading-Order")) - pages())
- assert not missing, f"Reading-Order links to missing pages: {missing}"
|