mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
change some definition usages to goto_definitions in tests and docs
This commit is contained in:
@@ -168,8 +168,10 @@ class Script(object):
|
|||||||
x.name.lower()))
|
x.name.lower()))
|
||||||
|
|
||||||
def _prepare_goto(self, goto_path, is_like_search=False):
|
def _prepare_goto(self, goto_path, is_like_search=False):
|
||||||
""" Base for completions, goto and definition. Basically it returns
|
"""
|
||||||
the resolved scopes under cursor. """
|
Base for completions/goto. Basically it returns the resolved scopes
|
||||||
|
under cursor.
|
||||||
|
"""
|
||||||
debug.dbg('start: %s in %s' % (goto_path, self._parser.user_scope))
|
debug.dbg('start: %s in %s' % (goto_path, self._parser.user_scope))
|
||||||
|
|
||||||
user_stmt = self._parser.user_stmt
|
user_stmt = self._parser.user_stmt
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ class TestBase(unittest.TestCase):
|
|||||||
pos = len(lines), len(lines[-1])
|
pos = len(lines), len(lines[-1])
|
||||||
return jedi.Script(src, pos[0], pos[1], path)
|
return jedi.Script(src, pos[0], pos[1], path)
|
||||||
|
|
||||||
def definition(self, src, pos=None):
|
def goto_definitions(self, src, pos=None):
|
||||||
script = self.get_script(src, pos)
|
script = self.get_script(src, pos)
|
||||||
return script.definition()
|
return script.goto_definitions()
|
||||||
|
|
||||||
def completions(self, src, pos=None, path=None):
|
def completions(self, src, pos=None, path=None):
|
||||||
script = self.get_script(src, pos, path)
|
script = self.get_script(src, pos, path)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ def make_definitions():
|
|||||||
variable = sys or C or x or f or g or g() or h""")
|
variable = sys or C or x or f or g or g() or h""")
|
||||||
lines = source.splitlines()
|
lines = source.splitlines()
|
||||||
script = api.Script(source, len(lines), len('variable'), None)
|
script = api.Script(source, len(lines), len('variable'), None)
|
||||||
definitions += script.definition()
|
definitions += script.goto_definitions()
|
||||||
|
|
||||||
script2 = api.Script(source, 4, len('class C'), None)
|
script2 = api.Script(source, 4, len('class C'), None)
|
||||||
definitions += script2.usages()
|
definitions += script2.usages()
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class TestRegression(TestBase):
|
|||||||
self.function_definition(s, pos)
|
self.function_definition(s, pos)
|
||||||
assert self.function_definition(s, pos)
|
assert self.function_definition(s, pos)
|
||||||
|
|
||||||
def test_definition_cursor(self):
|
def test_goto_definition_cursor(self):
|
||||||
|
|
||||||
s = ("class A():\n"
|
s = ("class A():\n"
|
||||||
" def _something(self):\n"
|
" def _something(self):\n"
|
||||||
@@ -68,7 +68,7 @@ class TestRegression(TestBase):
|
|||||||
diff_line = 4, 10
|
diff_line = 4, 10
|
||||||
should2 = 8, 10
|
should2 = 8, 10
|
||||||
|
|
||||||
get_def = lambda pos: [d.description for d in self.definition(s, pos)]
|
get_def = lambda pos: [d.description for d in self.goto_definitions(s, pos)]
|
||||||
in_name = get_def(in_name)
|
in_name = get_def(in_name)
|
||||||
under_score = get_def(under_score)
|
under_score = get_def(under_score)
|
||||||
should1 = get_def(should1)
|
should1 = get_def(should1)
|
||||||
@@ -84,20 +84,20 @@ class TestRegression(TestBase):
|
|||||||
self.assertRaises(jedi.NotFoundError, get_def, cls)
|
self.assertRaises(jedi.NotFoundError, get_def, cls)
|
||||||
|
|
||||||
def test_keyword_doc(self):
|
def test_keyword_doc(self):
|
||||||
r = list(self.definition("or", (1, 1)))
|
r = list(self.goto_definitions("or", (1, 1)))
|
||||||
assert len(r) == 1
|
assert len(r) == 1
|
||||||
assert len(r[0].doc) > 100
|
assert len(r[0].doc) > 100
|
||||||
|
|
||||||
r = list(self.definition("asfdasfd", (1, 1)))
|
r = list(self.goto_definitions("asfdasfd", (1, 1)))
|
||||||
assert len(r) == 0
|
assert len(r) == 0
|
||||||
|
|
||||||
def test_operator_doc(self):
|
def test_operator_doc(self):
|
||||||
r = list(self.definition("a == b", (1, 3)))
|
r = list(self.goto_definitions("a == b", (1, 3)))
|
||||||
assert len(r) == 1
|
assert len(r) == 1
|
||||||
assert len(r[0].doc) > 100
|
assert len(r[0].doc) > 100
|
||||||
|
|
||||||
def test_function_call_signature(self):
|
def test_function_call_signature(self):
|
||||||
defs = self.definition("""
|
defs = self.goto_definitions("""
|
||||||
def f(x, y=1, z='a'):
|
def f(x, y=1, z='a'):
|
||||||
pass
|
pass
|
||||||
f""")
|
f""")
|
||||||
@@ -105,7 +105,7 @@ class TestRegression(TestBase):
|
|||||||
assert "f(x, y = 1, z = 'a')" in doc
|
assert "f(x, y = 1, z = 'a')" in doc
|
||||||
|
|
||||||
def test_class_call_signature(self):
|
def test_class_call_signature(self):
|
||||||
defs = self.definition("""
|
defs = self.goto_definitions("""
|
||||||
class Foo:
|
class Foo:
|
||||||
def __init__(self, x, y=1, z='a'):
|
def __init__(self, x, y=1, z='a'):
|
||||||
pass
|
pass
|
||||||
@@ -113,12 +113,12 @@ class TestRegression(TestBase):
|
|||||||
doc = defs[0].doc
|
doc = defs[0].doc
|
||||||
assert "Foo(self, x, y = 1, z = 'a')" in doc
|
assert "Foo(self, x, y = 1, z = 'a')" in doc
|
||||||
|
|
||||||
def test_definition_at_zero(self):
|
def test_goto_definition_at_zero(self):
|
||||||
assert self.definition("a", (1, 1)) == []
|
assert self.goto_definitions("a", (1, 1)) == []
|
||||||
s = self.definition("str", (1, 1))
|
s = self.goto_definitions("str", (1, 1))
|
||||||
assert len(s) == 1
|
assert len(s) == 1
|
||||||
assert list(s)[0].description == 'class str'
|
assert list(s)[0].description == 'class str'
|
||||||
assert self.definition("", (1, 0)) == []
|
assert self.goto_definitions("", (1, 0)) == []
|
||||||
|
|
||||||
def test_complete_at_zero(self):
|
def test_complete_at_zero(self):
|
||||||
s = self.completions("str", (1, 3))
|
s = self.completions("str", (1, 3))
|
||||||
@@ -128,9 +128,9 @@ class TestRegression(TestBase):
|
|||||||
s = self.completions("", (1, 0))
|
s = self.completions("", (1, 0))
|
||||||
assert len(s) > 0
|
assert len(s) > 0
|
||||||
|
|
||||||
def test_definition_on_import(self):
|
def test_goto_definition_on_import(self):
|
||||||
assert self.definition("import sys_blabla", (1, 8)) == []
|
assert self.goto_definitions("import sys_blabla", (1, 8)) == []
|
||||||
assert len(self.definition("import sys", (1, 8))) == 1
|
assert len(self.goto_definitions("import sys", (1, 8))) == 1
|
||||||
|
|
||||||
@cwd_at('jedi')
|
@cwd_at('jedi')
|
||||||
def test_complete_on_empty_import(self):
|
def test_complete_on_empty_import(self):
|
||||||
@@ -263,15 +263,15 @@ class TestRegression(TestBase):
|
|||||||
# .parser to load the module
|
# .parser to load the module
|
||||||
api.modules.Module(os.path.abspath('dynamic.py'), src2).parser
|
api.modules.Module(os.path.abspath('dynamic.py'), src2).parser
|
||||||
script = jedi.Script(src1, 1, len(src1), '../setup.py')
|
script = jedi.Script(src1, 1, len(src1), '../setup.py')
|
||||||
result = script.definition()
|
result = script.goto_definitions()
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
assert result[0].description == 'class int'
|
assert result[0].description == 'class int'
|
||||||
|
|
||||||
def test_named_import(self):
|
def test_named_import(self):
|
||||||
""" named import - jedi-vim issue #8 """
|
""" named import - jedi-vim issue #8 """
|
||||||
s = "import time as dt"
|
s = "import time as dt"
|
||||||
assert len(jedi.Script(s, 1, 15, '/').definition()) == 1
|
assert len(jedi.Script(s, 1, 15, '/').goto_definitions()) == 1
|
||||||
assert len(jedi.Script(s, 1, 10, '/').definition()) == 1
|
assert len(jedi.Script(s, 1, 10, '/').goto_definitions()) == 1
|
||||||
|
|
||||||
def test_unicode_script(self):
|
def test_unicode_script(self):
|
||||||
""" normally no unicode objects are being used. (<=2.7) """
|
""" normally no unicode objects are being used. (<=2.7) """
|
||||||
@@ -328,10 +328,10 @@ class TestRegression(TestBase):
|
|||||||
|
|
||||||
def test_keyword_definition_doc(self):
|
def test_keyword_definition_doc(self):
|
||||||
""" github jedi-vim issue #44 """
|
""" github jedi-vim issue #44 """
|
||||||
defs = self.definition("print")
|
defs = self.goto_definitions("print")
|
||||||
assert [d.doc for d in defs]
|
assert [d.doc for d in defs]
|
||||||
|
|
||||||
defs = self.definition("import")
|
defs = self.goto_definitions("import")
|
||||||
assert len(defs) == 1
|
assert len(defs) == 1
|
||||||
assert [d.doc for d in defs]
|
assert [d.doc for d in defs]
|
||||||
|
|
||||||
@@ -380,7 +380,7 @@ class TestRegression(TestBase):
|
|||||||
|
|
||||||
variable = f or C""")
|
variable = f or C""")
|
||||||
lines = source.splitlines()
|
lines = source.splitlines()
|
||||||
defs = self.definition(source, (len(lines), 3))
|
defs = self.goto_definitions(source, (len(lines), 3))
|
||||||
defs = sorted(defs, key=lambda d: d.line)
|
defs = sorted(defs, key=lambda d: d.line)
|
||||||
self.assertEqual([d.description for d in defs],
|
self.assertEqual([d.description for d in defs],
|
||||||
['def f', 'class C'])
|
['def f', 'class C'])
|
||||||
@@ -389,21 +389,21 @@ class TestRegression(TestBase):
|
|||||||
class TestDocstring(TestBase):
|
class TestDocstring(TestBase):
|
||||||
|
|
||||||
def test_function_doc(self):
|
def test_function_doc(self):
|
||||||
defs = self.definition("""
|
defs = self.goto_definitions("""
|
||||||
def func():
|
def func():
|
||||||
'''Docstring of `func`.'''
|
'''Docstring of `func`.'''
|
||||||
func""")
|
func""")
|
||||||
self.assertEqual(defs[0].raw_doc, 'Docstring of `func`.')
|
self.assertEqual(defs[0].raw_doc, 'Docstring of `func`.')
|
||||||
|
|
||||||
def test_attribute_docstring(self):
|
def test_attribute_docstring(self):
|
||||||
defs = self.definition("""
|
defs = self.goto_definitions("""
|
||||||
x = None
|
x = None
|
||||||
'''Docstring of `x`.'''
|
'''Docstring of `x`.'''
|
||||||
x""")
|
x""")
|
||||||
self.assertEqual(defs[0].raw_doc, 'Docstring of `x`.')
|
self.assertEqual(defs[0].raw_doc, 'Docstring of `x`.')
|
||||||
|
|
||||||
def test_multiple_docstrings(self):
|
def test_multiple_docstrings(self):
|
||||||
defs = self.definition("""
|
defs = self.goto_definitions("""
|
||||||
def func():
|
def func():
|
||||||
'''Original docstring.'''
|
'''Original docstring.'''
|
||||||
x = func
|
x = func
|
||||||
@@ -435,7 +435,7 @@ class TestFeature(TestBase):
|
|||||||
import re
|
import re
|
||||||
any_re = re.compile('.*')
|
any_re = re.compile('.*')
|
||||||
any_re"""
|
any_re"""
|
||||||
self.assertEqual(self.definition(s)[0].full_name, 're.RegexObject')
|
self.assertEqual(self.goto_definitions(s)[0].full_name, 're.RegexObject')
|
||||||
|
|
||||||
def test_quick_completion(self):
|
def test_quick_completion(self):
|
||||||
sources = [
|
sources = [
|
||||||
|
|||||||
Reference in New Issue
Block a user