Test the cases whose mutants survived: ranges, renames, non-UTF-8 text, reading on past a skipped or whole file
This commit is contained in:
@@ -641,6 +641,10 @@ class BesideTest(unittest.TestCase):
|
||||
todo = TODO.replace("| 9 | 0.3.0", self.ROWS + "| 9 | 0.3.0") + self.DETAILS
|
||||
self.assertEqual(self.said(todo), ["- The items of release 0.2.0 that may start chunks beside item 3's, since none is predicted to touch a part that item 3 or an item named before it touches: 4. An item this chunk takes starts none. Not beside it: item 6, which overlaps item 3 at `src/app.py` `run`."])
|
||||
|
||||
def test_names_each_item_that_may_and_stops_there_when_none_is_refused(self):
|
||||
todo = TODO.replace("| 9 | 0.3.0", self.ROWS + "| 9 | 0.3.0") + self.DETAILS.removesuffix("`run`\n") + "`other`\n"
|
||||
self.assertEqual(self.said(todo), ["- The items of release 0.2.0 that may start chunks beside item 3's, since none is predicted to touch a part that item 3 or an item named before it touches: 4, 6. An item this chunk takes starts none."])
|
||||
|
||||
def test_says_when_none_may(self):
|
||||
todo = TODO.replace("| 9 | 0.3.0", self.ROWS + "| 9 | 0.3.0") + self.DETAILS.replace("`stop`", "`run`")
|
||||
self.assertEqual(self.said(todo), ["- No item of release 0.2.0 may start a chunk beside item 3's. Not beside it: item 4, which overlaps item 3 at `src/app.py` `run`; item 6, which overlaps item 3 at `src/app.py` `run`."])
|
||||
|
||||
@@ -91,6 +91,12 @@ class PredictedTest(unittest.TestCase):
|
||||
|
||||
def test_an_empty_list_is_a_failure(self) -> None:
|
||||
self.assertIsInstance(predicted("Touches:\n\nProse.\n"), Failure)
|
||||
found = predicted("Touches:\n")
|
||||
assert isinstance(found, Failure)
|
||||
self.assertEqual(found.reason, "no bullet follows `Touches:`")
|
||||
|
||||
def test_reads_a_list_right_under_its_label_a_one_line_range_and_a_name_of_any_letters(self) -> None:
|
||||
self.assertEqual(predicted("Touches:\n- `a.py`: `Xray`, lines 5-5\n"), {"a.py": (Part("Xray"), Part("lines 5-5"))})
|
||||
|
||||
def test_rendered_reads_back(self) -> None:
|
||||
touches = predicted(DETAIL)
|
||||
@@ -101,6 +107,10 @@ class PredictedTest(unittest.TestCase):
|
||||
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": ()})
|
||||
|
||||
def test_together_keeps_a_part_not_small_once_one_says_so_and_reads_on_past_a_whole_file(self) -> None:
|
||||
joined = together([{"a.py": (Part("f"),), "b.md": ()}, {"b.md": (Part("# T"),), "a.py": (Part("f", small=True),), "c.py": (Part("h"),)}])
|
||||
self.assertEqual(joined, {"a.py": (Part("f"),), "b.md": (), "c.py": (Part("h"),)})
|
||||
|
||||
|
||||
class OverlapsTest(unittest.TestCase):
|
||||
def test_other_files_and_other_parts_do_not_overlap(self) -> None:
|
||||
@@ -115,12 +125,19 @@ class OverlapsTest(unittest.TestCase):
|
||||
def test_a_whole_file_overlaps_any_part_of_it(self) -> None:
|
||||
self.assertEqual(overlaps({"a.py": ()}, {"a.py": (Part("g", small=True),)}), ["`a.py`"])
|
||||
|
||||
def test_reads_on_past_a_file_only_one_touches_and_past_a_whole_file(self) -> None:
|
||||
theirs = {"a.py": (), "b.py": (Part("g"),)}
|
||||
self.assertEqual(overlaps({"z.py": (Part("f"),), "a.py": (), "b.py": (Part("g"),)}, theirs), ["`a.py`", "`b.py` `g`"])
|
||||
|
||||
def test_line_ranges_overlap_where_they_share_a_line(self) -> None:
|
||||
self.assertEqual(overlaps({"x.sh": (Part("lines 1-10"),)}, {"x.sh": (Part("lines 10-12"),)}), ["`x.sh` lines 1-10"])
|
||||
self.assertEqual(overlaps({"x.sh": (Part("lines 1-9"),)}, {"x.sh": (Part("lines 10-12"),)}), [])
|
||||
self.assertEqual(overlaps({"x.sh": (Part("lines 10-12"),)}, {"x.sh": (Part("lines 1-10"),)}), ["`x.sh` lines 10-12"])
|
||||
self.assertEqual(overlaps({"x.sh": (Part("lines 11-12"),)}, {"x.sh": (Part("lines 1-10"),)}), [])
|
||||
|
||||
def test_a_line_range_overlaps_a_named_part_since_nothing_tells_them_apart(self) -> None:
|
||||
self.assertEqual(overlaps({"a.py": (Part("lines 1-9"),)}, {"a.py": (Part("f"),)}), ["`a.py` lines 1-9"])
|
||||
self.assertEqual(overlaps({"a.py": (Part("f"),)}, {"a.py": (Part("lines 1-9"),)}), ["`a.py` `f`"])
|
||||
|
||||
def test_a_small_change_on_either_side_is_taken(self) -> None:
|
||||
self.assertEqual(overlaps({"a.py": (Part("f", small=True),)}, {"a.py": (Part("f"),)}), [])
|
||||
@@ -148,6 +165,16 @@ class FilePartsTest(unittest.TestCase):
|
||||
def test_python_that_does_not_parse_has_no_names(self) -> None:
|
||||
self.assertIsNone(self.names("a.py", "def (:\n", 1))
|
||||
|
||||
def test_python_names_a_function_under_another_statement_and_an_annotated_assignment(self) -> None:
|
||||
text = "if True:\n\tdef f():\n\t\treturn 1\n\nclass C:\n\tif True:\n\t\tdef m(self):\n\t\t\treturn 2\n\nX: int = 1\n"
|
||||
self.assertEqual(self.names("a.py", text, 3, 8, 10), {"f", "C.m", "X"})
|
||||
|
||||
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"})
|
||||
|
||||
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"})
|
||||
|
||||
def test_markdown_names_the_heading_above_and_skips_fenced_lines(self) -> None:
|
||||
self.assertEqual(self.names("a.md", MARKDOWN, 1), {"(top)"})
|
||||
self.assertEqual(self.names("a.md", MARKDOWN, 3, 5, 8), {"# Title"})
|
||||
@@ -186,6 +213,14 @@ class ChunksBesideTest(unittest.TestCase):
|
||||
def test_no_item_starts_beside_one_that_predicts_nothing(self) -> None:
|
||||
items = plan((1, "0.2.0", "", ""), (2, "0.2.0", "", "- `b.py`"))
|
||||
self.assertEqual(chunks_beside(items, items[0]), "item 1's detail has no `Touches:` list")
|
||||
items = plan((1, "0.2.0", "", "- a.py"), (2, "0.2.0", "", "- `b.py`"))
|
||||
found = chunks_beside(items, items[0])
|
||||
assert isinstance(found, str)
|
||||
self.assertTrue(found.startswith("item 1's `Touches:` list cannot be read: the bullet '- a.py'"), found)
|
||||
|
||||
def test_names_each_place_an_item_overlaps(self) -> None:
|
||||
items = plan((1, "0.2.0", "", "- `a.py`: `f`, `g`"), (2, "0.2.0", "", "- `a.py`: `f`, `g`"))
|
||||
self.assertEqual(chunks_beside(items, items[0]), Beside([], ["item 2, which overlaps item 1 at `a.py` `f`, `a.py` `g`"]))
|
||||
|
||||
def test_says_nothing_where_no_item_predicts(self) -> None:
|
||||
items = plan((1, "0.2.0", "", ""), (2, "0.2.0", "", ""), (3, "0.3.0", "", "- `c.py`"))
|
||||
@@ -251,6 +286,28 @@ class TouchedTest(unittest.TestCase):
|
||||
def test_skipped_paths_do_not_count(self) -> None:
|
||||
self.assertEqual(self.touched({"todo.md": "plan\nmore\n", "gone.py": "x = 2\n"}, "todo.md"), {"gone.py": (Part("x"),)})
|
||||
|
||||
def test_reads_on_past_a_skipped_path(self) -> None:
|
||||
self.assertEqual(self.touched({"a.md": "# New\n", "gone.py": "x = 3\n"}, "a.md"), {"gone.py": (Part("x"),)})
|
||||
|
||||
def test_a_renamed_file_is_one_deleted_and_one_added(self) -> None:
|
||||
self.repo.run("mv", "a.py", "b.py")
|
||||
self.assertEqual(self.touched({}), {"a.py": (), "b.py": ()})
|
||||
|
||||
def test_lists_the_paths_in_order_whatever_happened_to_each(self) -> None:
|
||||
found = self.touched({"z.py": "y = 2\n", "gone.py": "x = 2\n"})
|
||||
assert isinstance(found, dict)
|
||||
self.assertEqual(list(found), ["gone.py", "z.py"])
|
||||
|
||||
def test_reads_the_diff_up_to_head_and_no_later(self) -> None:
|
||||
head = self.repo.commit({"gone.py": "x = 2\n"})
|
||||
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_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")
|
||||
self.assertEqual(self.touched({"n.md": b"# T\ncaf\xe9s\n"}), {"n.md": (Part("# T"),)})
|
||||
|
||||
def test_an_unknown_base_is_a_failure(self) -> None:
|
||||
self.assertIsInstance(diff_parts.touched("nope", "HEAD", self.repo.folder, set()), Failure)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user