Merge lp:~adiroiban/pocket-lint/bug-889648 into lp:pocket-lint

Proposed by Adi Roiban
Status: Merged
Approved by: Curtis Hovey
Approved revision: 402
Merged at revision: 402
Proposed branch: lp:~adiroiban/pocket-lint/bug-889648
Merge into: lp:pocket-lint
Diff against target: 59 lines (+33/-0)
2 files modified
pocketlint/formatcheck.py (+10/-0)
pocketlint/tests/test_python.py (+23/-0)
To merge this branch: bzr merge lp:~adiroiban/pocket-lint/bug-889648
Reviewer Review Type Date Requested Status
Curtis Hovey code Approve
Review via email: mp+82059@code.launchpad.net

Description of the change

Hi,

This is a stupid code that I have added just to start the discussion about how this should be solved.

The problem is that when calling pocket-lint using 'check_sources', PythonChecker will always receive an ascii text.
In PythonChecker tests, it is passed both ascii and unicode texts.

This inconsistency does not allow using sometihg line 'line = line.decode(self.encoding)' and the line lenght 'smart' check is hardcoded to unicode.

Cheers,
Adi

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

Line 52 should read
    full_text = encoding_line + line_79_chars

I have fixed this in my merge.

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-09-10 14:53:27 +0000
3+++ pocketlint/formatcheck.py 2011-11-13 00:00:29 +0000
4@@ -2,6 +2,7 @@
5 # Copyright (C) 2009-2011 - Curtis Hovey <sinzui.is at verizon.net>
6 # This software is licensed under the MIT license (see the file COPYING).
7 """Check for syntax and style problems."""
8+from __future__ import with_statement
9
10 __metaclass__ = type
11
12@@ -527,6 +528,15 @@
13 self.message(
14 line_no, 'Line contains a call to pdb.', icon='error')
15
16+ def check_length(self, line_no, line):
17+ # isinstance is checked since 'test_code_utf8' is passing an unicode
18+ # text to PythonChecker, but check_sources always opens the file in
19+ # ascii mode, so PythonChecker alwasy received the text as ascii
20+ # encoded.
21+ if self.encoding == 'utf-8' and not isinstance(line, unicode):
22+ line = line.decode('utf-8')
23+ super(PythonChecker, self).check_length(line_no, line)
24+
25 def check_ascii(self, line_no, line):
26 """Check that the line is ascii."""
27 if self.encoding != 'ascii':
28
29=== modified file 'pocketlint/tests/test_python.py'
30--- pocketlint/tests/test_python.py 2011-05-04 15:39:13 +0000
31+++ pocketlint/tests/test_python.py 2011-11-13 00:00:29 +0000
32@@ -256,3 +256,26 @@
33 self.assertEqual(
34 [(1, 'Non-ascii characer at position 21.')],
35 self.reporter.messages)
36+
37+ def test_length_unicode_ok(self):
38+ encoding_line = '# -*- coding: utf-8 -*-\n'
39+ unicode_4_chars = 'mi\xc8\x9bi'
40+ line_78_chars = 'pa' + unicode_4_chars * 19 + '\n'
41+ full_text = encoding_line + line_78_chars
42+
43+ checker = PythonChecker('bogus',full_text, self.reporter)
44+ checker.check_text()
45+
46+ self.assertEqual([], self.reporter.messages)
47+
48+ def test_length_unicode_bad(self):
49+ encoding_line = '# -*- coding: utf-8 -*-\n'
50+ unicode_4_chars = 'mi\xc8\x9bi'
51+ line_79_chars = 'pap' + unicode_4_chars * 19 + '\n'
52+ full_text = encoding_line + line_78_chars
53+
54+ checker = PythonChecker('bogus',full_text, self.reporter)
55+ checker.check_text()
56+
57+ self.assertEqual(
58+ [(2, 'Line exceeds 78 characters.')], self.reporter.messages)
59\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: