summaryrefslogtreecommitdiff
path: root/tests/test_data.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2023-01-23 19:44:41 -0500
committerNed Batchelder <ned@nedbatchelder.com>2023-01-24 19:23:48 -0500
commit4cc32922685c6971275f522304b3754ad1a233c1 (patch)
tree59ab9a76180a22a20fbd34b5d2188191daee4c0b /tests/test_data.py
parent674204fc958f30815fe482fe1ed36d01eb74c489 (diff)
downloadpython-coveragepy-git-4cc32922685c6971275f522304b3754ad1a233c1.tar.gz
perf: avoid needless sql operations. #1538
If the set of arcs is empty, skip the SQL operations. We also need to allow setting a file tracer for an unmeasured file, to avoid the Cython problem whose fix caused the performance issue in the first place. TBH, I don't know why we had to prevent file tracers on unmeasured files. Perhaps pytest-cov has changed to avoid the behavior that caused problems.
Diffstat (limited to 'tests/test_data.py')
-rw-r--r--tests/test_data.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/tests/test_data.py b/tests/test_data.py
index ab4e03f7..5953ba36 100644
--- a/tests/test_data.py
+++ b/tests/test_data.py
@@ -187,6 +187,14 @@ class CoverageDataTest(CoverageTest):
assert_line_counts(covdata, SUMMARY_3_4)
assert_measured_files(covdata, MEASURED_FILES_3_4)
+ def test_ok_to_add_empty_arcs(self) -> None:
+ covdata = DebugCoverageData()
+ covdata.add_arcs(ARCS_3)
+ covdata.add_arcs(ARCS_4)
+ covdata.add_arcs(dict.fromkeys(ARCS_3, set()))
+ assert_line_counts(covdata, SUMMARY_3_4)
+ assert_measured_files(covdata, MEASURED_FILES_3_4)
+
@pytest.mark.parametrize("klass", [CoverageData, DebugCoverageData])
def test_cant_add_arcs_with_lines(self, klass: TCoverageData) -> None:
covdata = klass()
@@ -350,16 +358,6 @@ class CoverageDataTest(CoverageTest):
assert covdata.file_tracer("p1.foo") == "p1.plugin"
assert covdata.file_tracer("main.py") == ""
- def test_cant_file_tracer_unmeasured_files(self) -> None:
- covdata = DebugCoverageData()
- msg = "Can't add file tracer data for unmeasured file 'p1.foo'"
- with pytest.raises(DataError, match=msg):
- covdata.add_file_tracers({"p1.foo": "p1.plugin"})
-
- covdata.add_lines({"p2.html": [10, 11, 12]})
- with pytest.raises(DataError, match=msg):
- covdata.add_file_tracers({"p1.foo": "p1.plugin"})
-
def test_cant_change_file_tracer_name(self) -> None:
covdata = DebugCoverageData()
covdata.add_lines({"p1.foo": [1, 2, 3]})