scripts/tests/proof_generator/generator_testlib.py
scripts/tests/proof_generator/generator_testlib.pyBrowse 41 files
793 tokens
3,137 bytes
Token encoding: o200k_base
Snapshot a9fb1c3
← Back to SKILL.md
1import subprocess2import sys3from pathlib import Path4 5import pytest6 7sys.path.insert(0, str(Path(__file__).resolve().parents[2]))8 9from mechanical_refactor_proof_generator import (10 infer_recipe,11 recipe_to_script,12)13 14 15def _git(repo: Path, *args: str) -> str:16 return subprocess.run(17 ["git", *args], cwd=repo, check=True, capture_output=True, text=True18 ).stdout.strip()19 20 21def _write(repo: Path, **files: str | None) -> None:22 for name, content in files.items():23 path = repo / name.replace("__", "/")24 if content is None:25 path.unlink()26 else:27 path.parent.mkdir(parents=True, exist_ok=True)28 path.write_text(content)29 30 31def _commit(repo: Path, message: str) -> str:32 _git(repo, "add", "-A")33 _git(repo, "commit", "-q", "-m", message)34 return _git(repo, "rev-parse", "HEAD")35 36 37def _method_onto_class(repo: Path) -> None:38 """Stage a base + a 'move foo from M onto C, lower the caller' commit."""39 _write(40 repo,41 **{42 "model.py": (43 "class M:\n"44 " @staticmethod\n"45 " def foo(self, x):\n"46 " return x + 1\n"47 "\n"48 " def other(self):\n"49 " return 0\n"50 ),51 "comp.py": "class C:\n def keep(self):\n return 1\n",52 "caller.py": (53 "class K:\n"54 " def run(self):\n"55 " from model import M\n"56 "\n"57 " return M.foo(self.c, 9)\n"58 ),59 },60 )61 _commit(repo, "base")62 _write(63 repo,64 **{65 "model.py": "class M:\n def other(self):\n return 0\n",66 "comp.py": (67 "class C:\n"68 " def keep(self):\n"69 " return 1\n"70 "\n"71 " def foo(self, x):\n"72 " return x + 1\n"73 ),74 "caller.py": (75 "class K:\n def run(self):\n return self.c.foo(9)\n"76 ),77 },78 )79 _commit(repo, "move foo onto C")80 81 82def _free_function_move_with_module_level_caller(repo: Path) -> None:83 """Stage a free function moved model.py -> util.py whose caller imports it at module84 level (so the repoint shows up in the symmetric module-level import diff)."""85 _write(86 repo,87 **{88 "model.py": "def keep():\n return 0\n\n\ndef resolve(m):\n return m\n",89 "util.py": "import os\n",90 "caller.py": (91 "from model import resolve\n\n\ndef run(m):\n return resolve(m)\n"92 ),93 },94 )95 _commit(repo, "base")96 _write(97 repo,98 **{99 "model.py": "def keep():\n return 0\n",100 "util.py": "import os\n\n\ndef resolve(m):\n return m\n",101 "caller.py": (102 "from util import resolve\n\n\ndef run(m):\n return resolve(m)\n"103 ),104 },105 )106 _commit(repo, "move resolve to util")107