summaryrefslogtreecommitdiff
path: root/tests/test_data.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2023-02-08 07:11:45 -0700
committerNed Batchelder <ned@nedbatchelder.com>2023-02-08 13:16:05 -0700
commit423fa596325acb8f6bcb37a3502cf7853e5d395a (patch)
treec8429927f19470c342b2f6440562c2083ddd54fd /tests/test_data.py
parentcb7d67962ca8ed9eb176e144b9cfe96373803bf4 (diff)
downloadpython-coveragepy-git-423fa596325acb8f6bcb37a3502cf7853e5d395a.tar.gz
feat: simplify purges_files
Also, move tests to test_data.py, and finish covering the code.
Diffstat (limited to 'tests/test_data.py')
-rw-r--r--tests/test_data.py29
1 files changed, 29 insertions, 0 deletions
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."""