test_free_statement.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. """The maintainer's "free and not for sale" statement is on the README and both wiki pages.
  2. The support links in the statement must be links the README already carries,
  3. so a page cannot quietly point readers at a donation address nobody reviewed.
  4. """
  5. import re
  6. from pathlib import Path
  7. ROOT = Path(__file__).resolve().parent.parent
  8. README = ROOT / "README.md"
  9. WHY = ROOT / "docs" / "wiki" / "Why-This-Exists.md"
  10. HOME = ROOT / "docs" / "wiki" / "Home.md"
  11. HEADINGS = {
  12. README: "## Free, and not for sale",
  13. WHY: "## Why this is free and not for sale",
  14. HOME: "## Why this is free and not for sale",
  15. }
  16. # Phrases every copy must keep: the meaning, not the whole wording.
  17. COMMON = ["System76 Pangolin", "knowledge is power", "gatekeeping", "90K in 90 days", "under no obligation", "share it"]
  18. # Only the long version carries the school and certificate claims.
  19. LONG_ONLY = ["CISSP", "about twelve years", "WGU", "not an indictment of WGU", "college as a whole", "four-year degree"]
  20. URL = re.compile(r"\]\((https?://[^)\s]+)\)")
  21. def section(text: str, heading: str) -> str:
  22. start = text.index(heading)
  23. rest = text[start + len(heading):]
  24. end = re.search(r"^## ", rest, re.MULTILINE)
  25. return heading + (rest[: end.start()] if end else rest)
  26. def foreign_support_links(body: str, readme_text: str) -> list[str]:
  27. """External links in body that the README does not already contain."""
  28. return [u for u in URL.findall(body) if u not in readme_text]
  29. def test_each_page_carries_the_statement():
  30. for path, heading in HEADINGS.items():
  31. text = path.read_text()
  32. assert heading in text, f"{path.name}: missing {heading!r}"
  33. body = section(text, heading)
  34. missing = [p for p in COMMON if p not in body]
  35. assert not missing, f"{path.name}: statement lost {missing}"
  36. assert "—" not in body and "–" not in body, f"{path.name}: dash in statement"
  37. def test_long_version_keeps_the_school_and_cert_claims():
  38. body = section(WHY.read_text(), HEADINGS[WHY])
  39. missing = [p for p in LONG_ONLY if p not in body]
  40. assert not missing, f"long version lost {missing}"
  41. def test_support_links_are_already_in_the_readme():
  42. readme_text = README.read_text()
  43. for path, heading in HEADINGS.items():
  44. body = section(path.read_text(), heading)
  45. own_wiki = "github.com/ChiefGyk3D/Clouds-Against-Humanity/wiki/"
  46. bad = [u for u in foreign_support_links(body, readme_text) if own_wiki not in u]
  47. assert not bad, f"{path.name}: links not in README.md: {bad}"
  48. readme_body = section(readme_text, HEADINGS[README])
  49. for url in ("https://patreon.com/chiefgyk3d", "https://streamelements.com/chiefgyk3d/tip"):
  50. assert url in readme_body and readme_text.count(url) >= 2
  51. def test_guard_bites_on_a_link_the_readme_lacks():
  52. body = "[tip](https://example.invalid/tip) and [Patreon](https://patreon.com/chiefgyk3d)"
  53. assert foreign_support_links(body, README.read_text()) == ["https://example.invalid/tip"]
  54. assert section("## A\nx\n## B\ny", "## A") == "## A\nx\n"