summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-08-10 16:39:22 -0400
committerNed Batchelder <ned@nedbatchelder.com>2018-08-10 16:39:22 -0400
commit8562aeb29eddf3349f5c363c1842f9822b18a450 (patch)
tree7f4c0f16843c4f9b78cc49c4f6d0354a0d8a0f91 /coverage
parent90bb6a77e02cbac6a23723b5907d5f59d1db1b82 (diff)
downloadpython-coveragepy-git-8562aeb29eddf3349f5c363c1842f9822b18a450.tar.gz
Move line_counts out of the data classes
Diffstat (limited to 'coverage')
-rw-r--r--coverage/cmdline.py3
-rw-r--r--coverage/data.py39
2 files changed, 22 insertions, 20 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 14948d1c..23d2aec3 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -14,6 +14,7 @@ import traceback
from coverage import env
from coverage.collector import CTracer
+from coverage.data import line_counts
from coverage.debug import info_formatter, info_header
from coverage.execfile import run_python_file, run_python_module
from coverage.misc import BaseCoverageException, ExceptionDuringRun, NoSource
@@ -660,7 +661,7 @@ class CoverageScript(object):
print("path: %s" % self.coverage.get_data().filename)
if data:
print("has_arcs: %r" % data.has_arcs())
- summary = data.line_counts(fullpath=True)
+ summary = line_counts(data, fullpath=True)
filenames = sorted(summary.keys())
print("\n%d files:" % len(filenames))
for f in filenames:
diff --git a/coverage/data.py b/coverage/data.py
index 9c82ccef..44b75439 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -244,25 +244,6 @@ class CoverageJsonData(object):
"""A list of all files that had been measured."""
return list(self._arcs or self._lines or {})
- def line_counts(self, fullpath=False):
- """Return a dict summarizing the line coverage data.
-
- Keys are based on the file names, and values are the number of executed
- lines. If `fullpath` is true, then the keys are the full pathnames of
- the files, otherwise they are the basenames of the files.
-
- Returns a dict mapping file names to counts of lines.
-
- """
- summ = {}
- if fullpath:
- filename_fn = lambda f: f
- else:
- filename_fn = os.path.basename
- for filename in self.measured_files():
- summ[filename_fn(filename)] = len(self.lines(filename))
- return summ
-
def __nonzero__(self):
return bool(self._lines or self._arcs)
@@ -662,6 +643,26 @@ elif which == "sql":
CoverageData = CoverageSqliteData
+def line_counts(data, fullpath=False):
+ """Return a dict summarizing the line coverage data.
+
+ Keys are based on the file names, and values are the number of executed
+ lines. If `fullpath` is true, then the keys are the full pathnames of
+ the files, otherwise they are the basenames of the files.
+
+ Returns a dict mapping file names to counts of lines.
+
+ """
+ summ = {}
+ if fullpath:
+ filename_fn = lambda f: f
+ else:
+ filename_fn = os.path.basename
+ for filename in data.measured_files():
+ summ[filename_fn(filename)] = len(data.lines(filename))
+ return summ
+
+
def add_data_to_hash(data, filename, hasher):
"""Contribute `filename`'s data to the `hasher`.