← back to Paul Conrad Archive
tests/test_py310_syntax.py
22 lines
"""Kamatera runs Python 3.10: every source file must parse under 3.10 grammar (e.g. no PEP 701 nested-quote f-strings)."""
import ast
import pathlib
import sys
import pytest
ROOT = pathlib.Path(__file__).resolve().parents[1]
FILES = sorted(p for d in ("src", "scripts", "tests") for p in (ROOT / d).rglob("*.py"))
@pytest.mark.skipif(sys.version_info < (3, 12), reason="running ON 3.10/3.11 already proves it")
@pytest.mark.parametrize("path", FILES, ids=lambda p: str(p.relative_to(ROOT)))
def test_parses_as_py310(path):
import subprocess
# ast feature_version does not enforce PEP 701 f-string rules, so check with a real 3.10 if present
py310 = next((p for p in ("/opt/homebrew/bin/python3.10", "/usr/local/bin/python3.10", str(pathlib.Path.home() / ".local/share/uv/python/cpython-3.10-macos-aarch64-none/bin/python3.10")) if pathlib.Path(p).exists()), None)
if py310 is None:
pytest.skip("no python3.10 interpreter on this host")
r = subprocess.run([py310, "-m", "py_compile", str(path)], capture_output=True, text=True)
assert r.returncode == 0, r.stderr