Merge lp:~adiroiban/pocket-lint/pep-in-memory into lp:pocket-lint

Proposed by Adi Roiban
Status: Needs review
Proposed branch: lp:~adiroiban/pocket-lint/pep-in-memory
Merge into: lp:pocket-lint
Diff against target: 235 lines (+39/-43)
3 files modified
pocketlint/formatcheck.py (+16/-3)
pocketlint/tests/test_python.py (+19/-37)
pocketlint/tests/test_text.py (+4/-3)
To merge this branch: bzr merge lp:~adiroiban/pocket-lint/pep-in-memory
Reviewer Review Type Date Requested Status
Curtis Hovey Pending
Review via email: mp+215549@code.launchpad.net

Description of the change

Description
----------

To allow in memory check of pep8 code , pocket-lint should pass already parsed lines to pep8 instead of only passing the filepath so that a file is only read once.

Changes
-------

I have updated check_pep8

I have updated tests to use the new PocketLintOptions object and stop using the mocked Bunch object.

I have updated the max_line_lenght update in PocketLintOption to keep in sync the pep8 option.

I have updated style so that pocket-lint code will pass pocket-lint checks.

Maybe we should update test.py to also run pocket-lint on the pocket-lint source code? What do you think? I can do that in separate branch. This can also be usefull for travis-ci integration.

Please let me know what do you think.

To post a comment you must log in.

Unmerged revisions

453. By Adi Roiban <email address hidden>

