summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/control.py2
-rw-r--r--coverage/data.py37
-rw-r--r--tests/test_arcs.py2
-rw-r--r--tests/test_data.py3
-rw-r--r--tests/test_oddball.py20
5 files changed, 32 insertions, 32 deletions
diff --git a/coverage/control.py b/coverage/control.py
index 40976014..412f7aec 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -860,7 +860,7 @@ class Coverage(object):
if isinstance(morf, string_class):
abs_morf = abs_file(morf)
- plugin_name = self.data.plugin_data().get(abs_morf)
+ plugin_name = self.data.plugin_name(abs_morf)
if plugin_name:
plugin = self.plugins.get(plugin_name)
diff --git a/coverage/data.py b/coverage/data.py
index 197dbd34..b42dc8d4 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -38,7 +38,7 @@ class CoverageData(object):
`debug` is a `DebugControl` object for writing debug messages.
"""
- self.collector = collector or 'unknown'
+ self.collector = collector
self.debug = debug
# A map from canonical Python source file name to a dictionary in
@@ -76,21 +76,22 @@ class CoverageData(object):
self.arcs = {}
self.plugins = {}
- def line_data(self):
- """Return the map from filenames to lists of line numbers executed."""
- return dict(
- (f, sorted(lmap.keys())) for f, lmap in iitems(self.lines)
- )
+ def line_data(self, filename):
+ """Get the list of lines executed for a file."""
+ return list(self.lines.get(filename, {}).keys())
- def arc_data(self):
- """Return the map from filenames to lists of line number pairs."""
- return dict(
- (f, sorted(amap.keys())) for f, amap in iitems(self.arcs)
- )
+ def plugin_name(self, filename):
+ """Get the plugin name for a file.
- def plugin_data(self):
- """Return the map from filenames to plugin names."""
- return self.plugins
+ Arguments:
+ filename: the name of the file you're interested in.
+
+ Returns:
+ str: the name of the plugin that handles this file. Can be None
+ if no plugin was involved.
+
+ """
+ return self.plugins.get(filename)
def read(self, file_obj):
"""Return the stored coverage data from the given file.
@@ -133,10 +134,10 @@ class CoverageData(object):
# Create the file data.
file_data = {}
- file_data['lines'] = self.line_data()
- arcs = self.arc_data()
- if arcs:
- file_data['arcs'] = arcs
+ file_data['lines'] = dict((f, list(lmap.keys())) for f, lmap in iitems(self.lines))
+
+ if self.arcs:
+ file_data['arcs'] = dict((f, list(amap.keys())) for f, amap in iitems(self.arcs))
if self.collector:
file_data['collector'] = self.collector
diff --git a/tests/test_arcs.py b/tests/test_arcs.py
index 63120616..c84c5441 100644
--- a/tests/test_arcs.py
+++ b/tests/test_arcs.py
@@ -761,5 +761,5 @@ class LineDataTest(CoverageTest):
self.start_import_stop(cov, "fun1")
data = cov.get_data()
- fun1_lines = data.line_data()[abs_file("fun1.py")]
+ fun1_lines = data.line_data(abs_file("fun1.py"))
self.assertEqual(fun1_lines, [1, 2, 5])
diff --git a/tests/test_data.py b/tests/test_data.py
index c89bbea7..ff4d0c0a 100644
--- a/tests/test_data.py
+++ b/tests/test_data.py
@@ -107,10 +107,11 @@ class DataTest(DataTestHelpers, CoverageTest):
covdata1 = CoverageData()
covdata1.add_line_data(DATA_1)
covdatafiles.write(covdata1)
+
covdata1.erase()
self.assert_summary(covdata1, {})
- covdatafiles.erase()
+ covdatafiles.erase()
covdata2 = CoverageData()
covdatafiles.read(covdata2)
self.assert_summary(covdata2, {})
diff --git a/tests/test_oddball.py b/tests/test_oddball.py
index 268624f7..5288f022 100644
--- a/tests/test_oddball.py
+++ b/tests/test_oddball.py
@@ -1,9 +1,9 @@
"""Oddball cases for testing coverage.py"""
-import os
import sys
import coverage
+from coverage.files import abs_file
from tests.coveragetest import CoverageTest
from tests import osinfo
@@ -307,7 +307,8 @@ class ExceptionTest(CoverageTest):
for callnames, lines_expected in runs:
# Make the list of functions we'll call for this test.
- calls = [getattr(sys.modules[cn], cn) for cn in callnames.split()]
+ callnames = callnames.split()
+ calls = [getattr(sys.modules[cn], cn) for cn in callnames]
cov = coverage.coverage()
cov.start()
@@ -318,16 +319,13 @@ class ExceptionTest(CoverageTest):
# Clean the line data and compare to expected results.
# The filenames are absolute, so keep just the base.
- data = cov.get_data()
- lines = data.line_data()
clean_lines = {}
- for f, llist in lines.items():
- # f is a path to a Python module, so we drop the '.py' to get
- # a callname.
- basename = os.path.basename(f)
- assert basename.endswith(".py")
- if basename[:-3] in callnames:
- clean_lines[basename] = llist
+ data = cov.get_data()
+ for callname in callnames:
+ filename = callname + ".py"
+ lines = data.line_data(abs_file(filename))
+ clean_lines[filename] = sorted(lines)
+
self.assertEqual(clean_lines, lines_expected)