summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Richter <stephan.richter@gmail.com>2019-01-27 16:34:59 -0500
committerNed Batchelder <ned@nedbatchelder.com>2019-02-17 18:07:24 -0500
commit3e4188695fc0f5934933889b1707c17299936ac8 (patch)
tree001f9454c06b21b8b9d7801603c2d9a7561142d7
parentf12db7fd4b3ab288f7f770f7138062951feaa6c9 (diff)
downloadpython-coveragepy-git-3e4188695fc0f5934933889b1707c17299936ac8.tar.gz
Make sure that arcs() and lines() only returns distinct line combination values and not one entry for each context.
-rw-r--r--coverage/sqldata.py4
-rw-r--r--tests/test_data.py16
2 files changed, 18 insertions, 2 deletions
diff --git a/coverage/sqldata.py b/coverage/sqldata.py
index 91ad3cd5..8bfb04be 100644
--- a/coverage/sqldata.py
+++ b/coverage/sqldata.py
@@ -468,7 +468,7 @@ class CoverageSqliteData(SimpleReprMixin):
if file_id is None:
return None
else:
- query = "select lineno from line where file_id = ?"
+ query = "select distinct lineno from line where file_id = ?"
data = [file_id]
if context is not None:
query += " and context_id = ?"
@@ -483,7 +483,7 @@ class CoverageSqliteData(SimpleReprMixin):
if file_id is None:
return None
else:
- query = "select fromno, tono from arc where file_id = ?"
+ query = "select distinct fromno, tono from arc where file_id = ?"
data = [file_id]
if context is not None:
query += " and context_id = ?"
diff --git a/tests/test_data.py b/tests/test_data.py
index bda73810..3f96288f 100644
--- a/tests/test_data.py
+++ b/tests/test_data.py
@@ -199,6 +199,22 @@ class CoverageDataTest(DataTestHelpers, CoverageTest):
covdata.add_run_info(count=17)
self.assertEqual(covdata.run_infos(), [{"hello": "there", "count": 17}])
+ def test_no_duplicate_lines(self):
+ covdata = CoverageData()
+ covdata.set_context("context1")
+ covdata.add_lines(LINES_1)
+ covdata.set_context("context2")
+ covdata.add_lines(LINES_1)
+ self.assertEqual(covdata.lines('a.py'), A_PY_LINES_1)
+
+ def test_no_duplicate_arcs(self):
+ covdata = CoverageData()
+ covdata.set_context("context1")
+ covdata.add_arcs(ARCS_3)
+ covdata.set_context("context2")
+ covdata.add_arcs(ARCS_3)
+ self.assertEqual(covdata.arcs('x.py'), X_PY_ARCS_3)
+
def test_no_arcs_vs_unmeasured_file(self):
covdata = CoverageData()
covdata.add_arcs(ARCS_3)