diff --git a/pycodestyle.py b/pycodestyle.py index cad68eaf..92124910 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -2134,7 +2134,7 @@ def __init__(self, options): self.elapsed = 0 self.total_errors = 0 self.counters = dict.fromkeys(self._benchmark_keys, 0) - self.messages = {} + self.messages = [] def start(self): """Start the timer.""" @@ -2167,7 +2167,7 @@ def error(self, line_number, offset, text, check): self.counters[code] += 1 else: self.counters[code] = 1 - self.messages[code] = text[5:] + self.messages.append((line_number, offset, code, text[5:])) # Don't care about expected errors or warnings if code in self.expected: return @@ -2183,8 +2183,7 @@ def get_file_results(self): def get_count(self, prefix=''): """Return the total count of errors and warnings.""" - return sum(self.counters[key] - for key in self.messages if key.startswith(prefix)) + return len(self.messages) def get_statistics(self, prefix=''): """Get statistics for message codes that start with the prefix. @@ -2194,8 +2193,8 @@ def get_statistics(self, prefix=''): prefix='W' matches all warnings prefix='E4' matches all errors that have to do with imports """ - return ['%-7s %s %s' % (self.counters[key], key, self.messages[key]) - for key in sorted(self.messages) if key.startswith(prefix)] + return ['%-7s %s %s' % (self.counters[key[2]], key[2], key[3]) + for key in sorted(self.messages) if key[2].startswith(prefix)] def print_statistics(self, prefix=''): """Print overall statistics (number of errors and warnings).""" diff --git a/testsuite/test_all.py b/testsuite/test_all.py index 0e4bc7d1..109766c2 100644 --- a/testsuite/test_all.py +++ b/testsuite/test_all.py @@ -43,7 +43,7 @@ def test_own_dog_food(self): os.path.join(ROOT_DIR, 'setup.py')] report = self._style.init_report(pycodestyle.StandardReport) report = self._style.check_files(files) - self.assertEqual(list(report.messages.keys()), ['W504'], + self.assertEqual(report.messages[0][2], 'W504', msg='Failures: %s' % report.messages)