Test the planters' and mutmut's report on the lines the mutation run left alive
CI / tests (pull_request) Successful in 3m53s

This commit is contained in:
2026-11-23 21:58:35 +01:00
parent 8bab7b3a6f
commit fc9749aa0a
3 changed files with 64 additions and 8 deletions
+20 -4
View File
@@ -99,14 +99,16 @@ class KilledMutantsTest(unittest.TestCase):
(self.top / path).parent.mkdir(parents=True, exist_ok=True)
(self.top / path).write_text(text)
self.ran: list[tuple[list[str], str, list[str]]] = []
# Where the fake mutmut writes its copy of calc.py, from the folder it runs in.
self.copy = "pkg/calc.py"
def mutmut(self, results: str = RESULTS, code: int = 0, said: str = ""):
def run(argv: list[str], cwd: str) -> Ran:
self.ran.append((argv, cwd, sorted(str(path.relative_to(cwd)) for path in pathlib.Path(cwd).rglob("*") if path.is_file())))
if argv[:2] == ["mutmut", "results"]:
return Ran(0, results)
pathlib.Path(cwd, "mutants/pkg").mkdir(parents=True)
pathlib.Path(cwd, "mutants/pkg/calc.py").write_text(COPY)
pathlib.Path(cwd, "mutants", self.copy).parent.mkdir(parents=True)
pathlib.Path(cwd, "mutants", self.copy).write_text(COPY)
return Ran(code, said)
return run
@@ -138,8 +140,22 @@ class KilledMutantsTest(unittest.TestCase):
self.assertIsInstance(found, Failure)
self.assertIn(reason, found.reason)
def test_a_file_that_is_gone_is_a_failure(self):
self.assertIsInstance(killed_mutants(str(self.top), ["bin/pkg/gone.py"], self.mutmut(), 3), Failure)
def test_a_file_that_is_gone_is_a_failure_that_names_the_tree(self):
found = killed_mutants(str(self.top), ["bin/pkg/gone.py"], self.mutmut(), 3)
self.assertIsInstance(found, Failure)
self.assertIn(f"could not read the files to mutate in {self.top}", found.reason)
def test_mutates_a_function_on_the_files_first_line_and_one_on_its_last(self):
(self.top / "bin/pkg/ends.py").write_text("def first(n): return n + 1\n\n\ndef last(n): return n * 2")
killed_mutants(str(self.top), ["bin/pkg/ends.py"], self.mutmut(), 3)
self.assertEqual(self.ran[0][0][4:], ["pkg.ends.x_first*", "pkg.ends.x_last*"])
def test_a_file_in_the_folder_mutmut_runs_in_at_the_top_keeps_its_path(self):
(self.top / "setup.cfg").write_text("[tool:pytest]\n")
(self.top / "calc.py").write_text(CALC)
self.copy = "calc.py"
found = killed_mutants(str(self.top), ["calc.py"], self.mutmut(), 3)
self.assertEqual(found[0], Mutant("calc.py", 2, "calc.py:2 x_double__mutmut_1", (b"\treturn n * 2",), (b"\treturn n / 2",)))
class TaskTextTest(unittest.TestCase):