Initial code to fix pep8 in memory check.

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 2014-03-09 21:04:28 +0000
3+++ pocketlint/formatcheck.py 2014-04-12 16:02:11 +0000
4@@ -265,8 +265,8 @@
5 """Default options used by pocketlint"""
6
7 def __init__(self, command_options=None):
8- self.max_line_length = 0
9-
10+ self._max_line_length = 0
11+ self.regex_line = []
12 self.jslint = {
13 'enabled': True,
14 }
15@@ -290,6 +290,15 @@
16 if command_options:
17 self._updateFromCommandLineOptions(command_options)
18
19+ @property
20+ def max_line_length(self):
21+ return self._max_line_length
22+
23+ @max_line_length.setter
24+ def max_line_length(self, value):
25+ self._max_line_length = value
26+ self.pep8['max_line_length'] = value - 1
27+
28 def _updateFromCommandLineOptions(self, options):
29 """
30 Update with options received from command line.
31@@ -734,7 +743,11 @@
32 pep8_report = PEP8Report(options, self.message)
33 try:
34 pep8_checker = pep8.Checker(
35- self.file_path, options=options, report=pep8_report)
36+ filename=self.file_path,
37+ lines=self.text.splitlines(True),
38+ options=options,
39+ report=pep8_report,
40+ )
41 pep8_checker.check_all()
42 except TokenError as er:
43 message, location = er.args
44
45=== modified file 'pocketlint/tests/test_python.py'
46--- pocketlint/tests/test_python.py 2014-03-09 21:00:26 +0000
47+++ pocketlint/tests/test_python.py 2014-04-12 16:02:11 +0000
48@@ -5,17 +5,16 @@
49 absolute_import,
50 print_function,
51 unicode_literals,
52-)
53+ )
54
55 import unittest
56 from tempfile import NamedTemporaryFile
57
58 from pocketlint.formatcheck import (
59- get_option_parser,
60 # Imported via pocketlint to avoid duplication of conditional import.
61 pep257,
62- PythonChecker,
63-)
64+ PocketLintOptions, PythonChecker,
65+ )
66 from pocketlint.tests import CheckerTestCase
67 from pocketlint.tests.test_text import TestAnyTextMixin
68
69@@ -171,7 +170,7 @@
70 source = (
71 '# -*- coding: utf-8 -*-\n'
72 'variable = u"r\xe9sum\xe9"'
73- )
74+ )
75 checker = PythonChecker('bogus', source, self.reporter)
76 # This should set the correct encoding.
77 checker.check_text()
78@@ -183,33 +182,23 @@
79 class TestPEP8(CheckerTestCase):
80 """Verify PEP8 integration."""
81
82- def setUp(self):
83- super(TestPEP8, self).setUp()
84- self.file = NamedTemporaryFile(prefix='pocketlint_')
85-
86- def tearDown(self):
87- self.file.close()
88-
89 def test_code_without_issues(self):
90- self.write_to_file(self.file, good_python)
91 checker = PythonChecker(
92- self.file.name, good_python, self.reporter)
93+ 'file/path', good_python, self.reporter)
94 checker.check_pep8()
95 self.assertEqual([], self.reporter.messages)
96
97 def test_bad_syntax(self):
98- self.write_to_file(self.file, bad_syntax2_python)
99 checker = PythonChecker(
100- self.file.name, ugly_style_python, self.reporter)
101+ 'file/path', ugly_style_python, self.reporter)
102 checker.check_pep8()
103 self.assertEqual(
104- [(4, 'E901 TokenError: EOF in multi-line statement')],
105+ [(4, 'E222 multiple spaces after operator')],
106 self.reporter.messages)
107
108 def test_code_with_IndentationError(self):
109- self.write_to_file(self.file, bad_indentation_python)
110 checker = PythonChecker(
111- self.file.name, bad_indentation_python, self.reporter)
112+ 'file/path', bad_indentation_python, self.reporter)
113 checker.check_pep8()
114 expected = [(
115 4,
116@@ -219,9 +208,8 @@
117 checker.check_pep8()
118
119 def test_code_closing_bracket(self):
120- self.write_to_file(self.file, hanging_style_python)
121 checker = PythonChecker(
122- self.file.name, hanging_style_python, self.reporter)
123+ 'file/path', hanging_style_python, self.reporter)
124 checker.options.pep8['hang_closing'] = True
125 checker.check_pep8()
126 self.assertEqual([], self.reporter.messages)
127@@ -233,32 +221,28 @@
128 self.reporter.messages)
129
130 def test_code_with_issues(self):
131- self.write_to_file(self.file, ugly_style_python)
132 checker = PythonChecker(
133- self.file.name, ugly_style_python, self.reporter)
134+ 'file/path', ugly_style_python, self.reporter)
135 checker.check_pep8()
136 self.assertEqual(
137 [(4, 'E222 multiple spaces after operator')],
138 self.reporter.messages)
139
140 def test_code_with_comments(self):
141- self.write_to_file(self.file, ugly_style_lines_python)
142 checker = PythonChecker(
143- self.file.name, ugly_style_lines_python, self.reporter)
144+ 'file/path', ugly_style_lines_python, self.reporter)
145 checker.check_pep8()
146 self.assertEqual([], self.reporter.messages)
147
148 def test_long_length_good(self):
149 long_line = '1234 56189' * 7 + '12345678' + '\n'
150- self.write_to_file(self.file, long_line)
151- checker = PythonChecker(self.file.name, long_line, self.reporter)
152+ checker = PythonChecker('file/path', long_line, self.reporter)
153 checker.check_pep8()
154 self.assertEqual([], self.reporter.messages)
155
156 def test_long_length_bad(self):
157 long_line = '1234 56189' * 8 + '\n'
158- self.write_to_file(self.file, long_line)
159- checker = PythonChecker(self.file.name, long_line, self.reporter)
160+ checker = PythonChecker('file/path', long_line, self.reporter)
161 checker.check_pep8()
162 self.assertEqual(
163 [(1, 'E501 line too long (80 > 79 characters)')],
164@@ -266,11 +250,10 @@
165
166 def test_long_length_options(self):
167 long_line = '1234 56189' * 7 + '\n'
168- parser = get_option_parser()
169- (options, sources) = parser.parse_args(['-m', '60'])
170- self.write_to_file(self.file, long_line)
171+ options = PocketLintOptions()
172+ options.max_line_length = 60
173 checker = PythonChecker(
174- self.file.name, long_line, self.reporter, options)
175+ 'file/path', long_line, self.reporter, options)
176 checker.check_pep8()
177 self.assertEqual(
178 [(1, 'E501 line too long (70 > 59 characters)')],
179@@ -322,8 +305,7 @@
180 def test_pep8_options(self):
181 """It can set PEP8 options."""
182 long_line = '1234 56189' * 7 + '\n'
183- self.write_to_file(self.file, long_line)
184- checker = PythonChecker(self.file.name, long_line, self.reporter)
185+ checker = PythonChecker('file/path', long_line, self.reporter)
186 checker.options.pep8['ignore'] = ['E501']
187 checker.options.pep8['max_line_length'] = 60
188 checker.check_pep8()
189@@ -346,7 +328,7 @@
190 [(1, 'All modules should have docstrings.'),
191 (3, 'First line should end with a period.'), ],
192 self.reporter.messages,
193- )
194+ )
195
196 def test_code_with_ignore(self):
197 """A list with error message which should be ignored can be
198@@ -364,7 +346,7 @@
199 self.assertEqual(
200 [(1, 'All modules should have docstrings.'), ],
201 self.reporter.messages,
202- )
203+ )
204
205
206 class TestText(CheckerTestCase, TestAnyTextMixin):
207
208=== modified file 'pocketlint/tests/test_text.py'
209--- pocketlint/tests/test_text.py 2014-03-09 21:00:26 +0000
210+++ pocketlint/tests/test_text.py 2014-04-12 16:02:11 +0000
211@@ -5,12 +5,12 @@
212 absolute_import,
213 print_function,
214 unicode_literals,
215-)
216+ )
217
218 from pocketlint.formatcheck import (
219 AnyTextChecker,
220 get_option_parser,
221-)
222+ )
223 from pocketlint.tests import Bunch, CheckerTestCase
224
225
226@@ -71,7 +71,8 @@
227 regex_line=[
228 ('.*marker.*', 'Explanation.'),
229 ('.*sign.*', 'Message.'),
230- ])
231+ ],
232+ )
233
234 self.create_and_check(
235 'bogus',

Subscribers

People subscribed via source and target branches

to all changes: