From 230219b50f515b93adc9fc5c3aee5cc256876b0d Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 3 Jul 2009 22:04:50 -0400 Subject: I meant for the list of lines to be sorted. --- coverage/data.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'coverage/data.py') diff --git a/coverage/data.py b/coverage/data.py index e913a9f0..a616f536 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -3,6 +3,17 @@ import os import cPickle as pickle +# Python 2.3 compatibility: it doesn't have `sorted`. +try: + sorted +except NameError: + def sorted(iterable): # pylint: disable-msg=W0622 + """A 2.3-compatible implementation of `sorted`.""" + lst = list(iterable) + lst.sort() + return lst + + class CoverageData: """Manages collected coverage data, including file storage. @@ -10,7 +21,8 @@ class CoverageData: * collector: a string identifying the collecting software - * lines: a dict mapping filenames to lists of line numbers executed: + * lines: a dict mapping filenames to sorted lists of line numbers + executed: { 'file1': [17,23,45], 'file2': [1,2,3], ... } """ @@ -90,7 +102,7 @@ class CoverageData: def line_data(self): """Return the map from filenames to lists of line numbers executed.""" return dict( - [(f, list(linemap.keys())) for f, linemap in self.lines.items()] + [(f, sorted(linemap.keys())) for f, linemap in self.lines.items()] ) def write_file(self, filename): -- cgit v1.2.1