fix python 2.7 issues. the parser now only takes unicode inputs

This commit is contained in:
Dave Halter
2014-02-23 11:44:32 +01:00
parent c5fcebde82
commit 8e847f4982
7 changed files with 63 additions and 57 deletions

View File

@@ -1,3 +1,4 @@
from jedi._compatibility import u
from jedi.parser import Parser
from jedi.parser.user_context import UserContextParser
from jedi.parser import representation as pr
@@ -5,19 +6,19 @@ from jedi.parser import representation as pr
def test_user_statement_on_import():
"""github #285"""
s = "from datetime import (\n" \
" time)"
s = u("from datetime import (\n"
" time)")
for pos in [(2, 1), (2, 4)]:
u = UserContextParser(s, None, pos, None).user_stmt()
assert isinstance(u, pr.Import)
assert u.defunct is False
assert [str(n) for n in u.get_defined_names()] == ['time']
p = UserContextParser(s, None, pos, None).user_stmt()
assert isinstance(p, pr.Import)
assert p.defunct is False
assert [str(n) for n in p.get_defined_names()] == ['time']
class TestCallAndName():
def get_call(self, source):
stmt = Parser(source, no_docstr=True).module.statements[0]
stmt = Parser(u(source), no_docstr=True).module.statements[0]
return stmt.expression_list()[0]
def test_name_and_call_positions(self):
@@ -52,7 +53,7 @@ class TestCallAndName():
class TestSubscopes():
def get_sub(self, source):
return Parser(source).module.subscopes[0]
return Parser(u(source)).module.subscopes[0]
def test_subscope_names(self):
name = self.get_sub('class Foo: pass').name
@@ -71,7 +72,7 @@ class TestImports():
return Parser(source).module.imports[0]
def test_import_names(self):
imp = self.get_import('import math\n')
imp = self.get_import(u('import math\n'))
names = imp.get_defined_names()
assert len(names) == 1
assert str(names[0]) == 'math'
@@ -83,13 +84,13 @@ class TestImports():
def test_module():
module = Parser('asdf', 'example.py', no_docstr=True).module
module = Parser(u('asdf'), 'example.py', no_docstr=True).module
name = module.name
assert str(name) == 'example'
assert name.start_pos == (0, 0)
assert name.end_pos == (0, 0)
module = Parser('asdf', no_docstr=True).module
module = Parser(u('asdf'), no_docstr=True).module
name = module.name
assert str(name) == ''
assert name.start_pos == (0, 0)