8000 Merge pull request #2099 from pelson/re-enable_pep8_test · matplotlib/matplotlib@42165c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 42165c8

Browse files
committed
Merge pull request #2099 from pelson/re-enable_pep8_test
Updated coding standards test to raise an exception containing the PEP8 failiures.
2 parents 3e61c81 + babd28a commit 42165c8

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

lib/matplotlib/tests/test_coding_standards.py

Lines changed: 32 additions & 14 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

@@ -142,17 +142,21 @@ class StandardReportWithExclusions(pep8.StandardReport):
142142
'*/matplotlib/projections/geo.py',
143143
'*/matplotlib/projections/polar.py']
144144

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()
147150

148151
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).
150154
if not self._deferred_print:
151155
return self.file_errors
152156

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.
156160
for pattern in self.expected_bad_files:
157161
if fnmatch(self.filename, pattern):
158162
self.matched_exclusions.add(pattern)
@@ -166,12 +170,20 @@ def get_file_results(self):
166170
self.total_errors -= 1
167171
return self.file_errors
168172

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
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,11 +204,12 @@ 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.
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'))
200213

201214
# Support for egg shared object wrappers, which are not PEP8 compliant,
202215
# nor part of the matplotlib repository.
@@ -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:

lib/matplotlib/tests/test_table.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
extensions=['png'],
88
remove_text=True)
99
def test_zorder():
10-
data = [[ 66386, 174296,],
11-
[ 58230, 381139,]]
10+
data = [[66386, 174296],
11+
[58230, 381139]]
1212

1313
colLabels = ('Freeze', 'Wind')
1414
rowLabels = ['%d year' % x for x in (100, 50)]
1515

16-
1716
cellText = []
1817
yoff = np.array([0.0] * len(colLabels))
1918
for row in reversed(data):

0 commit comments

Comments
 (0)
0