killinchu / tests /test_readme_link_contract.py
betterwithage's picture
fix: repair case-sensitive README links (#11)
3f82309
Raw
History Blame Contribute Delete
944 Bytes
from pathlib import Path
import re
import subprocess
import unittest
from urllib.parse import unquote
ROOT = Path(__file__).resolve().parents[1]
class ReadmeLinkContractTests(unittest.TestCase):
def test_relative_readme_links_match_tracked_paths_exactly(self):
readme = (ROOT / "README.md").read_text(encoding="utf-8")
tracked = set(
subprocess.check_output(["git", "ls-files"], cwd=ROOT, text=True).splitlines()
)
missing = []
for raw in re.findall(r"\]\(([^)]+)\)", readme):
target = raw.strip().split()[0].strip("<>")
if not target or target.startswith(("#", "http:", "https:", "mailto:")):
continue
path = unquote(target.split("#", 1)[0]).replace("\\", "/")
if path and path not in tracked:
missing.append(path)
self.assertEqual(missing, [])
if __name__ == "__main__":
unittest.main()