summaryrefslogtreecommitdiff
path: root/coverage/summary.py
diff options
context:
space:
mode:
authorDan Wandschneider <daniel.wandschneider@schrodinger.com>2016-06-08 19:51:55 -0400
committerDan Wandschneider <daniel.wandschneider@schrodinger.com>2016-06-08 19:51:55 -0400
commita488a33ac1cb1d8443681814ee8c5d167e129e0d (patch)
tree313e7ec8d4e6606eb8ae54e40113d54eb5ce4f4e /coverage/summary.py
parent0c39e2f5774b78ca5025e8ffe0fbde4ab2e86abf (diff)
downloadpython-coveragepy-git-a488a33ac1cb1d8443681814ee8c5d167e129e0d.tar.gz
Issue 199: Sort text report.
Allows sorting of the text report based on: Name, Stmts, Miss, Cover Tested on Mac with Python 2.7.11 and Python 3.5 Help message for the new option is: python -m coverage report -h ... --sort=SORT Sort report by a column. Valid values are: Name, Stmts, Miss, Cover. ...
Diffstat (limited to 'coverage/summary.py')
-rw-r--r--coverage/summary.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/coverage/summary.py b/coverage/summary.py
index 81844b55..c5b393d7 100644
--- a/coverage/summary.py
+++ b/coverage/summary.py
@@ -62,6 +62,7 @@ class SummaryReporter(Reporter):
total = Numbers()
skipped_count = 0
+ lines = []
for fr in file_reporters:
try:
@@ -90,7 +91,10 @@ class SummaryReporter(Reporter):
missing_fmtd += ", "
missing_fmtd += branches_fmtd
args += (missing_fmtd,)
- writeout(fmt_coverage % args)
+ text = fmt_coverage % args
+ # Add numeric percent coverage so that sorting makes sense
+ args += (nums.pc_covered,)
+ lines.append((text, args))
except Exception:
report_it = not self.config.ignore_errors
if report_it:
@@ -100,7 +104,19 @@ class SummaryReporter(Reporter):
if typ is NotPython and not fr.should_be_python():
report_it = False
if report_it:
- writeout(fmt_err % (fr.relative_filename(), typ.__name__, msg))
+ args = (fr.relative_filename(), typ.__name__, msg)
+ lines.append((fmt_err % args, (fr.relative_filename(), 0, 0, 0, 0)))
+
+ if getattr(self.config, 'sort', None):
+ column_order = dict(Name=0,
+ Stmts=1,
+ Miss=2,
+ Cover=-1,
+ Missing=4)
+ position = column_order.get(self.config.sort)
+ lines.sort(key=lambda l: (l[1][position], l[0]))
+ for line in lines:
+ writeout(line[0])
if total.n_files > 1:
writeout(rule)