From 50535ae9b23ce336fcc84e11c3546ab75c1e55b8 Mon Sep 17 00:00:00 2001 From: Dan Wandschneider Date: Wed, 8 Jun 2016 19:51:55 -0400 Subject: 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. ... --- coverage/summary.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'coverage/summary.py') 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) -- cgit v1.2.1