61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
|
|
|
|
REPOSITORY_ROOT = Path(__file__).resolve().parents[2]
|
|
CHECK_DOCS = REPOSITORY_ROOT / "scripts" / "check_docs.py"
|
|
FIXTURES = Path(__file__).resolve().parent / "fixtures" / "docs"
|
|
|
|
|
|
def run_docs(root: Path, *excluded_paths: str) -> subprocess.CompletedProcess[str]:
|
|
return subprocess.run(
|
|
[
|
|
sys.executable,
|
|
str(CHECK_DOCS),
|
|
str(root),
|
|
*(argument for path in excluded_paths for argument in ("--exclude", path)),
|
|
],
|
|
cwd=REPOSITORY_ROOT,
|
|
text=True,
|
|
capture_output=True,
|
|
check=False,
|
|
)
|
|
|
|
|
|
def run_fixture(name: str) -> subprocess.CompletedProcess[str]:
|
|
return run_docs(FIXTURES / name)
|
|
|
|
|
|
class CheckDocsTest(unittest.TestCase):
|
|
def test_accepts_existing_file_and_heading(self) -> None:
|
|
result = run_fixture("valid.md")
|
|
|
|
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
|
self.assertIn("errors=0", result.stdout)
|
|
|
|
def test_rejects_missing_file(self) -> None:
|
|
result = run_fixture("missing-file.md")
|
|
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("missing file", result.stdout)
|
|
|
|
def test_rejects_missing_heading(self) -> None:
|
|
result = run_fixture("missing-anchor.md")
|
|
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("missing anchor", result.stdout)
|
|
|
|
def test_excludes_explicit_fixture_paths(self) -> None:
|
|
result = run_docs(FIXTURES, "missing-file.md", "missing-anchor.md")
|
|
|
|
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
|
self.assertIn("errors=0", result.stdout)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|