From 2f9f0dd809e2dfadf851ba1e4d1f89745afa31f0 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Fri, 31 May 2013 09:00:03 +0100 Subject: [PATCH 1/2] Updated coding standards test to raise an exception containing the PEP8 failiures. --- lib/matplotlib/tests/test_coding_standards.py | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/tests/test_coding_standards.py b/lib/matplotlib/tests/test_coding_standards.py index 0b0fb976f623..84c84f5626c3 100644 --- a/lib/matplotlib/tests/test_coding_standards.py +++ b/lib/matplotlib/tests/test_coding_standards.py @@ -10,7 +10,7 @@ except ImportError: HAS_PEP8 = False else: - HAS_PEP8 = True + HAS_PEP8 = pep8.__version__ > '1.4.5' import matplotlib @@ -141,15 +141,18 @@ class StandardReportWithExclusions(pep8.StandardReport): '*/matplotlib/projections/__init__.py', '*/matplotlib/projections/geo.py', '*/matplotlib/projections/polar.py'] - + + #: A class attribute to store the lines of failing tests. + _global_deferred_print = [] + #: A class attribute to store patterns which have seen exceptions. matched_exclusions = set() - + def get_file_results(self): # If the file had no errors, return self.file_errors (which will be 0) if not self._deferred_print: return self.file_errors - + # Iterate over all of the patterns, to find a possible exclusion. If we # the filename is to be excluded, go ahead and remove the counts that # self.error added. @@ -165,13 +168,22 @@ def get_file_results(self): self.file_errors -= 1 self.total_errors -= 1 return self.file_errors - - # Otherwise call the superclass' method to print the bad results. - return super(StandardReportWithExclusions, - self).get_file_results() + + # mirror the content of StandardReport, only storing the output to + # file rather than printing. This could be a feature request for + # the PEP8 tool. + self._deferred_print.sort() + for line_number, offset, code, text, doc in self._deferred_print: + self._global_deferred_print.append( + self._fmt % { + 'path': self.filename, + 'row': self.line_offset + line_number, 'col': offset + 1, + 'code': code, 'text': text, + }) + return self.file_errors -def _test_pep8_conformance(): +def test_pep8_conformance(): # Tests the matplotlib codebase against the "pep8" tool. # # Users can add their own excluded files (should files exist in the @@ -192,6 +204,7 @@ def _test_pep8_conformance(): # "reporter=pep8.FileReport" to the StyleGuide constructor. pep8style = pep8.StyleGuide(quiet=False, reporter=StandardReportWithExclusions) + reporter = pep8style.options.reporter # Extend the number of PEP8 guidelines which are not checked. pep8style.options.ignore = pep8style.options.ignore + ('E121', 'E122', @@ -225,10 +238,15 @@ def _test_pep8_conformance(): pep8style.options.exclude.extend(extra_exclude) result = pep8style.check_files([os.path.dirname(matplotlib.__file__)]) - assert_equal(result.total_errors, 0, "Found code syntax " + if reporter is StandardReportWithExclusions: + assert_equal(result.total_errors, 0, + ("Found code syntax errors (and warnings):\n" + "{0}".format( + '\n'.join(reporter._global_deferred_print)))) + else: + assert_equal(result.total_errors, 0, "Found code syntax " "errors (and warnings).") - reporter = pep8style.options.reporter # If we've been using the exclusions reporter, check that we didn't # exclude files unnecessarily. if reporter is StandardReportWithExclusions: From babd28a838410a066edbb2964f84956a461e869b Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Thu, 19 Sep 2013 08:26:18 +0100 Subject: [PATCH 2/2] Fixed failing PEP8 tests. --- lib/matplotlib/tests/test_coding_standards.py | 36 +++++++++---------- lib/matplotlib/tests/test_table.py | 5 ++- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/matplotlib/tests/test_coding_standards.py b/lib/matplotlib/tests/test_coding_standards.py index 84c84f5626c3..9d8883ef3d10 100644 --- a/lib/matplotlib/tests/test_coding_standards.py +++ b/lib/matplotlib/tests/test_coding_standards.py @@ -141,21 +141,22 @@ class StandardReportWithExclusions(pep8.StandardReport): '*/matplotlib/projections/__init__.py', '*/matplotlib/projections/geo.py', '*/matplotlib/projections/polar.py'] - + #: A class attribute to store the lines of failing tests. _global_deferred_print = [] - + #: A class attribute to store patterns which have seen exceptions. matched_exclusions = set() - + def get_file_results(self): - # If the file had no errors, return self.file_errors (which will be 0) + # If the file had no errors, return self.file_errors + # (which will be 0). if not self._deferred_print: return self.file_errors - - # Iterate over all of the patterns, to find a possible exclusion. If we - # the filename is to be excluded, go ahead and remove the counts that - # self.error added. + + # Iterate over all of the patterns, to find a possible exclusion. + # If the filename is to be excluded, go ahead and remove the + # counts that self.error added. for pattern in self.expected_bad_files: if fnmatch(self.filename, pattern): self.matched_exclusions.add(pattern) @@ -168,18 +169,17 @@ def get_file_results(self): self.file_errors -= 1 self.total_errors -= 1 return self.file_errors - + # mirror the content of StandardReport, only storing the output to # file rather than printing. This could be a feature request for # the PEP8 tool. self._deferred_print.sort() - for line_number, offset, code, text, doc in self._deferred_print: + for line_number, offset, code, text, _ in self._deferred_print: self._global_deferred_print.append( - self._fmt % { - 'path': self.filename, - 'row': self.line_offset + line_number, 'col': offset + 1, - 'code': code, 'text': text, - }) + self._fmt % {'path': self.filename, + 'row': self.line_offset + line_number, + 'col': offset + 1, 'code': code, + 'text': text}) return self.file_errors @@ -207,9 +207,9 @@ def test_pep8_conformance(): reporter = pep8style.options.reporter # Extend the number of PEP8 guidelines which are not checked. - pep8style.options.ignore = pep8style.options.ignore + ('E121', 'E122', - 'E123', 'E124', 'E125', 'E126', 'E127', - 'E128') + pep8style.options.ignore = (pep8style.options.ignore + + ('E121', 'E122', 'E123', 'E124', 'E125', + 'E126', 'E127', 'E128')) # Support for egg shared object wrappers, which are not PEP8 compliant, # nor part of the matplotlib repository. diff --git a/lib/matplotlib/tests/test_table.py b/lib/matplotlib/tests/test_table.py index 6c173e8087ef..18add08fb183 100644 --- a/lib/matplotlib/tests/test_table.py +++ b/lib/matplotlib/tests/test_table.py @@ -7,13 +7,12 @@ extensions=['png'], remove_text=True) def test_zorder(): - data = [[ 66386, 174296,], - [ 58230, 381139,]] + data = [[66386, 174296], + [58230, 381139]] colLabels = ('Freeze', 'Wind') rowLabels = ['%d year' % x for x in (100, 50)] - cellText = [] yoff = np.array([0.0] * len(colLabels)) for row in reversed(data):