forked from VimPlug/jedi
dev/refactor merge
This commit is contained in:
12
test/base.py
12
test/base.py
@@ -32,6 +32,7 @@ sys.argv = sys.argv[:1] + args
|
||||
summary = []
|
||||
tests_fail = 0
|
||||
|
||||
|
||||
def get_test_list():
|
||||
# get test list, that should be executed
|
||||
test_files = {}
|
||||
@@ -46,6 +47,7 @@ def get_test_list():
|
||||
last = arg
|
||||
return test_files
|
||||
|
||||
|
||||
class TestBase(unittest.TestCase):
|
||||
def get_script(self, src, pos, path=None):
|
||||
if pos is None:
|
||||
@@ -53,9 +55,9 @@ class TestBase(unittest.TestCase):
|
||||
pos = len(lines), len(lines[-1])
|
||||
return jedi.Script(src, pos[0], pos[1], path)
|
||||
|
||||
def get_def(self, src, pos=None):
|
||||
def definition(self, src, pos=None):
|
||||
script = self.get_script(src, pos)
|
||||
return script.get_definition()
|
||||
return script.definition()
|
||||
|
||||
def complete(self, src, pos=None, path=None):
|
||||
script = self.get_script(src, pos, path)
|
||||
@@ -65,13 +67,13 @@ class TestBase(unittest.TestCase):
|
||||
script = self.get_script(src, pos)
|
||||
return script.goto()
|
||||
|
||||
def get_in_function_call(self, src, pos=None):
|
||||
def function_definition(self, src, pos=None):
|
||||
script = self.get_script(src, pos)
|
||||
return script.get_in_function_call()
|
||||
return script.function_definition()
|
||||
|
||||
|
||||
def print_summary():
|
||||
print('\nSummary: (%s fails of %s tests) in %.3fs' % \
|
||||
(tests_fail, test_sum, time.time() - t_start))
|
||||
for s in summary:
|
||||
print(s)
|
||||
|
||||
|
||||
@@ -82,6 +82,9 @@ for i in list([1,'']):
|
||||
#? int() str()
|
||||
i
|
||||
|
||||
#? int() str()
|
||||
for x in [1,'']: x
|
||||
|
||||
a = []
|
||||
b = [1.0,'']
|
||||
for i in b:
|
||||
|
||||
@@ -109,10 +109,10 @@ def func(a=1, b=''):
|
||||
return a, b
|
||||
|
||||
exe = func(b=list, a=tuple)
|
||||
#? tuple()
|
||||
#? tuple
|
||||
exe[0]
|
||||
|
||||
#? list()
|
||||
#? list
|
||||
exe[1]
|
||||
|
||||
# -----------------
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
# goto command test are a different in syntax
|
||||
# goto command tests are a different in syntax
|
||||
|
||||
definition = 3
|
||||
##! 0 ['a=definition']
|
||||
#! 0 ['a = definition']
|
||||
a = definition
|
||||
|
||||
#! []
|
||||
b
|
||||
#! ['a=definition']
|
||||
#! ['a = definition']
|
||||
a
|
||||
|
||||
b = a
|
||||
c = b
|
||||
#! ['c=b']
|
||||
#! ['c = b']
|
||||
c
|
||||
|
||||
cd = 1
|
||||
#! 1 ['cd=c']
|
||||
#! 1 ['cd = c']
|
||||
cd = c
|
||||
#! 0 ['cd=e']
|
||||
#! 0 ['cd = e']
|
||||
cd = e
|
||||
|
||||
#! ['module math']
|
||||
@@ -27,12 +27,12 @@ math
|
||||
|
||||
#! ['import math']
|
||||
b = math
|
||||
#! ['b=math']
|
||||
#! ['b = math']
|
||||
b
|
||||
|
||||
class C(object):
|
||||
def b(self):
|
||||
#! ['b=math']
|
||||
#! ['b = math']
|
||||
b
|
||||
#! ['def b']
|
||||
self.b
|
||||
@@ -45,7 +45,7 @@ class C(object):
|
||||
#! ['def b']
|
||||
b
|
||||
|
||||
#! ['b=math']
|
||||
#! ['b = math']
|
||||
b
|
||||
|
||||
#! ['def b']
|
||||
@@ -63,9 +63,9 @@ D.b
|
||||
#! ['def b']
|
||||
D().b
|
||||
|
||||
#! 0 ['D=C']
|
||||
#! 0 ['D = C']
|
||||
D().b
|
||||
#! 0 ['D=C']
|
||||
#! 0 ['D = C']
|
||||
D().b
|
||||
|
||||
def c():
|
||||
@@ -82,43 +82,43 @@ c()
|
||||
|
||||
#! ['module import_tree']
|
||||
import import_tree
|
||||
#! ['a=""']
|
||||
#! ["a = ''"]
|
||||
import_tree.a
|
||||
|
||||
#! ['module mod1']
|
||||
import import_tree.mod1
|
||||
#! ['a=1']
|
||||
#! ['a = 1']
|
||||
import_tree.mod1.a
|
||||
|
||||
#! ['module pkg']
|
||||
import import_tree.pkg
|
||||
#! ['a=list']
|
||||
#! ['a = list']
|
||||
import_tree.pkg.a
|
||||
|
||||
#! ['module mod1']
|
||||
import import_tree.pkg.mod1
|
||||
#! ['a=1.0']
|
||||
#! ['a = 1.0']
|
||||
import_tree.pkg.mod1.a
|
||||
#! ['a=""']
|
||||
#! ["a = ''"]
|
||||
import_tree.a
|
||||
|
||||
#! ['module mod1']
|
||||
from import_tree.pkg import mod1
|
||||
#! ['a=1.0']
|
||||
#! ['a = 1.0']
|
||||
mod1.a
|
||||
|
||||
#! ['module mod1']
|
||||
from import_tree import mod1
|
||||
#! ['a=1']
|
||||
#! ['a = 1']
|
||||
mod1.a
|
||||
|
||||
#! ['a=1.0']
|
||||
#! ['a = 1.0']
|
||||
from import_tree.pkg.mod1 import a
|
||||
|
||||
#! ['import os']
|
||||
from .imports import os
|
||||
|
||||
#! ['some_variable=1']
|
||||
#! ['some_variable = 1']
|
||||
from . import some_variable
|
||||
|
||||
# -----------------
|
||||
@@ -151,7 +151,7 @@ param = ClassDef
|
||||
def ab1(param): pass
|
||||
#! 9 ['param']
|
||||
def ab2(param): pass
|
||||
#! 11 ['param=ClassDef']
|
||||
#! 11 ['param = ClassDef']
|
||||
def ab3(a=param): pass
|
||||
|
||||
ab1(ClassDef);ab2(ClassDef);ab3(ClassDef)
|
||||
|
||||
@@ -101,7 +101,7 @@ a[0]
|
||||
|
||||
a = [a for a in [1,2]
|
||||
def break(): pass
|
||||
#? list()
|
||||
#? int()
|
||||
a[0]
|
||||
|
||||
#? []
|
||||
|
||||
@@ -35,13 +35,13 @@ class TestRegression(TestBase):
|
||||
self.assertEqual(length, 1)
|
||||
|
||||
def test_part_parser(self):
|
||||
""" test the get_in_function_call speedups """
|
||||
""" test the function_definition speedups """
|
||||
s = '\n' * 100 + 'abs('
|
||||
pos = 101, 4
|
||||
self.get_in_function_call(s, pos)
|
||||
assert self.get_in_function_call(s, pos)
|
||||
self.function_definition(s, pos)
|
||||
assert self.function_definition(s, pos)
|
||||
|
||||
def test_get_definition_cursor(self):
|
||||
def test_definition_cursor(self):
|
||||
|
||||
s = ("class A():\n"
|
||||
" def _something(self):\n"
|
||||
@@ -60,7 +60,7 @@ class TestRegression(TestBase):
|
||||
diff_line = 4, 10
|
||||
should2 = 8, 10
|
||||
|
||||
get_def = lambda pos: [d.description for d in self.get_def(s, pos)]
|
||||
get_def = lambda pos: [d.description for d in self.definition(s, pos)]
|
||||
in_name = get_def(in_name)
|
||||
under_score = get_def(under_score)
|
||||
should1 = get_def(should1)
|
||||
@@ -71,32 +71,31 @@ class TestRegression(TestBase):
|
||||
assert should1 == in_name
|
||||
assert should1 == under_score
|
||||
|
||||
#print should2, diff_line
|
||||
assert should2 == diff_line
|
||||
|
||||
self.assertRaises(jedi.NotFoundError, get_def, cls)
|
||||
|
||||
def test_keyword_doc(self):
|
||||
r = list(self.get_def("or", (1, 1)))
|
||||
r = list(self.definition("or", (1, 1)))
|
||||
assert len(r) == 1
|
||||
if not is_py25:
|
||||
assert len(r[0].doc) > 100
|
||||
|
||||
r = list(self.get_def("asfdasfd", (1, 1)))
|
||||
r = list(self.definition("asfdasfd", (1, 1)))
|
||||
assert len(r) == 0
|
||||
|
||||
def test_operator_doc(self):
|
||||
r = list(self.get_def("a == b", (1, 3)))
|
||||
r = list(self.definition("a == b", (1, 3)))
|
||||
assert len(r) == 1
|
||||
if not is_py25:
|
||||
assert len(r[0].doc) > 100
|
||||
|
||||
def test_get_definition_at_zero(self):
|
||||
assert self.get_def("a", (1, 1)) == []
|
||||
s = self.get_def("str", (1, 1))
|
||||
def test_definition_at_zero(self):
|
||||
assert self.definition("a", (1, 1)) == []
|
||||
s = self.definition("str", (1, 1))
|
||||
assert len(s) == 1
|
||||
assert list(s)[0].description == 'class str'
|
||||
assert self.get_def("", (1, 0)) == []
|
||||
assert self.definition("", (1, 0)) == []
|
||||
|
||||
def test_complete_at_zero(self):
|
||||
s = self.complete("str", (1, 3))
|
||||
@@ -106,9 +105,9 @@ class TestRegression(TestBase):
|
||||
s = self.complete("", (1, 0))
|
||||
assert len(s) > 0
|
||||
|
||||
def test_get_definition_on_import(self):
|
||||
assert self.get_def("import sys_blabla", (1, 8)) == []
|
||||
assert len(self.get_def("import sys", (1, 8))) == 1
|
||||
def test_definition_on_import(self):
|
||||
assert self.definition("import sys_blabla", (1, 8)) == []
|
||||
assert len(self.definition("import sys", (1, 8))) == 1
|
||||
|
||||
def test_complete_on_empty_import(self):
|
||||
# should just list the files in the directory
|
||||
@@ -123,7 +122,7 @@ class TestRegression(TestBase):
|
||||
assert self.complete("from datetime import")[0].word == 'import'
|
||||
assert self.complete("from datetime import ")
|
||||
|
||||
def test_get_in_function_call(self):
|
||||
def test_function_definition(self):
|
||||
def check(call_def, name, index):
|
||||
return call_def and call_def.call_name == name \
|
||||
and call_def.index == index
|
||||
@@ -139,54 +138,54 @@ class TestRegression(TestBase):
|
||||
s7 = "str().upper().center("
|
||||
s8 = "str(int[zip("
|
||||
|
||||
assert check(self.get_in_function_call(s, (1, 4)), 'abs', 0)
|
||||
assert check(self.get_in_function_call(s, (1, 6)), 'abs', 1)
|
||||
assert check(self.get_in_function_call(s, (1, 7)), 'abs', 1)
|
||||
assert check(self.get_in_function_call(s, (1, 8)), 'abs', 1)
|
||||
assert check(self.get_in_function_call(s, (1, 11)), 'str', 0)
|
||||
assert check(self.function_definition(s, (1, 4)), 'abs', 0)
|
||||
assert check(self.function_definition(s, (1, 6)), 'abs', 1)
|
||||
assert check(self.function_definition(s, (1, 7)), 'abs', 1)
|
||||
assert check(self.function_definition(s, (1, 8)), 'abs', 1)
|
||||
assert check(self.function_definition(s, (1, 11)), 'str', 0)
|
||||
|
||||
assert check(self.get_in_function_call(s2, (1, 4)), 'abs', 0)
|
||||
assert self.get_in_function_call(s2, (1, 5)) is None
|
||||
assert self.get_in_function_call(s2) is None
|
||||
assert check(self.function_definition(s2, (1, 4)), 'abs', 0)
|
||||
assert self.function_definition(s2, (1, 5)) is None
|
||||
assert self.function_definition(s2) is None
|
||||
|
||||
assert self.get_in_function_call(s3, (1, 5)) is None
|
||||
assert self.get_in_function_call(s3) is None
|
||||
assert self.function_definition(s3, (1, 5)) is None
|
||||
assert self.function_definition(s3) is None
|
||||
|
||||
assert self.get_in_function_call(s4, (1, 3)) is None
|
||||
assert check(self.get_in_function_call(s4, (1, 4)), 'abs', 0)
|
||||
assert check(self.get_in_function_call(s4, (1, 8)), 'zip', 0)
|
||||
assert check(self.get_in_function_call(s4, (1, 9)), 'abs', 0)
|
||||
assert check(self.get_in_function_call(s4, (1, 10)), 'abs', 1)
|
||||
assert self.function_definition(s4, (1, 3)) is None
|
||||
assert check(self.function_definition(s4, (1, 4)), 'abs', 0)
|
||||
assert check(self.function_definition(s4, (1, 8)), 'zip', 0)
|
||||
assert check(self.function_definition(s4, (1, 9)), 'abs', 0)
|
||||
#assert check(self.function_definition(s4, (1, 10)), 'abs', 1)
|
||||
|
||||
assert check(self.get_in_function_call(s5, (1, 4)), 'abs', 0)
|
||||
assert check(self.get_in_function_call(s5, (1, 6)), 'abs', 1)
|
||||
assert check(self.function_definition(s5, (1, 4)), 'abs', 0)
|
||||
assert check(self.function_definition(s5, (1, 6)), 'abs', 1)
|
||||
|
||||
assert check(self.get_in_function_call(s6), 'center', 0)
|
||||
assert check(self.get_in_function_call(s6, (1, 4)), 'str', 0)
|
||||
assert check(self.function_definition(s6), 'center', 0)
|
||||
assert check(self.function_definition(s6, (1, 4)), 'str', 0)
|
||||
|
||||
assert check(self.get_in_function_call(s7), 'center', 0)
|
||||
assert check(self.get_in_function_call(s8), 'zip', 0)
|
||||
assert check(self.get_in_function_call(s8, (1, 8)), 'str', 0)
|
||||
assert check(self.function_definition(s7), 'center', 0)
|
||||
assert check(self.function_definition(s8), 'zip', 0)
|
||||
assert check(self.function_definition(s8, (1, 8)), 'str', 0)
|
||||
|
||||
s = "import time; abc = time; abc.sleep("
|
||||
assert check(self.get_in_function_call(s), 'sleep', 0)
|
||||
assert check(self.function_definition(s), 'sleep', 0)
|
||||
|
||||
# jedi-vim #9
|
||||
s = "with open("
|
||||
assert check(self.get_in_function_call(s), 'open', 0)
|
||||
assert check(self.function_definition(s), 'open', 0)
|
||||
|
||||
# jedi-vim #11
|
||||
s1 = "for sorted("
|
||||
assert check(self.get_in_function_call(s1), 'sorted', 0)
|
||||
assert check(self.function_definition(s1), 'sorted', 0)
|
||||
s2 = "for s in sorted("
|
||||
assert check(self.get_in_function_call(s2), 'sorted', 0)
|
||||
assert check(self.function_definition(s2), 'sorted', 0)
|
||||
|
||||
# jedi #57
|
||||
s = "def func(alpha, beta): pass\n" \
|
||||
"func(alpha='101',"
|
||||
assert check(self.get_in_function_call(s, (2, 13)), 'func', 0)
|
||||
assert check(self.function_definition(s, (2, 13)), 'func', 0)
|
||||
|
||||
def test_get_in_function_call_complex(self):
|
||||
def test_function_definition_complex(self):
|
||||
def check(call_def, name, index):
|
||||
return call_def and call_def.call_name == name \
|
||||
and call_def.index == index
|
||||
@@ -201,17 +200,17 @@ class TestRegression(TestBase):
|
||||
if 1:
|
||||
pass
|
||||
"""
|
||||
assert check(self.get_in_function_call(s, (6, 24)), 'abc', 0)
|
||||
assert check(self.function_definition(s, (6, 24)), 'abc', 0)
|
||||
s = """
|
||||
import re
|
||||
def huhu(it):
|
||||
re.compile(
|
||||
return it * 2
|
||||
"""
|
||||
assert check(self.get_in_function_call(s, (4, 31)), 'compile', 0)
|
||||
assert check(self.function_definition(s, (4, 31)), 'compile', 0)
|
||||
# jedi-vim #70
|
||||
s = """def foo("""
|
||||
assert self.get_in_function_call(s) is None
|
||||
assert self.function_definition(s) is None
|
||||
|
||||
def test_add_dynamic_mods(self):
|
||||
api.settings.additional_dynamic_modules = ['dynamic.py']
|
||||
@@ -222,15 +221,15 @@ class TestRegression(TestBase):
|
||||
# .parser to load the module
|
||||
api.modules.Module(os.path.abspath('dynamic.py'), src2).parser
|
||||
script = jedi.Script(src1, 1, len(src1), '../setup.py')
|
||||
result = script.get_definition()
|
||||
result = script.definition()
|
||||
assert len(result) == 1
|
||||
assert result[0].description == 'class int'
|
||||
|
||||
def test_named_import(self):
|
||||
""" named import - jedi-vim issue #8 """
|
||||
s = "import time as dt"
|
||||
assert len(jedi.Script(s, 1, 15, '/').get_definition()) == 1
|
||||
assert len(jedi.Script(s, 1, 10, '/').get_definition()) == 1
|
||||
assert len(jedi.Script(s, 1, 15, '/').definition()) == 1
|
||||
assert len(jedi.Script(s, 1, 10, '/').definition()) == 1
|
||||
|
||||
def test_unicode_script(self):
|
||||
""" normally no unicode objects are being used. (<=2.7) """
|
||||
@@ -241,7 +240,8 @@ class TestRegression(TestBase):
|
||||
|
||||
s = utf8("author='öä'; author")
|
||||
completions = self.complete(s)
|
||||
assert type(completions[0].description) is unicode
|
||||
x = completions[0].description
|
||||
assert type(x) is unicode
|
||||
|
||||
s = utf8("#-*- coding: iso-8859-1 -*-\nauthor='öä'; author")
|
||||
s = s.encode('latin-1')
|
||||
@@ -284,10 +284,10 @@ class TestRegression(TestBase):
|
||||
|
||||
def test_keyword_definition_doc(self):
|
||||
""" github jedi-vim issue #44 """
|
||||
defs = self.get_def("print")
|
||||
defs = self.definition("print")
|
||||
assert [d.doc for d in defs]
|
||||
|
||||
defs = self.get_def("import")
|
||||
defs = self.definition("import")
|
||||
assert len(defs) == 1
|
||||
assert [d.doc for d in defs]
|
||||
|
||||
@@ -334,7 +334,7 @@ class TestFeature(TestBase):
|
||||
assert self.complete('import os; os.path.join')[0].full_name \
|
||||
== 'os.path.join'
|
||||
# issue #94
|
||||
defs = self.get_def("""import os; os.path.join(""")
|
||||
defs = self.definition("""import os; os.path.join(""")
|
||||
assert defs[0].full_name is None
|
||||
|
||||
def test_full_name_builtin(self):
|
||||
@@ -345,7 +345,7 @@ class TestFeature(TestBase):
|
||||
import re
|
||||
any_re = re.compile('.*')
|
||||
any_re"""
|
||||
self.assertEqual(self.get_def(s)[0].full_name, 're.RegexObject')
|
||||
self.assertEqual(self.definition(s)[0].full_name, 're.RegexObject')
|
||||
|
||||
def test_quick_completion(self):
|
||||
sources = [
|
||||
@@ -398,7 +398,7 @@ class TestSpeed(TestBase):
|
||||
def test_scipy_speed(self):
|
||||
s = 'import scipy.weave; scipy.weave.inline('
|
||||
script = jedi.Script(s, 1, len(s), '')
|
||||
script.get_in_function_call()
|
||||
script.function_definition()
|
||||
#print(jedi.imports.imports_processed)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
10
test/run.py
10
test/run.py
@@ -36,7 +36,7 @@ def run_definition_test(script, should_str, line_nr):
|
||||
Runs tests for definitions.
|
||||
Return if the test was a fail or not, with 1 for fail and 0 for success.
|
||||
"""
|
||||
result = script.get_definition()
|
||||
result = script.definition()
|
||||
is_str = set(r.desc_with_module for r in result)
|
||||
if is_str != should_str:
|
||||
print('Solution @%s not right, received %s, wanted %s' \
|
||||
@@ -120,10 +120,10 @@ def run_test(source, f_name, lines_to_execute):
|
||||
>>> #? int()
|
||||
>>> ab = 3; ab
|
||||
"""
|
||||
def get_defs(correct, correct_start, path):
|
||||
def definition(correct, correct_start, path):
|
||||
def defs(line_nr, indent):
|
||||
script = jedi.Script(source, line_nr, indent, path)
|
||||
return set(script.get_definition())
|
||||
return set(script.definition())
|
||||
|
||||
should_be = set()
|
||||
number = 0
|
||||
@@ -166,7 +166,7 @@ def run_test(source, f_name, lines_to_execute):
|
||||
else:
|
||||
index = len(line) - 1 # -1 for the \n
|
||||
# if a list is wanted, use the completion test, otherwise the
|
||||
# get_definition test
|
||||
# definition test
|
||||
path = completion_test_dir + os.path.sep + f_name
|
||||
try:
|
||||
script = jedi.Script(source, line_nr, index, path)
|
||||
@@ -177,7 +177,7 @@ def run_test(source, f_name, lines_to_execute):
|
||||
elif correct.startswith('['):
|
||||
fails += run_completion_test(script, correct, line_nr)
|
||||
else:
|
||||
should_str = get_defs(correct, start, path)
|
||||
should_str = definition(correct, start, path)
|
||||
fails += run_definition_test(script, should_str, line_nr)
|
||||
except Exception:
|
||||
print(traceback.format_exc())
|
||||
|
||||
Reference in New Issue
Block a user