10
10
except ImportError :
11
11
HAS_PEP8 = False
12
12
else :
13
- HAS_PEP8 = True
13
+ HAS_PEP8 = pep8 . __version__ > '1.4.5'
14
14
15
15
import matplotlib
16
16
@@ -141,15 +141,18 @@ class StandardReportWithExclusions(pep8.StandardReport):
141
141
'*/matplotlib/projections/__init__.py' ,
142
142
'*/matplotlib/projections/geo.py' ,
143
143
'*/matplotlib/projections/polar.py' ]
144
-
144
+
145
+ #: A class attribute to store the lines of failing tests.
146
+ _global_deferred_print = []
147
+
145
148
#: A class attribute to store patterns which have seen exceptions.
146
149
matched_exclusions = set ()
147
-
150
+
148
151
def get_file_results (self ):
149
152
# If the file had no errors, return self.file_errors (which will be 0)
150
153
if not self ._deferred_print :
151
154
return self .file_errors
152
-
155
+
153
156
# Iterate over all of the patterns, to find a possible exclusion. If we
154
157
# the filename is to be excluded, go ahead and remove the counts that
155
158
# self.error added.
@@ -165,13 +168,22 @@ def get_file_results(self):
165
168
self .file_errors -= 1
166
169
self .total_errors -= 1
167
170
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
172
184
173
185
174
- def _test_pep8_conformance ():
186
+ def test_pep8_conformance ():
175
187
# Tests the matplotlib codebase against the "pep8" tool.
176
188
#
177
189
# Users can add their own excluded files (should files exist in the
@@ -192,6 +204,7 @@ def _test_pep8_conformance():
192
204
# "reporter=pep8.FileReport" to the StyleGuide constructor.
193
205
pep8style = pep8 .StyleGuide (quiet = False ,
194
206
reporter = StandardReportWithExclusions )
207
+ reporter = pep8style .options .reporter
195
208
196
209
# Extend the number of PEP8 guidelines which are not checked.
197
210
pep8style .options .ignore = pep8style .options .ignore + ('E121' , 'E122' ,
@@ -225,10 +238,15 @@ def _test_pep8_conformance():
225
238
pep8style .options .exclude .extend (extra_exclude )
226
239
227
240
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 "
229
248
"errors (and warnings)." )
230
249
231
- reporter = pep8style .options .reporter
232
250
# If we've been using the exclusions reporter, check that we didn't
233
251
# exclude files unnecessarily.
234
252
if reporter is StandardReportWithExclusions :
0 commit comments