Answer stability round 1: 0 🔴, 6 🟡 (0 misread); leave blank lines and empty files out of what a chunk touched, spell a name that holds a backtick as Markdown does, pin two mutants, and sort a chunk's IDs
This commit is contained in:
@@ -103,6 +103,30 @@ class PredictedTest(unittest.TestCase):
|
||||
assert isinstance(touches, dict)
|
||||
self.assertEqual(predicted(f"Touches:\n\n{rendered(touches)}\n"), touches)
|
||||
|
||||
def test_a_name_that_holds_backticks_takes_a_longer_run_with_a_space_inside_each_end(self) -> None:
|
||||
self.assertEqual(predicted("Touches:\n- `a.md`: `` ## The `foo` tool `` (small), ``` `` ```, `` `x` ``\n"), {"a.md": (Part("## The `foo` tool", small=True), Part("``"), Part("`x`"))})
|
||||
self.assertEqual(rendered({"a.md": (Part("## The `foo` tool", small=True), Part("``"))}), "- `a.md`: `` ## The `foo` tool `` (small), ``` `` ```")
|
||||
|
||||
def test_a_name_ends_only_at_a_run_as_long_as_the_one_that_opens_it(self) -> None:
|
||||
self.assertEqual(predicted("Touches:\n- `a.md`: `` a ``` b ``, `c``d`\n"), {"a.md": (Part("a ``` b"), Part("c``d"))})
|
||||
|
||||
def test_a_path_holds_any_character_and_a_single_backtick_keeps_a_names_spaces(self) -> None:
|
||||
self.assertEqual(predicted("Touches:\n- `my file.md`: ` x `\n- `` a`b.md ``\n"), {"my file.md": (Part(" x "),), "a`b.md": ()})
|
||||
|
||||
def test_rendered_reads_back_whatever_a_path_or_a_name_holds(self) -> None:
|
||||
touches = {"my file.md": (Part("## todo.md: under `Touches:` in its detail"), Part("## ``a`` and `b`", small=True), Part("`"), Part("## ends in `x`"), Part(" x "), Part("lines 2-3")), "a`b.md": (), "c, d: e.md": (Part("# T"),)}
|
||||
self.assertEqual(predicted(f"Touches:\n\n{rendered(touches)}\n"), touches)
|
||||
|
||||
def test_a_longer_run_without_its_spaces_or_its_end_or_a_name_is_a_failure(self) -> None:
|
||||
for bullet in ("- `a.md`: ``## A``", "- `a.md`: `` ## A", "- `a.md`: `` ## A `", "- `a.md`: `` ``", "- `a.md`: ", "- `a.md`:", "- `a.md`: `f`, ", "- `a.md`: `f`,`g`", "- ``", "- `a.md` (small)", "- `a.md`: `f` (small) (small)"):
|
||||
with self.subTest(bullet):
|
||||
self.assertIsInstance(predicted(f"Touches:\n\n{bullet}\n"), Failure)
|
||||
|
||||
def test_a_range_that_runs_backwards_is_a_failure_that_says_so(self) -> None:
|
||||
found = predicted("Touches:\n\n- `bin/a.py`: `f`, lines 20-10\n")
|
||||
assert isinstance(found, Failure)
|
||||
self.assertEqual(found.reason, "the bullet '- `bin/a.py`: `f`, lines 20-10' under `Touches:` holds a line range whose first line comes after its last")
|
||||
|
||||
def test_together_joins_items_and_keeps_small_only_where_each_says_so(self) -> None:
|
||||
joined = together([{"a.py": (Part("f", small=True), Part("g", small=True))}, {"a.py": (Part("f"),), "b.md": ()}, {"b.md": (Part("# T"),)}])
|
||||
self.assertEqual(joined, {"a.py": (Part("f"), Part("g", small=True)), "b.md": ()})
|
||||
@@ -162,6 +186,28 @@ class FilePartsTest(unittest.TestCase):
|
||||
self.assertEqual(self.names("a.py", PYTHON, 99), {"(module)"})
|
||||
self.assertEqual(self.names("a.py", "", 1), {"(module)"})
|
||||
|
||||
def test_python_names_no_part_for_a_blank_line_between_statements(self) -> None:
|
||||
text = "def a():\n\treturn 1\n\n\ndef b():\n\treturn 2\n\n# end\n\n"
|
||||
self.assertEqual(self.names("a.py", text, 1, 2, 3, 4), {"a"})
|
||||
self.assertEqual(self.names("a.py", text, 3, 4), set())
|
||||
self.assertEqual(self.names("a.py", text, 7, 9), set())
|
||||
self.assertEqual(self.names("a.py", text, 8), {"b"})
|
||||
self.assertEqual(self.names("a.py", "# only\n\n", 2), set())
|
||||
|
||||
def test_python_names_the_part_a_blank_line_inside_a_statement_lies_in(self) -> None:
|
||||
self.assertEqual(self.names("a.py", "def a():\n\tx = 1\n\n\treturn x\n\nT = \"\"\"\n\n\"\"\"\n", 3, 7), {"a", "T"})
|
||||
|
||||
def test_blank_lines_name_their_parts_where_separators_count(self) -> None:
|
||||
text = "def a():\n\treturn 1\n\n\ndef b():\n\treturn 2\n\n"
|
||||
self.assertEqual(file_parts.part_names("a.py", text, [3, 7], separators=True), {"b"})
|
||||
self.assertEqual(file_parts.part_names("a.py", "# only\n\n", [2], separators=True), {"(module)"})
|
||||
self.assertEqual(file_parts.part_names("a.md", "# A\n\n", [2], separators=True), {"# A"})
|
||||
|
||||
def test_python_without_statements_names_the_module_only_for_a_line(self) -> None:
|
||||
self.assertEqual(self.names("a.py", ""), set())
|
||||
self.assertEqual(self.names("a.py", "# only a comment\n"), set())
|
||||
self.assertEqual(self.names("a.py", "# only a comment\n", 1), {"(module)"})
|
||||
|
||||
def test_python_that_does_not_parse_has_no_names(self) -> None:
|
||||
self.assertIsNone(self.names("a.py", "def (:\n", 1))
|
||||
|
||||
@@ -171,6 +217,7 @@ class FilePartsTest(unittest.TestCase):
|
||||
|
||||
def test_python_gives_a_line_after_the_last_statement_to_it(self) -> None:
|
||||
self.assertEqual(self.names("a.py", "A = 1\nB = 2\nC = 3\n# end\n", 4), {"C"})
|
||||
self.assertEqual(self.names("a.py", "class A:\n\tdef f(self):\n\t\tpass\n\n# end\n", 5), {"A"})
|
||||
|
||||
def test_markdown_drops_a_headings_trailing_space_and_puts_a_line_past_the_end_under_the_last_heading(self) -> None:
|
||||
self.assertEqual(self.names("a.md", "# A \ntext\n## B\n", 2, 4), {"# A", "## B"})
|
||||
@@ -180,6 +227,15 @@ class FilePartsTest(unittest.TestCase):
|
||||
self.assertEqual(self.names("a.md", MARKDOWN, 3, 5, 8), {"# Title"})
|
||||
self.assertEqual(self.names("a.md", MARKDOWN, 13), {"## Goals"})
|
||||
|
||||
def test_markdown_names_no_part_for_a_blank_line(self) -> None:
|
||||
self.assertEqual(self.names("a.md", "# A\ntext\n\n## End\nmore\n", 3, 4, 5), {"## End"})
|
||||
self.assertEqual(self.names("a.md", "# A\n \t\n", 2), set())
|
||||
|
||||
def test_markdown_closes_a_fence_only_on_its_own_character_at_least_as_long(self) -> None:
|
||||
self.assertEqual(self.names("a.md", "# A\n````\n```\n# not\n````\n# B\ntext\n", 4, 7), {"# A", "# B"})
|
||||
self.assertEqual(self.names("a.md", "# A\n```\n~~~\n# not\n```\n# B\ntext\n", 4, 7), {"# A", "# B"})
|
||||
self.assertEqual(self.names("a.md", "# A\n~~~\n~~~ not the end\n# not\n~~~~~ \n# B\ntext\n", 4, 7), {"# A", "# B"})
|
||||
|
||||
def test_any_other_file_has_no_names(self) -> None:
|
||||
self.assertIsNone(self.names("run.sh", "echo\n", 1))
|
||||
|
||||
@@ -303,6 +359,31 @@ class TouchedTest(unittest.TestCase):
|
||||
self.repo.commit({"gone.py": "x = 2\ny = 3\n", "run.sh": "one\n"})
|
||||
self.assertEqual(diff_parts.touched(self.base, head, self.repo.folder, set()), {"gone.py": (Part("x"),)})
|
||||
|
||||
def test_reads_the_diff_up_to_head_whatever_the_work_tree_holds(self) -> None:
|
||||
text = "def f():\n\treturn 1\n\n\ndef g():\n\treturn 2\n"
|
||||
self.base = self.repo.commit({"gone.py": text})
|
||||
head = self.repo.commit({"gone.py": text.replace("return 2", "return 3")})
|
||||
pathlib.Path(self.repo.folder, "gone.py").write_text("def new():\n\treturn 0\n\n\n" + text.replace("return 2", "return 3"), encoding="utf-8")
|
||||
self.assertEqual(diff_parts.touched(self.base, head, self.repo.folder, set()), {"gone.py": (Part("g"),)})
|
||||
|
||||
def test_an_inserted_function_or_section_does_not_name_its_neighbours(self) -> None:
|
||||
text = "def a():\n\treturn 1\n\n\ndef b():\n\treturn 2\n\n\ndef c():\n\treturn 3\n"
|
||||
self.base = self.repo.commit({"m.py": text, "m.md": "# A\ntext\n\n## B\ntext\n", "pkg.py": "", "c.py": "# only a comment\n"})
|
||||
self.assertEqual(self.touched({"m.py": text.replace("def b", "def new():\n\treturn 9\n\n\ndef b"), "m.md": "# A\ntext\n\n## B\ntext\n\n## End\nmore\n", "pkg.py": "def f():\n\treturn 1\n", "c.py": "# only a comment\n\n\ndef g():\n\treturn 1\n"}), {
|
||||
"c.py": (Part("g"),),
|
||||
"m.md": (Part("## End"),),
|
||||
"m.py": (Part("new"),),
|
||||
"pkg.py": (Part("f"),),
|
||||
})
|
||||
|
||||
def test_a_deleted_function_does_not_name_the_next_one(self) -> None:
|
||||
text = "def a():\n\treturn 1\n\n\ndef b():\n\treturn 2\n\n\ndef c():\n\treturn 3\n"
|
||||
self.base = self.repo.commit({"m.py": text})
|
||||
self.assertEqual(self.touched({"m.py": text.replace("def b():\n\treturn 2\n\n\n", "")}), {"m.py": (Part("b"),)})
|
||||
|
||||
def test_a_change_of_blank_lines_alone_names_the_part_they_go_with(self) -> None:
|
||||
self.assertEqual(self.touched({"a.py": PYTHON.replace("\n\nclass Plan", "\n\n\nclass Plan"), "a.md": MARKDOWN.replace("Text.\n", "Text.\n\n")}), {"a.md": (Part("# Title"),), "a.py": (Part("Plan"),)})
|
||||
|
||||
def test_reads_text_that_is_not_utf_8(self) -> None:
|
||||
self.repo.commit({"n.md": b"# T\ncaf\xe9\n"})
|
||||
self.base = self.repo.run("rev-parse", "HEAD")
|
||||
@@ -379,6 +460,13 @@ class RecordCommandTest(unittest.TestCase):
|
||||
self.assertEqual(text.count("## Chunk 3, "), 1)
|
||||
self.assertNotIn("touch-predictions.md", text)
|
||||
|
||||
def test_names_a_chunk_by_its_ids_in_order_each_once(self) -> None:
|
||||
path = self.set_record()
|
||||
self.record("record", "3", "4")
|
||||
ran = self.record("record", "4", "3", "4")
|
||||
self.assertEqual(ran.stdout, f"Recorded what chunk 3, 4 was predicted to touch, and what it touched, in {path}.\n")
|
||||
self.assertEqual(re.findall(r"^## Chunk ([\d, ]+), \d{4}", path.read_text(encoding="utf-8"), re.M), ["3, 4"])
|
||||
|
||||
def test_records_nothing_where_the_config_leaves_the_setting_out(self) -> None:
|
||||
ran = self.record("record", "3")
|
||||
self.assertEqual((ran.returncode, ran.stdout), (0, "The project's config sets no `touch-predictions`, so nothing is recorded.\n"))
|
||||
|
||||
Reference in New Issue
Block a user