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
1=== modified file 'pocketlint/formatcheck.py'
2--- pocketlint/formatcheck.py 2013-11-06 15:21:20 +0000
3+++ pocketlint/formatcheck.py 2014-02-05 18:44:51 +0000
4@@ -633,7 +633,11 @@
5 """Check compilation and syntax."""
6 try:
7 tree = compile(
8- self.text, self.file_path, "exec", _ast.PyCF_ONLY_AST)
9+ self.text.encode(self.encoding),
10+ self.file_path,
11+ "exec",
12+ _ast.PyCF_ONLY_AST,
13+ )
14 except (SyntaxError, IndentationError) as exc:
15 line_no = exc.lineno or 0
16 line = exc.text or ''
17
18=== modified file 'pocketlint/tests/test_python.py'
19--- pocketlint/tests/test_python.py 2013-02-16 18:03:51 +0000
20+++ pocketlint/tests/test_python.py 2014-02-05 18:44:51 +0000
21@@ -150,6 +150,21 @@
22 self.assertEqual([], self.reporter.messages)
23 self.assertEqual(0, self.reporter.call_count)
24
25+ def test_pyflakes_unicode(self):
26+ """
27+ It handles Python non-ascii encoded files.
28+ """
29+ source = (
30+ '# -*- coding: utf-8 -*-\n'
31+ 'variable = u"r\xe9sum\xe9"'
32+ )
33+ checker = PythonChecker('bogus', source, self.reporter)
34+ # This should set the correct encoding.
35+ checker.check_text()
36+
37+ checker.check_flakes()
38+ self.assertEqual([], self.reporter.messages)
39+
40
41 class TestPEP8(CheckerTestCase):
42 """Verify PEP8 integration."""

Subscribers

People subscribed via source and target branches

to all changes: