scripts/tests/reproduction_utils/test_delete_file.py
scripts/tests/reproduction_utils/test_delete_file.pyBrowse 41 files
606 tokens
2,355 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 9import mechanical_refactor_reproduction_utils as rr10from mechanical_refactor_reproduction_utils import (11 Repro,12 _def_span,13 _find_class,14 _find_def,15 _replace_span,16 _slice_span,17 dedent,18 exec_command,19 git_add_and_commit,20 verify_mechanical_refactor,21)22from reproduction_testlib import _apply, _commit, _git, _write # noqa: F40123 24 25def test_delete_file_removes_emptied_source(tmp_path: Path) -> None:26 """delete_file removes a source module left empty after its defs relocated."""27 (tmp_path / "gone.py").write_text("import os\n")28 r = Repro("b", "t").delete_file("gone.py")29 _apply(r, tmp_path)30 assert not (tmp_path / "gone.py").exists()31 32 33def test_delete_file_refuses_a_file_with_remaining_definitions(tmp_path: Path) -> None:34 """Deleting a module that still contains defs must fail loudly."""35 (tmp_path / "live.py").write_text("def still_used():\n return 42\n")36 r = Repro("b", "t").delete_file("live.py")37 with pytest.raises(AssertionError):38 _apply(r, tmp_path)39 assert (tmp_path / "live.py").exists()40 41 42def test_delete_file_on_a_missing_path_is_a_no_op(tmp_path: Path) -> None:43 """Deleting an already-absent file does nothing and raises nothing."""44 r = Repro("b", "t").delete_file("nope.py")45 _apply(r, tmp_path)46 assert not (tmp_path / "nope.py").exists()47 48 49def test_delete_file_allows_a_bare_module_logger(tmp_path: Path) -> None:50 """A leftover module holding only imports and a `logger` is deletable scaffolding."""51 (tmp_path / "gone.py").write_text(52 "import logging\n\nlogger = logging.getLogger(__name__)\n"53 )54 r = Repro("b", "t").delete_file("gone.py")55 _apply(r, tmp_path)56 assert not (tmp_path / "gone.py").exists()57 58 59def test_delete_file_still_refuses_a_non_logger_assignment(tmp_path: Path) -> None:60 """A leftover module-level assignment other than a logger blocks deletion."""61 (tmp_path / "live.py").write_text("CONFIG = {'a': 1}\n")62 r = Repro("b", "t").delete_file("live.py")63 with pytest.raises(AssertionError):64 _apply(r, tmp_path)65 assert (tmp_path / "live.py").exists()66 67 68# --- adversarial audit: extract_function -----------------------------------------69