-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_scripts_compile.py
More file actions
28 lines (19 loc) · 914 Bytes
/
test_scripts_compile.py
File metadata and controls
28 lines (19 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Every script in `.github/scripts/` must parse on the project's pinned Python.
Catches a class of regression where a script lands with a syntax error that
the corresponding CI gate happens to not exercise. Cheap and broad: one test,
one `py_compile.compile` per script.
"""
from __future__ import annotations
import py_compile
from pathlib import Path
import pytest
REPO_ROOT = Path(__file__).resolve().parent.parent
SCRIPTS_DIR = REPO_ROOT / ".github" / "scripts"
def _ci_scripts() -> list[Path]:
return sorted(p for p in SCRIPTS_DIR.glob("*.py") if p.is_file())
@pytest.mark.parametrize("script", _ci_scripts(), ids=lambda p: p.name)
def test_ci_script_compiles(script: Path) -> None:
try:
py_compile.compile(str(script), doraise=True)
except py_compile.PyCompileError as exc: # pragma: no cover — failure path
pytest.fail(f"{script.name} failed to compile: {exc.msg}")