Merge lp:~jamestait/u1-test-utils/pep8-report-summary into lp:u1-test-utils

Proposed by James Tait
Status: Merged
Approved by: James Tait
Approved revision: 98
Merged at revision: 98
Proposed branch: lp:~jamestait/u1-test-utils/pep8-report-summary
Merge into: lp:u1-test-utils
Diff against target: 42 lines (+21/-1)
1 file modified
u1testutils/static/test_pep8_conformance.py (+21/-1)
To merge this branch: bzr merge lp:~jamestait/u1-test-utils/pep8-report-summary
Reviewer Review Type Date Requested Status
Leo Arias (community) code review Approve
Review via email: mp+192692@code.launchpad.net

Commit message

Summarise code format errors in the failure message.

Description of the change

Add a UnitTestReport that collates PEP8 format warnings and reports them
in the failure message, for easy readability at the end of the test run,
rather than having to scroll back through all the test output.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

Thank you! Looks good.

review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'u1testutils/static/test_pep8_conformance.py'
2--- u1testutils/static/test_pep8_conformance.py 2013-08-08 16:32:44 +0000
3+++ u1testutils/static/test_pep8_conformance.py 2013-10-25 12:41:07 +0000
4@@ -20,6 +20,24 @@
5 from collections import defaultdict
6
7
8+class UnitTestReport(pep8.BaseReport):
9+ def __init__(self, options):
10+ super(UnitTestReport, self).__init__(options)
11+ self._fmt = pep8.REPORT_FORMAT.get(options.format.lower(),
12+ options.format)
13+ self._msgs = []
14+
15+ def error(self, line_number, offset, text, check):
16+ """Report an error, according to options."""
17+ super(UnitTestReport, self).error(line_number, offset,
18+ text, check)
19+ self._msgs.append(self._fmt % {
20+ 'path': self.filename,
21+ 'row': self.line_offset + line_number, 'col': offset + 1,
22+ 'code': text[:4], 'text': text[5:],
23+ })
24+
25+
26 class Pep8ConformanceTestCase(unittest.TestCase):
27
28 packages = []
29@@ -43,10 +61,12 @@
30 testsuite='',
31 verbose=0
32 )
33+ self.report = self.pep8style.init_report(UnitTestReport)
34
35 def test_pep8_conformance(self):
36 self.assertNotEqual([], self.packages,
37 'You should define some packages to check')
38 for package in self.packages:
39 self.pep8style.input_dir(os.path.dirname(package.__file__))
40- self.assertEqual(self.pep8style.options.report.total_errors, 0)
41+ self.assertEqual(self.pep8style.options.report.total_errors, 0,
42+ '\n'.join(self.report._msgs))

Subscribers

People subscribed via source and target branches

to all changes: