diff options
author | Dan Wandschneider <daniel.wandschneider@schrodinger.com> | 2016-06-08 19:51:55 -0400 |
---|---|---|
committer | Dan Wandschneider <daniel.wandschneider@schrodinger.com> | 2016-06-08 19:51:55 -0400 |
commit | 50535ae9b23ce336fcc84e11c3546ab75c1e55b8 (patch) | |
tree | 277c4f865b72001ce1553e5802fc96cb1df378b6 /coverage/summary.py | |
parent | c1a4b7cc8fc250a76b92afa2630d11c7d5275705 (diff) | |
download | python-coveragepy-50535ae9b23ce336fcc84e11c3546ab75c1e55b8.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.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/coverage/summary.py b/coverage/summary.py index 81844b5..c5b393d 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) |