From ef62904af3465d99a438e2a65a28d62c5eed2c53 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 4 May 2014 11:50:13 +0200 Subject: [PATCH] python 2 compatibility (also with the new travis build) --- jedi/evaluate/imports.py | 1 + test/test_evaluate/test_pyc.py | 6 +++++- test/test_parser/test_fast_parser.py | 9 +++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index 7c10e5bc..073d64af 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -408,6 +408,7 @@ class _Importer(object): path += '/__init__.py' with open(path, 'rb') as f: source = f.read() + source = source.replace(b'\n', b'\r\n') else: source = current_namespace[0].read() current_namespace[0].close() diff --git a/test/test_evaluate/test_pyc.py b/test/test_evaluate/test_pyc.py index dee78e58..c101da13 100644 --- a/test/test_evaluate/test_pyc.py +++ b/test/test_evaluate/test_pyc.py @@ -6,11 +6,12 @@ Test completions from *.pyc files: - delete the pure python dummy module - try jedi on the generated *.pyc """ -import compileall import os import shutil import sys +import pytest + import jedi from ..helpers import cwd_at @@ -29,6 +30,7 @@ def generate_pyc(): pass with open("dummy_package/dummy.py", 'w') as f: f.write(SRC) + import compileall compileall.compile_file("dummy_package/dummy.py") os.remove("dummy_package/dummy.py") @@ -43,6 +45,8 @@ def generate_pyc(): shutil.copy(os.path.join("dummy_package/__pycache__", f), dst) +# Python 2.6 does not necessarily come with `compileall.compile_file`. +@pytest.mark.skipif("sys.version_info > (2,6)") @cwd_at('test/test_evaluate') def test_pyc(): """ diff --git a/test/test_parser/test_fast_parser.py b/test/test_parser/test_fast_parser.py index 8c45cf50..3d4c94c6 100644 --- a/test/test_parser/test_fast_parser.py +++ b/test/test_parser/test_fast_parser.py @@ -1,6 +1,7 @@ from textwrap import dedent import jedi +from jedi._compatibility import u from jedi.parser.fast import FastParser @@ -23,11 +24,11 @@ class Two(Abc): b = " def g(self):\n" \ " self." assert jedi.Script(a, 8, 12, 'example.py').completions() - assert jedi.Script(a + b, path='example.py').completions() + assert jedi.Script(a + b, path='example.py').completions() a = a[:-1] + '.\n' assert jedi.Script(a, 8, 13, 'example.py').completions() - assert jedi.Script(a + b, path='example.py').completions() + assert jedi.Script(a + b, path='example.py').completions() def test_class_in_docstr(): @@ -42,7 +43,7 @@ def test_class_in_docstr(): def test_carriage_return_splitting(): - source = dedent(''' + source = u(dedent(''' @@ -50,7 +51,7 @@ def test_carriage_return_splitting(): class Foo(): pass - ''') + ''')) source = source.replace('\n', '\r\n') p = FastParser(source) assert [str(n) for n in p.module.get_defined_names()] == ['Foo']