14
14
except ImportError :
15
15
HAS_PEP8 = False
16
16
else :
17
- HAS_PEP8 = True
17
+ HAS_PEP8 = pep8 . __version__ > '1.4.5'
18
18
19
19
import matplotlib
20
20
@@ -127,17 +127,21 @@ class StandardReportWithExclusions(pep8.StandardReport):
127
127
'*/matplotlib/projections/geo.py' ,
128
128
'*/matplotlib/projections/polar.py' ]
129
129
130
+ #: A class attribute to store the lines of failing tests.
131
+ _global_deferred_print = []
132
+
130
133
#: A class attribute to store patterns which have seen exceptions.
131
134
matched_exclusions = set ()
132
135
133
136
def get_file_results (self ):
134
- # If the file had no errors, return self.file_errors (which will be 0)
137
+ # If the file had no errors, return self.file_errors
138
+ # (which will be 0).
135
139
if not self ._deferred_print :
136
140
return self .file_errors
137
141
138
- # Iterate over all of the patterns, to find a possible exclusion. If we
139
- # the filename is to be excluded, go ahead and remove the counts that
140
- # self.error added.
142
+ # Iterate over all of the patterns, to find a possible exclusion.
143
+ # If the filename is to be excluded, go ahead and remove the
144
+ # counts that self.error added.
141
145
for pattern in self .expected_bad_files :
142
146
if fnmatch (self .filename , pattern ):
143
147
self .matched_exclusions .add (pattern )
@@ -151,12 +155,20 @@ def get_file_results(self):
151
155
self .total_errors -= 1
152
156
return self .file_errors
153
157
154
- # Otherwise call the superclass' method to print the bad results.
155
- return super (StandardReportWithExclusions ,
156
- self ).get_file_results ()
158
+ # mirror the content of StandardReport, only storing the output to
159
+ # file rather than printing. This could be a feature request for
160
+ # the PEP8 tool.
161
+ self ._deferred_print .sort ()
162
+ for line_number , offset , code , text , _ in self ._deferred_print :
163
+ self ._global_deferred_print .append (
164
+ self ._fmt % {'path' : self .filename ,
165
+ 'row' : self .line_offset + line_number ,
166
+ 'col' : offset + 1 , 'code' : code ,
167
+ 'text' : text })
168
+ return self .file_errors
157
169
158
170
159
- def _test_pep8_conformance ():
171
+ def test_pep8_conformance ():
160
172
# Tests the matplotlib codebase against the "pep8" tool.
161
173
#
162
174
# Users can add their own excluded files (should files exist in the
@@ -172,11 +184,12 @@ def _test_pep8_conformance():
172
184
# "reporter=pep8.FileReport" to the StyleGuide constructor.
173
185
pep8style = pep8 .StyleGuide (quiet = False ,
174
186
reporter = StandardReportWithExclusions )
187
+ reporter = pep8style .options .reporter
175
188
176
189
# Extend the number of PEP8 guidelines which are not checked.
177
- pep8style .options .ignore = pep8style .options .ignore + ( 'E121' , 'E122' ,
178
- 'E123 ' , 'E124 ' , 'E125 ' , 'E126 ' , 'E127 ' ,
179
- 'E128' )
190
+ pep8style .options .ignore = ( pep8style .options .ignore +
191
+ ( 'E121 ' , 'E122 ' , 'E123 ' , 'E124 ' , 'E125 ' ,
192
+ 'E126' , 'E127' , 'E128' ) )
180
193
181
194
# Support for egg shared object wrappers, which are not PEP8 compliant,
182
195
# nor part of the matplotlib repository.
@@ -205,10 +218,15 @@ def _test_pep8_conformance():
205
218
pep8style .options .exclude .extend (extra_exclude )
206
219
207
220
result = pep8style .check_files ([os .path .dirname (matplotlib .__file__ )])
208
- assert_equal (result .total_errors , 0 , "Found code syntax "
221
+ if reporter is StandardReportWithExclusions :
222
+ assert_equal (result .total_errors , 0 ,
223
+ ("Found code syntax errors (and warnings):\n "
224
+ "{0}" .format (
225
+ '\n ' .join (reporter ._global_deferred_print ))))
226
+ else :
227
+ assert_equal (result .total_errors , 0 , "Found code syntax "
209
228
"errors (and warnings)." )
210
229
211
- reporter = pep8style .options .reporter
212
230
# If we've been using the exclusions reporter, check that we didn't
213
231
# exclude files unnecessarily.
214
232
if reporter is StandardReportWithExclusions :
0 commit comments