Have mutmut copy each entry of the folder rather than '.', which copied mutants/ into itself and collected the tests twice
This commit is contained in:
@@ -15,7 +15,7 @@ from mutate_changes.tool_process import failed, Ran, run_tool
|
||||
from failure import Failure
|
||||
from mutate_changes.mutmut_mutants import function_keys, mutant_globs, mutated_line, named, statuses
|
||||
from git_cli.git_repo import git
|
||||
from mutate_changes.mutmut_setup import leaving_out, left_out, mutmut_config
|
||||
from mutate_changes.mutmut_setup import left_out, mutmut_config
|
||||
|
||||
CAUGHT = frozenset({"caught by type check", "killed"})
|
||||
CONFIGS = ("pyproject.toml", "setup.cfg")
|
||||
@@ -82,8 +82,8 @@ def mutate_folder(top: str, path: str, files: dict[str, frozenset[int]], prefix:
|
||||
return Failure(f"could not make a scratch folder in {top}: {failure}")
|
||||
try:
|
||||
copy = os.path.join(scratch, "copy")
|
||||
copy_files(root, listed.split("\0"), copy)
|
||||
return mutate_copy(copy, folder, ["mutmut", "run", "--max-children", str(jobs), *globs], prefix)
|
||||
copied = copy_files(root, listed.split("\0"), copy)
|
||||
return mutate_copy(copy, copied, folder, ["mutmut", "run", "--max-children", str(jobs), *globs], prefix)
|
||||
except OSError as failure:
|
||||
return Failure(f"could not set mutmut up in {scratch}, a copy of {root}: {failure}")
|
||||
finally:
|
||||
@@ -117,8 +117,11 @@ def project_setup(root: str) -> str | Failure:
|
||||
return Failure(f"could not read the mutmut settings in {root}: {failure}")
|
||||
|
||||
|
||||
def copy_files(root: str, paths: list[str], copy: str) -> None:
|
||||
"""Copy the files git lists in root, tracked or not ignored, to copy, symlinks as symlinks. Leaves out mutmut's own mutants/ and the scratch folders of runs that never cleaned up."""
|
||||
def copy_files(root: str, paths: list[str], copy: str) -> list[str]:
|
||||
"""Copy the files git lists in root, tracked or not ignored, to copy, symlinks as symlinks, and name each file and folder copied to copy's top.
|
||||
|
||||
Leaves out mutmut's own mutants/ and the scratch folders of runs that never cleaned up."""
|
||||
copied = set()
|
||||
for path in paths:
|
||||
source, target = os.path.join(root, path), os.path.join(copy, path)
|
||||
gone_or_submodule = not os.path.lexists(source) or os.path.isdir(source) and not os.path.islink(source)
|
||||
@@ -126,10 +129,12 @@ def copy_files(root: str, paths: list[str], copy: str) -> None:
|
||||
continue
|
||||
os.makedirs(os.path.dirname(target), exist_ok=True)
|
||||
shutil.copy2(source, target, follow_symlinks=False)
|
||||
copied.add(path.split("/")[0])
|
||||
return sorted(copied)
|
||||
|
||||
|
||||
def mutate_copy(copy: str, folder: Folder, argv: list[str], prefix: str | None) -> list[str] | Failure:
|
||||
ran = run_until_stats_pass(copy, folder, argv, prefix)
|
||||
def mutate_copy(copy: str, copied: list[str], folder: Folder, argv: list[str], prefix: str | None) -> list[str] | Failure:
|
||||
ran = run_until_stats_pass(copy, copied, folder, argv, prefix)
|
||||
if isinstance(ran, Failure):
|
||||
return ran
|
||||
output, left = ran
|
||||
@@ -140,17 +145,17 @@ def mutate_copy(copy: str, folder: Folder, argv: list[str], prefix: str | None)
|
||||
return results if isinstance(results, Failure) else failed(f"mutmut results in {folder.label}", results)
|
||||
shown, counted = not_killed(folder, statuses(results.output), copy)
|
||||
unreached = " No test reaches them." if NO_TEST in output else ""
|
||||
left_files = sorted({nodeid.partition("::")[0].removeprefix("mutants/") for nodeid in left})
|
||||
left_files = sorted({option.partition("=")[2].partition("::")[0] for option in left})
|
||||
left_note = f" Left out tests in {', '.join(left_files)} that fail without a mutant." if left else ""
|
||||
return [f"mutmut in {folder.label}: {counted} mutants on changed lines, {len(shown)} not killed.{unreached}{left_note}", *shown]
|
||||
|
||||
|
||||
def run_until_stats_pass(copy: str, folder: Folder, argv: list[str], prefix: str | None) -> tuple[str, list[str]] | Failure:
|
||||
"""mutmut's output, and the nodeid of each test it left out because the test fails before any mutant: mutmut runs no mutant while one fails."""
|
||||
ran = configured_run(copy, folder, LIST_FAILURES, argv, prefix)
|
||||
def run_until_stats_pass(copy: str, copied: list[str], folder: Folder, argv: list[str], prefix: str | None) -> tuple[str, list[str]] | Failure:
|
||||
"""mutmut's output, and the options that left out each test that fails before any mutant: mutmut runs no mutant while one fails."""
|
||||
ran = configured_run(copy, copied, folder, LIST_FAILURES, argv, prefix)
|
||||
left: list[str] = []
|
||||
if isinstance(ran, Ran) and STATS_FAILED in ran.output and (left := left_out(ran.output)):
|
||||
ran = configured_run(copy, folder, leaving_out(left, copy), argv, prefix)
|
||||
ran = configured_run(copy, copied, folder, left, argv, prefix)
|
||||
if isinstance(ran, Failure):
|
||||
return ran
|
||||
if ran.code and NO_MUTANT not in ran.output and NO_TEST not in ran.output:
|
||||
@@ -158,8 +163,8 @@ def run_until_stats_pass(copy: str, folder: Folder, argv: list[str], prefix: str
|
||||
return ran.output, left
|
||||
|
||||
|
||||
def configured_run(copy: str, folder: Folder, options: list[str], argv: list[str], prefix: str | None) -> Ran | Failure:
|
||||
config = mutmut_config(folder.setup, sorted(folder.files), options)
|
||||
def configured_run(copy: str, copied: list[str], folder: Folder, options: list[str], argv: list[str], prefix: str | None) -> Ran | Failure:
|
||||
config = mutmut_config(folder.setup, sorted(folder.files), copied, options)
|
||||
if isinstance(config, Failure):
|
||||
return Failure(f"{folder.label}: {config.reason}")
|
||||
pathlib.Path(copy, "setup.cfg").write_text(config, encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user