Plant a mutant in a Python file whose lines end in CRLF
CI / tests (pull_request) Successful in 4m8s

This commit is contained in:
2026-11-23 23:14:36 +01:00
parent fb3e526989
commit 4620365931
4 changed files with 41 additions and 4 deletions
+9 -1
View File
@@ -8,7 +8,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from failure import Failure
from task_bench.python_bugs import killed_mutants, task_text
from task_bench.planted_mutant import Mutant
from task_bench.planted_mutant import Mutant, mutated
from mutate_changes.tool_process import Ran
CALC = "def double(n):\n\treturn n * 2\n\n\ndef triple(n):\n\treturn (\n\t\tn * 3\n\t)\n"
@@ -163,6 +163,14 @@ class KilledMutantsTest(unittest.TestCase):
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_with_crlf_line_ends_gives_the_same_mutants_without_the_cr_and_applies_to_it(self):
(self.top / "bin/pkg/calc.py").write_bytes(CALC.replace("\n", "\r\n").encode())
found = killed_mutants(str(self.top), ["bin/pkg/calc.py"], self.mutmut(RESULTS.replace("calc.x_", "pkg.calc.x_")), 3)
self.assertEqual([(mutant.line, mutant.was, mutant.now) for mutant in found], [(2, (b"\treturn n * 2",), (b"\treturn n / 2",)), (6, (b"\treturn (", b"\t\tn * 3", b"\t)"), (b"\treturn [", b"\t\tn * 3", b"\t]"))])
changed = mutated((self.top / "bin/pkg/calc.py").read_bytes(), found[0])
self.assertIsNotNone(changed)
self.assertIn(b"\treturn n / 2\r\n", changed or b"")
def test_keeps_the_mutants_of_every_folder_mutmut_runs_in(self):
for path, text in (("tools/setup.cfg", "[tool:pytest]\n"), ("tools/pkg/calc.py", CALC)):
(self.top / path).parent.mkdir(parents=True, exist_ok=True)