From 423fa596325acb8f6bcb37a3502cf7853e5d395a Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 8 Feb 2023 07:11:45 -0700 Subject: feat: simplify purges_files Also, move tests to test_data.py, and finish covering the code. --- tests/test_data.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/test_data.py') diff --git a/tests/test_data.py b/tests/test_data.py index 5953ba36..1cc64572 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -588,6 +588,35 @@ class CoverageDataTest(CoverageTest): assert_lines1_data(covdata) assert not exceptions + def test_purge_files_lines(self) -> None: + covdata = DebugCoverageData() + covdata.add_lines(LINES_1) + covdata.add_lines(LINES_2) + assert_line_counts(covdata, SUMMARY_1_2) + covdata.purge_files(["a.py", "b.py"]) + assert_line_counts(covdata, {"a.py": 0, "b.py": 0, "c.py": 1}) + covdata.purge_files(["c.py"]) + assert_line_counts(covdata, {"a.py": 0, "b.py": 0, "c.py": 0}) + # It's OK to "purge" a file that wasn't measured. + covdata.purge_files(["xyz.py"]) + assert_line_counts(covdata, {"a.py": 0, "b.py": 0, "c.py": 0}) + + def test_purge_files_arcs(self) -> None: + covdata = CoverageData() + covdata.add_arcs(ARCS_3) + covdata.add_arcs(ARCS_4) + assert_line_counts(covdata, SUMMARY_3_4) + covdata.purge_files(["x.py", "y.py"]) + assert_line_counts(covdata, {"x.py": 0, "y.py": 0, "z.py": 1}) + covdata.purge_files(["z.py"]) + assert_line_counts(covdata, {"x.py": 0, "y.py": 0, "z.py": 0}) + + def test_cant_purge_in_empty_data(self) -> None: + covdata = DebugCoverageData() + msg = "Can't purge files in an empty CoverageData" + with pytest.raises(DataError, match=msg): + covdata.purge_files(["abc.py"]) + class CoverageDataInTempDirTest(CoverageTest): """Tests of CoverageData that need a temporary directory to make files.""" -- cgit v1.2.1