mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 18:17:07 +08:00
fix python 2.7 issues. the parser now only takes unicode inputs
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user