Datasets:
docs: complete the card + contributing guide + completeness guard
Browse files
tests/test_readme_complete.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The README must stay complete.
|
| 2 |
+
|
| 3 |
+
Not a style rule. Each item here is something a stranger needs in order to
|
| 4 |
+
decide whether to trust this and how to run it, and every one of them has gone
|
| 5 |
+
missing from some README in this portfolio at some point -- a badge pointing at
|
| 6 |
+
a workflow that had been renamed, a quickstart whose output no longer matched,
|
| 7 |
+
a contributing pointer to a file that did not exist.
|
| 8 |
+
|
| 9 |
+
The checks are structural. Whether the *content* is honest is enforced
|
| 10 |
+
separately, by the guards that re-run the transcripts and diff them.
|
| 11 |
+
"""
|
| 12 |
+
from __future__ import annotations
|
| 13 |
+
|
| 14 |
+
import re
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
|
| 17 |
+
HERE = Path(__file__).resolve().parents[1]
|
| 18 |
+
_RAW = (HERE / "README.md").read_text(encoding="utf-8")
|
| 19 |
+
# Hugging Face cards open with YAML front-matter. It is metadata, not prose,
|
| 20 |
+
# and counting it as the top of the document made the tagline check look past
|
| 21 |
+
# the tagline entirely.
|
| 22 |
+
README = re.sub(r"\A---\n.*?\n---\n", "", _RAW, flags=re.S)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def test_there_is_a_one_line_description_near_the_top() -> None:
|
| 26 |
+
"""A stranger should know what this is within two screens-worth of text."""
|
| 27 |
+
head = "\n".join(README.splitlines()[:14])
|
| 28 |
+
# The tagline may wrap; `re.S` lets `.` cross the line break.
|
| 29 |
+
assert re.search(r"^\*\*.+?\*\*", head, re.M | re.S), (
|
| 30 |
+
"no bold description in the first 14 lines after any front-matter"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def test_every_required_section_is_present() -> None:
|
| 35 |
+
missing = [s for s in ['Why this exists', '30-second quickstart', 'Scope, honestly', 'Contributing', 'Citation', 'Licence'] if f"## {s}" not in README]
|
| 36 |
+
assert not missing, f"README is missing section(s): {missing}"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def test_every_badge_is_an_image_link_with_an_https_target() -> None:
|
| 40 |
+
badges = re.findall(r"!\[[^\]]*\]\(([^)]+)\)", README)
|
| 41 |
+
assert badges, "no badges"
|
| 42 |
+
bad = [b for b in badges if not b.startswith("https://")]
|
| 43 |
+
assert not bad, f"badge(s) with a non-https target: {bad}"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_local_links_point_at_files_that_exist() -> None:
|
| 47 |
+
"""A dead relative link is the cheapest possible broken promise."""
|
| 48 |
+
targets = re.findall(r"\]\((?!https?://|#)([^)\s]+)\)", README)
|
| 49 |
+
missing = [t for t in targets if not (HERE / t.split("#")[0]).exists()]
|
| 50 |
+
assert not missing, f"README links to path(s) that do not exist: {missing}"
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def test_it_cross_links_the_portfolio_and_the_docs_site() -> None:
|
| 54 |
+
assert "nickharris808.github.io/physics-lint" in README, "no docs-site link"
|
| 55 |
+
assert re.search(r"rest of the toolkit|## Related", README), (
|
| 56 |
+
"no cross-links to the sibling artifacts"
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def test_the_scope_section_says_what_this_does_not_prove() -> None:
|
| 61 |
+
m = re.search(r"^## Scope, honestly$(.*?)(?=^## |\Z)", README, re.M | re.S)
|
| 62 |
+
assert m, "no honest-scope section"
|
| 63 |
+
body = m.group(1).lower()
|
| 64 |
+
assert re.search(r"\bnot\b|never|does not", body), (
|
| 65 |
+
"the scope section states no limitation, which is not a scope section"
|
| 66 |
+
)
|