Skip to content

Commit 045a420

Browse files
added descending sort option in coverage report
1 parent 13159a9 commit 045a420

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

coverage/summary.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,21 @@ def report(self, morfs, outfile=None):
104104

105105
# Sort the lines and write them out.
106106
if getattr(self.config, 'sort', None):
107-
position = column_order.get(self.config.sort.lower())
107+
_sort = self.config.sort.lower()
108+
if _sort[0] == '-':
109+
reverse = True
110+
sort_option = _sort[1:]
111+
elif _sort[0] == '+':
112+
reverse = False
113+
sort_option = _sort[1:]
114+
else:
115+
reverse = False
116+
sort_option = _sort
117+
118+
position = column_order.get(sort_option)
108119
if position is None:
109120
raise CoverageException("Invalid sorting option: {!r}".format(self.config.sort))
110-
lines.sort(key=lambda l: (l[1][position], l[0]))
121+
lines.sort(key=lambda l: (l[1][position], l[0]), reverse=reverse)
111122

112123
for line in lines:
113124
self.writeout(line[0])

0 commit comments

Comments
 (0)