from pathlib import Path ROOT = Path(__file__).resolve().parents[1] def _strip_inline_comment(line: str) -> str: return line.split("#", 1)[0].strip() def test_requirements_have_version_specifiers(): unpinned = [] for raw_line in (ROOT / "requirements.txt").read_text(encoding="utf-8").splitlines(): line = _strip_inline_comment(raw_line) if not line: continue if line.startswith(("-", "--")): continue if "@" in line: continue if not any(op in line for op in ("==", ">=", "<=", "~=", "!=", ">")): unpinned.append(line) assert unpinned == []