import pathlib import subprocess import sys import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from repo_checks import ROOT # Runs a launcher as a Python of the version in argv[2] would, up to its first import of the setup's own code. AS_VERSION = "import sys; launcher = sys.argv[1]; sys.version_info = tuple(map(int, sys.argv[2].split('.'))); sys.version = sys.argv[2] + ' (main)'; sys.argv = [launcher, '--help']; exec(compile(open(launcher).read(), launcher, 'exec'), {'__file__': launcher, '__name__': '__main__'})" class LauncherPython(unittest.TestCase): def ran(self, tool: str, version: str) -> subprocess.CompletedProcess[str]: return subprocess.run([sys.executable, "-c", AS_VERSION, str(ROOT / "bin" / tool), version], capture_output=True, text=True) def test_a_command_that_starts_claudes_names_the_python_it_needs_where_python3_is_older(self) -> None: for tool in ("build-epic", "build-release"): with self.subTest(tool): ran = self.ran(tool, "3.13.9") self.assertEqual((ran.returncode, ran.stdout, ran.stderr), (1, "", f"{tool} needs Python 3.14 or later as python3 on PATH; it found Python 3.13.9\n")) def test_it_starts_on_the_python_it_needs(self) -> None: for tool in ("build-epic", "build-release"): with self.subTest(tool): ran = self.ran(tool, "3.14.0") self.assertEqual((ran.returncode, ran.stderr), (0, "")) self.assertIn(f"usage: {tool}", ran.stdout)