Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2f9f0dd

Browse filesBrowse files
committed
Updated coding standards test to raise an exception containing the PEP8 failiures.
1 parent 4daa8ca commit 2f9f0dd
Copy full SHA for 2f9f0dd

File tree

Expand file treeCollapse file tree

1 file changed

+29
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-11
lines changed

‎lib/matplotlib/tests/test_coding_standards.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_coding_standards.py
+29-11Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
except ImportError:
1111
HAS_PEP8 = False
1212
else:
13-
HAS_PEP8 = True
13+
HAS_PEP8 = pep8.__version__ > '1.4.5'
1414

1515
import matplotlib
1616

@@ -141,15 +141,18 @@ class StandardReportWithExclusions(pep8.StandardReport):
141141
'*/matplotlib/projections/__init__.py',
142142
'*/matplotlib/projections/geo.py',
143143
'*/matplotlib/projections/polar.py']
144-
144+
145+
#: A class attribute to store the lines of failing tests.
146+
_global_deferred_print = []
147+
145148
#: A class attribute to store patterns which have seen exceptions.
146149
matched_exclusions = set()
147-
150+
148151
def get_file_results(self):
149152
# If the file had no errors, return self.file_errors (which will be 0)
150153
if not self._deferred_print:
151154
return self.file_errors
152-
155+
153156
# Iterate over all of the patterns, to find a possible exclusion. If we
154157
# the filename is to be excluded, go ahead and remove the counts that
155158
# self.error added.
@@ -165,13 +168,22 @@ def get_file_results(self):
165168
self.file_errors -= 1
166169
self.total_errors -= 1
167170
return self.file_errors
168-
169-
# Otherwise call the superclass' method to print the bad results.
170-
return super(StandardReportWithExclusions,
171-
self).get_file_results()
171+
172+
# mirror the content of StandardReport, only storing the output to
173+
# file rather than printing. This could be a feature request for
174+
# the PEP8 tool.
175+
self._deferred_print.sort()
176+
for line_number, offset, code, text, doc in self._deferred_print:
177+
self._global_deferred_print.append(
178+
self._fmt % {
179+
'path': self.filename,
180+
'row': self.line_offset + line_number, 'col': offset + 1,
181+
'code': code, 'text': text,
182+
})
183+
return self.file_errors
172184

173185

174-
def _test_pep8_conformance():
186+
def test_pep8_conformance():
175187
# Tests the matplotlib codebase against the "pep8" tool.
176188
#
177189
# Users can add their own excluded files (should files exist in the
@@ -192,6 +204,7 @@ def _test_pep8_conformance():
192204
# "reporter=pep8.FileReport" to the StyleGuide constructor.
193205
pep8style = pep8.StyleGuide(quiet=False,
194206
reporter=StandardReportWithExclusions)
207+
reporter = pep8style.options.reporter
195208

196209
# Extend the number of PEP8 guidelines which are not checked.
197210
pep8style.options.ignore = pep8style.options.ignore + ('E121', 'E122',
@@ -225,10 +238,15 @@ def _test_pep8_conformance():
225238
pep8style.options.exclude.extend(extra_exclude)
226239

227240
result = pep8style.check_files([os.path.dirname(matplotlib.__file__)])
228-
assert_equal(result.total_errors, 0, "Found code syntax "
241+
if reporter is StandardReportWithExclusions:
242+
assert_equal(result.total_errors, 0,
243+
("Found code syntax errors (and warnings):\n"
244+
"{0}".format(
245+
'\n'.join(reporter._global_deferred_print))))
246+
else:
247+
assert_equal(result.total_errors, 0, "Found code syntax "
229248
"errors (and warnings).")
230249

231-
reporter = pep8style.options.reporter
232250
# If we've been using the exclusions reporter, check that we didn't
233251
# exclude files unnecessarily.
234252
if reporter is StandardReportWithExclusions:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.