scripts/tests/reproduction_utils/test_move_assign.py
scripts/tests/reproduction_utils/test_move_assign.pyBrowse 41 files
732 tokens
2,517 bytes
Token encoding: o200k_base
Snapshot a9fb1c3
← Back to SKILL.md
1import sys2from pathlib import Path3 4import pytest5 6sys.path.insert(0, str(Path(__file__).resolve().parents[2]))7 8from mechanical_refactor_reproduction_utils import Repro9from reproduction_testlib import _apply # noqa: F40110 11 12def test_move_assign_relocates_a_module_constant(tmp_path: Path) -> None:13 """The assignment is cut verbatim from the source and lands after the destination's imports."""14 (tmp_path / "src.py").write_text(15 "import os\n\nLIMIT = 480 # seconds\n\n\ndef stay():\n return LIMIT\n"16 )17 (tmp_path / "dst.py").write_text("import sys\n\n\ndef keep():\n return 1\n")18 r = Repro("b", "t").move_assign("LIMIT", src="src.py", dst="dst.py")19 _apply(r, tmp_path)20 assert "LIMIT" not in (tmp_path / "src.py").read_text().split("def stay")[0]21 assert (tmp_path / "dst.py").read_text() == (22 "import sys\n\nLIMIT = 480 # seconds\n\n\ndef keep():\n return 1\n"23 )24 25 26def test_move_assign_pastes_above_the_named_sibling(tmp_path: Path) -> None:27 """With before=, the constant lands immediately above the named top-level statement."""28 (tmp_path / "src.py").write_text("RATIO = 3\n")29 (tmp_path / "dst.py").write_text("def first():\n return 1\n")30 r = Repro("b", "t").move_assign("RATIO", src="src.py", dst="dst.py", before="first")31 _apply(r, tmp_path)32 assert (tmp_path / "dst.py").read_text() == (33 "RATIO = 3\n\ndef first():\n return 1\n"34 )35 36 37def test_move_assign_relocates_an_annotated_constant(tmp_path: Path) -> None:38 """An annotated module constant (AnnAssign) is cut verbatim with its annotation intact."""39 (tmp_path / "src.py").write_text(40 "import os\n\nLIMIT: int = 480\n\n\ndef stay():\n return LIMIT\n"41 )42 (tmp_path / "dst.py").write_text("import sys\n\n\ndef keep():\n return 1\n")43 r = Repro("b", "t").move_assign("LIMIT", src="src.py", dst="dst.py")44 _apply(r, tmp_path)45 assert "LIMIT" not in (tmp_path / "src.py").read_text().split("def stay")[0]46 assert (tmp_path / "dst.py").read_text() == (47 "import sys\n\nLIMIT: int = 480\n\n\ndef keep():\n return 1\n"48 )49 50 51def test_move_assign_missing_source_raises(tmp_path: Path) -> None:52 """A name with no module-level assignment in the source fails loudly."""53 (tmp_path / "src.py").write_text("x = 1\n")54 (tmp_path / "dst.py").write_text("import os\n")55 r = Repro("b", "t").move_assign("MISSING", src="src.py", dst="dst.py")56 with pytest.raises(AssertionError):57 _apply(r, tmp_path)58