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
@@ -142,17 +142,21 @@ class StandardReportWithExclusions(pep8.StandardReport):
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
- # If the file had no errors, return self.file_errors (which will be 0)
152
+ # If the file had no errors, return self.file_errors
153
+ # (which will be 0).
150
154
if not self ._deferred_print :
151
155
return self .file_errors
152
156
153
- # Iterate over all of the patterns, to find a possible exclusion. If we
154
- # the filename is to be excluded, go ahead and remove the counts that
155
- # self.error added.
157
+ # Iterate over all of the patterns, to find a possible exclusion.
158
+ # If the filename is to be excluded, go ahead and remove the
159
+ # counts that self.error added.
156
160
for pattern in self .expected_bad_files :
157
161
if fnmatch (self .filename , pattern ):
158
162
self .matched_exclusions .add (pattern )
@@ -166,12 +170,20 @@ def get_file_results(self):
166
170
self .total_errors -= 1
167
171
return self .file_errors
168
172
169
- # Otherwise call the superclass' method to print the bad results.
170
- return super (StandardReportWithExclusions ,
171
- self ).get_file_results ()
173
+ # mirror the content of StandardReport, only storing the output to
174
+ # file rather than printing. This could be a feature request for
175
+ # the PEP8 tool.
176
+ self ._deferred_print .sort ()
177
+ for line_number , offset , code , text , _ in self ._deferred_print :
178
+ self ._global_deferred_print .append (
179
+ self ._fmt % {'path' : self .filename ,
180
+ 'row' : self .line_offset + line_number ,
181
+ 'col' : offset + 1 , 'code' : code ,
182
+ 'text' : text })
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,11 +204,12 @@ 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
- pep8style .options .ignore = pep8style .options .ignore + ( 'E121' , 'E122' ,
198
- 'E123 ' , 'E124 ' , 'E125 ' , 'E126 ' , 'E127 ' ,
199
- 'E128' )
210
+ pep8style .options .ignore = ( pep8style .options .ignore +
211
+ ( 'E121 ' , 'E122 ' , 'E123 ' , 'E124 ' , 'E125 ' ,
212
+ 'E126' , 'E127' , 'E128' ) )
200
213
201
214
# Support for egg shared object wrappers, which are not PEP8 compliant,
202
215
# nor part of the matplotlib repository.
@@ -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