Merge lp:~adiroiban/pocket-lint/unicode-pyflakes into lp:pocket-lint

Proposed by Adi Roiban
Status: Merged
Merged at revision: 445
Proposed branch: lp:~adiroiban/pocket-lint/unicode-pyflakes
Merge into: lp:pocket-lint
Diff against target: 42 lines (+20/-1)
2 files modified
pocketlint/formatcheck.py (+5/-1)
pocketlint/tests/test_python.py (+15/-0)
To merge this branch: bzr merge lp:~adiroiban/pocket-lint/unicode-pyflakes
Reviewer Review Type Date Requested Status
Curtis Hovey code Approve
Review via email: mp+205030@code.launchpad.net

Description of the change

Here is the fix for encoding source before sending it to pyflakes.

Hope that travis-ci branch will land soon in master so that we can test on both python 3.3 and 2.7.

I have only tested on python 2.7

Thanks!

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

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'pocketlint/formatcheck.py'
--- pocketlint/formatcheck.py 2013-11-06 15:21:20 +0000
+++ pocketlint/formatcheck.py 2014-02-05 18:44:51 +0000
@@ -633,7 +633,11 @@
633 """Check compilation and syntax."""633 """Check compilation and syntax."""
634 try:634 try:
635 tree = compile(635 tree = compile(
636 self.text, self.file_path, "exec", _ast.PyCF_ONLY_AST)636 self.text.encode(self.encoding),
637 self.file_path,
638 "exec",
639 _ast.PyCF_ONLY_AST,
640 )
637 except (SyntaxError, IndentationError) as exc:641 except (SyntaxError, IndentationError) as exc:
638 line_no = exc.lineno or 0642 line_no = exc.lineno or 0
639 line = exc.text or ''643 line = exc.text or ''
640644
=== modified file 'pocketlint/tests/test_python.py'
--- pocketlint/tests/test_python.py 2013-02-16 18:03:51 +0000
+++ pocketlint/tests/test_python.py 2014-02-05 18:44:51 +0000
@@ -150,6 +150,21 @@
150 self.assertEqual([], self.reporter.messages)150 self.assertEqual([], self.reporter.messages)
151 self.assertEqual(0, self.reporter.call_count)151 self.assertEqual(0, self.reporter.call_count)
152152
153 def test_pyflakes_unicode(self):
154 """
155 It handles Python non-ascii encoded files.
156 """
157 source = (
158 '# -*- coding: utf-8 -*-\n'
159 'variable = u"r\xe9sum\xe9"'
160 )
161 checker = PythonChecker('bogus', source, self.reporter)
162 # This should set the correct encoding.
163 checker.check_text()
164
165 checker.check_flakes()
166 self.assertEqual([], self.reporter.messages)
167
153168
154class TestPEP8(CheckerTestCase):169class TestPEP8(CheckerTestCase):
155 """Verify PEP8 integration."""170 """Verify PEP8 integration."""

Subscribers

People subscribed via source and target branches

to all changes: