summaryrefslogtreecommitdiff
path: root/coverage/sqldata.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-09-15 08:07:26 -0400
committerNed Batchelder <ned@nedbatchelder.com>2018-09-21 17:56:49 -0400
commitd2f77ab2ffc308e616af0207546ee1bef1cb8c75 (patch)
tree1cfa74a6998eb7bbc08ce28594b5f80dff457d65 /coverage/sqldata.py
parent2f1b8cfcfe184a8fd6f3f2f789530bddb233dda8 (diff)
downloadpython-coveragepy-git-d2f77ab2ffc308e616af0207546ee1bef1cb8c75.tar.gz
measured_contexts() and two simple tests of the global context
Diffstat (limited to 'coverage/sqldata.py')
-rw-r--r--coverage/sqldata.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/coverage/sqldata.py b/coverage/sqldata.py
index b9488557..45c1570c 100644
--- a/coverage/sqldata.py
+++ b/coverage/sqldata.py
@@ -179,18 +179,16 @@ class CoverageSqliteData(SimpleRepr):
return self._file_map.get(filename)
def set_context(self, context):
- """Get the context id for `context`."""
+ """Set the current context for future `add_lines` etc."""
self._start_using()
- if not context:
- self._context_id = 0
- else:
- with self._connect() as con:
- row = con.execute("select id from context where context = ?", (context,)).fetchone()
- if row is not None:
- self._context_id = row[0]
- else:
- cur = con.execute("insert into context (context) values (?)", (context,))
- self._context_id = cur.lastrowid
+ context = context or ""
+ with self._connect() as con:
+ row = con.execute("select id from context where context = ?", (context,)).fetchone()
+ if row is not None:
+ self._context_id = row[0]
+ else:
+ cur = con.execute("insert into context (context) values (?)", (context,))
+ self._context_id = cur.lastrowid
def add_lines(self, line_data):
"""Add measured line data.
@@ -384,6 +382,13 @@ class CoverageSqliteData(SimpleRepr):
"""A set of all files that had been measured."""
return set(self._file_map)
+ def measured_contexts(self):
+ """A set of all contexts that have been measured."""
+ self._start_using()
+ with self._connect() as con:
+ contexts = set(row[0] for row in con.execute("select distinct(context) from context"))
+ return contexts
+
def file_tracer(self, filename):
"""Get the plugin name of the file tracer for a file.