Merge lp:~adiroiban/pocket-lint/pocket-lint-764627 into lp:pocket-lint

Proposed by Curtis Hovey
Status: Merged
Approved by: Curtis Hovey
Approved revision: 379
Merged at revision: 377
Proposed branch: lp:~adiroiban/pocket-lint/pocket-lint-764627
Merge into: lp:pocket-lint
Diff against target: 95 lines (+35/-4)
2 files modified
pocketlint/formatcheck.py (+17/-4)
pocketlint/tests/test_python.py (+18/-0)
To merge this branch: bzr merge lp:~adiroiban/pocket-lint/pocket-lint-764627
Reviewer Review Type Date Requested Status
Curtis Hovey code Approve
Review via email: mp+58174@code.launchpad.net

Description of the change

Subclass PyFlakesChecker to supress irrelevant errors.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

I was initial -1 on handling this issue in pocket-lint, but I see your implementation provides a lot of opportunities for future development. Your PocketLintPyFlakesChecker subclass could accept a Reporter instance either in __init__ or check to remove the integration hack that is visible in the diff. I am not +1 about this change.

I want to merge your branch, but before I do, can you help me understand the test change? I expect to see an explicit test that will raise WindowsError or cause it to be raised. The change I see looks like it it updating an existing test, but it is not clear which test is checking for this. I also do not understand how the added try/except tests that the subclass suppresses the error

review: Needs Information (code)
377. By Adi Roiban

Fix pep8 and pyflakes overlaping.

Revision history for this message
Adi Roiban (adiroiban) wrote :

The updated 'good_python' text is raising the WindowsError in the default pyflakes.

If run the tests on Linux using the updated test with the current formatchecker.py code you will see that the tests are failing.

Do you want me to test that WindowsError is raised when using the default pyflakes checker and the it is ignored when using the modified pyflackes checker?

There was an error in the initial code this is why PocketLintPyFlakesChecker was also added to the pep8 check.
If you look at the check_pep8 you will see that pep8.Checker.report_error is monkey patched, but then pyflakes Checker.report_error is restored.

I have updated the code to reflect this error.

I have imported the pyflackes Checker as PyFlakesChecker since using the generic Checker name can be confusing and it could lead to errors like the one discovered now.

I am not sure what I understood your request.

We can also talk via FreeNode IRC . my nickname is adiroiban

Cheers,

Revision history for this message
Curtis Hovey (sinzui) wrote :

Firstly, good_python is intended to be good code that does not cause any errors. Hacking it to not do that implies it is not good python. The good_python should not be used to test a rare case.

I expect to see a new test that only exercises the lines of code that changed. I think you want to create a separate example to test called bad_windowserrror_python and add a new test to TestPyflakes that verifies everything is okay.

review: Needs Fixing (code)
378. By Adi Roiban

Add a separate test for WindowsError.

379. By Adi Roiban

Fix the test.

Revision history for this message
Adi Roiban (adiroiban) wrote :

Hi,

Thanks for the review and Sorry for the delay. I added a different test for pyflakes.

Hope it is ok now . Feel feel add any comments :)

Adi

Revision history for this message
Curtis Hovey (sinzui) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pocketlint/formatcheck.py'
2--- pocketlint/formatcheck.py 2011-04-18 02:04:09 +0000
3+++ pocketlint/formatcheck.py 2011-04-19 16:34:52 +0000
4@@ -32,7 +32,7 @@
5
6 import contrib.pep8 as pep8
7 from contrib.cssccc import CSSCodingConventionChecker
8-from contrib.pyflakes.checker import Checker
9+from contrib.pyflakes.checker import Checker as PyFlakesChecker
10 try:
11 import cssutils
12 HAS_CSSUTILS = True
13@@ -54,6 +54,19 @@
14 ]
15
16
17+class PocketLintPyFlakesChecker(PyFlakesChecker):
18+ '''PocketLint checker for pyflakes.
19+
20+ This is here to work around some of the pyflakes problems.
21+ '''
22+
23+ def NAME(self, node):
24+ '''Locate name. Ignore WindowsErrors.'''
25+ if node.name == 'WindowsError':
26+ return
27+ return super(PocketLintPyFlakesChecker, self).NAME(node)
28+
29+
30 class Reporter:
31 """Common rules for checkers."""
32 CONSOLE = object()
33@@ -345,7 +358,7 @@
34 error_lineno = 0
35 else:
36 error_message, location = str(error).rsplit(':')
37- error_lineno = int(location.split(',')[0].split()[1])- offset
38+ error_lineno = int(location.split(',')[0].split()[1]) - offset
39 self.message(error_lineno, error_message, icon='error')
40 self.check_text()
41
42@@ -459,7 +472,7 @@
43 message = '%s: %s' % (explanation, line.strip())
44 self.message(line_no, message, icon='error')
45 else:
46- warnings = Checker(tree)
47+ warnings = PocketLintPyFlakesChecker(tree)
48 for warning in warnings.messages:
49 dummy, line_no, message = str(warning).split(':')
50 self.message(int(line_no), message.strip(), icon='error')
51@@ -481,7 +494,7 @@
52 message, location = er.args
53 self.message(location[0], message, icon='error')
54 finally:
55- Checker.report_error = original_report_error
56+ pep8.Checker.report_error = original_report_error
57
58 def check_text(self):
59 """Call each line_method for each line in text."""
60
61=== modified file 'pocketlint/tests/test_python.py'
62--- pocketlint/tests/test_python.py 2011-04-17 16:32:41 +0000
63+++ pocketlint/tests/test_python.py 2011-04-19 16:34:52 +0000
64@@ -15,6 +15,16 @@
65 print "Good night."
66 """
67
68+good_python_on_windows = """\
69+class example:
70+
71+ def __init__(self, value):
72+ try:
73+ open("some.file")
74+ except WindowsError:
75+ pass
76+"""
77+
78 bad_syntax_python = """\
79 class Test():
80 def __init__(self, default='', non_default):
81@@ -77,6 +87,14 @@
82 self.assertEqual([], self.reporter.messages)
83 self.assertEqual(0, self.reporter.call_count)
84
85+ def test_windows_code_without_issues(self):
86+ self.reporter.call_count = 0
87+ checker = PythonChecker(
88+ 'bogus', good_python_on_windows, self.reporter)
89+ checker.check_flakes()
90+ self.assertEqual([], self.reporter.messages)
91+ self.assertEqual(0, self.reporter.call_count)
92+
93 def test_code_with_SyntaxError(self):
94 self.reporter.call_count = 0
95 checker = PythonChecker(

Subscribers

People subscribed via source and target branches

to all changes: