forked from VimPlug/jedi
goto_assignment -> goto everywhere where it was left
This commit is contained in:
@@ -123,11 +123,11 @@ def test_completion_on_complex_literals(Script):
|
||||
{'if', 'and', 'in', 'is', 'not', 'or'})
|
||||
|
||||
|
||||
def test_goto_assignments_on_non_name(Script, environment):
|
||||
assert Script('for').goto_assignments() == []
|
||||
def test_goto_non_name(Script, environment):
|
||||
assert Script('for').goto() == []
|
||||
|
||||
assert Script('assert').goto_assignments() == []
|
||||
assert Script('True').goto_assignments() == []
|
||||
assert Script('assert').goto() == []
|
||||
assert Script('True').goto() == []
|
||||
|
||||
|
||||
def test_infer_on_non_name(Script):
|
||||
@@ -197,23 +197,23 @@ def test_get_line_code_on_builtin(Script, disable_typeshed):
|
||||
assert abs_.line is None
|
||||
|
||||
|
||||
def test_goto_assignments_follow_imports(Script):
|
||||
def test_goto_follow_imports(Script):
|
||||
code = dedent("""
|
||||
import inspect
|
||||
inspect.isfunction""")
|
||||
definition, = Script(code, column=0).goto_assignments(follow_imports=True)
|
||||
definition, = Script(code).goto(column=0, follow_imports=True)
|
||||
assert 'inspect.py' in definition.module_path
|
||||
assert (definition.line, definition.column) == (1, 0)
|
||||
|
||||
definition, = Script(code).goto_assignments(follow_imports=True)
|
||||
definition, = Script(code).goto(follow_imports=True)
|
||||
assert 'inspect.py' in definition.module_path
|
||||
assert (definition.line, definition.column) > (1, 0)
|
||||
|
||||
code = '''def param(p): pass\nparam(1)'''
|
||||
start_pos = 1, len('def param(')
|
||||
|
||||
script = Script(code, *start_pos)
|
||||
definition, = script.goto_assignments(follow_imports=True)
|
||||
script = Script(code)
|
||||
definition, = script.goto(*start_pos, follow_imports=True)
|
||||
assert (definition.line, definition.column) == start_pos
|
||||
assert definition.name == 'p'
|
||||
result, = definition.goto()
|
||||
@@ -223,17 +223,17 @@ def test_goto_assignments_follow_imports(Script):
|
||||
result, = result.infer()
|
||||
assert result.name == 'int'
|
||||
|
||||
definition, = script.goto_assignments()
|
||||
definition, = script.goto(*start_pos)
|
||||
assert (definition.line, definition.column) == start_pos
|
||||
|
||||
d, = Script('a = 1\na').goto_assignments(follow_imports=True)
|
||||
d, = Script('a = 1\na').goto(follow_imports=True)
|
||||
assert d.name == 'a'
|
||||
|
||||
|
||||
def test_goto_module(Script):
|
||||
def check(line, expected, follow_imports=False):
|
||||
script = Script(path=path, line=line)
|
||||
module, = script.goto_assignments(follow_imports=follow_imports)
|
||||
script = Script(path=path)
|
||||
module, = script.goto(line=line, follow_imports=follow_imports)
|
||||
assert module.module_path == expected
|
||||
|
||||
base_path = os.path.join(os.path.dirname(__file__), 'simple_import')
|
||||
@@ -309,9 +309,9 @@ def test_backslash_continuation_and_bracket(Script):
|
||||
|
||||
def test_goto_follow_builtin_imports(Script):
|
||||
s = Script('import sys; sys')
|
||||
d, = s.goto_assignments(follow_imports=True)
|
||||
d, = s.goto(follow_imports=True)
|
||||
assert d.in_builtin_module() is True
|
||||
d, = s.goto_assignments(follow_imports=True, follow_builtin_imports=True)
|
||||
d, = s.goto(follow_imports=True, follow_builtin_imports=True)
|
||||
assert d.in_builtin_module() is True
|
||||
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ def test_basedefinition_type(Script, names):
|
||||
definitions += script2.usages()
|
||||
|
||||
source_param = "def f(a): return a"
|
||||
script_param = Script(source_param, 1, len(source_param), None)
|
||||
definitions += script_param.goto_assignments()
|
||||
script_param = Script(source_param, path=None)
|
||||
definitions += script_param.goto(1, len(source_param))
|
||||
|
||||
return definitions
|
||||
|
||||
@@ -118,7 +118,7 @@ def test_class_call_signature(Script):
|
||||
|
||||
|
||||
def test_position_none_if_builtin(Script):
|
||||
gotos = Script('import sys; sys.path').goto_assignments()
|
||||
gotos = Script('import sys; sys.path').goto()
|
||||
assert gotos[0].in_builtin_module()
|
||||
assert gotos[0].line is not None
|
||||
assert gotos[0].column is not None
|
||||
@@ -206,8 +206,8 @@ def test_signature_params(Script):
|
||||
|
||||
check(Script(s).infer())
|
||||
|
||||
check(Script(s).goto_assignments())
|
||||
check(Script(s + '\nbar=foo\nbar').goto_assignments())
|
||||
check(Script(s).goto())
|
||||
check(Script(s + '\nbar=foo\nbar').goto())
|
||||
|
||||
|
||||
def test_param_endings(Script):
|
||||
@@ -253,7 +253,7 @@ def test_is_definition_import(names, code, expected):
|
||||
|
||||
def test_parent(Script):
|
||||
def _parent(source, line=None, column=None):
|
||||
def_, = Script(dedent(source), line, column).goto_assignments()
|
||||
def_, = Script(dedent(source)).goto(line, column)
|
||||
return def_.parent()
|
||||
|
||||
parent = _parent('foo=1\nfoo')
|
||||
@@ -270,7 +270,7 @@ def test_parent(Script):
|
||||
|
||||
def test_parent_on_function(Script):
|
||||
code = 'def spam():\n pass'
|
||||
def_, = Script(code, line=1, column=len('def spam')).goto_assignments()
|
||||
def_, = Script(code).goto(line=1, column=len('def spam'))
|
||||
parent = def_.parent()
|
||||
assert parent.name == ''
|
||||
assert parent.type == 'module'
|
||||
@@ -328,13 +328,13 @@ def test_type_II(Script):
|
||||
|
||||
|
||||
"""
|
||||
This tests the BaseDefinition.goto_assignments function, not the jedi
|
||||
This tests the BaseDefinition.goto function, not the jedi
|
||||
function. They are not really different in functionality, but really
|
||||
different as an implementation.
|
||||
"""
|
||||
|
||||
|
||||
def test_goto_assignment_repetition(names):
|
||||
def test_goto_repetition(names):
|
||||
defs = names('a = 1; a', references=True, definitions=False)
|
||||
# Repeat on the same variable. Shouldn't change once we're on a
|
||||
# definition.
|
||||
@@ -344,7 +344,7 @@ def test_goto_assignment_repetition(names):
|
||||
assert ass[0].description == 'a = 1'
|
||||
|
||||
|
||||
def test_goto_assignments_named_params(names):
|
||||
def test_goto_named_params(names):
|
||||
src = """\
|
||||
def foo(a=1, bar=2):
|
||||
pass
|
||||
@@ -468,7 +468,7 @@ def test_builtin_module_with_path(Script):
|
||||
]
|
||||
)
|
||||
def test_execute(Script, code, description):
|
||||
definition, = Script(code).goto_assignments()
|
||||
definition, = Script(code).goto()
|
||||
definitions = definition.execute()
|
||||
if description is None:
|
||||
assert not definitions
|
||||
@@ -477,7 +477,7 @@ def test_execute(Script, code, description):
|
||||
assert d.description == description
|
||||
|
||||
|
||||
@pytest.mark.parametrize('goto_assignment', [False, True, None])
|
||||
@pytest.mark.parametrize('goto', [False, True, None])
|
||||
@pytest.mark.parametrize(
|
||||
'code, name, file_name', [
|
||||
('from pkg import Foo; Foo.foo', 'foo', '__init__.py'),
|
||||
@@ -485,15 +485,15 @@ def test_execute(Script, code, description):
|
||||
('from pkg import Foo; Foo.bar', 'bar', 'module.py'),
|
||||
('from pkg import Foo; Foo().bar', 'bar', 'module.py'),
|
||||
])
|
||||
def test_inheritance_module_path(Script, goto_assignment, code, name, file_name):
|
||||
def test_inheritance_module_path(Script, goto, code, name, file_name):
|
||||
base_path = os.path.join(get_example_dir('inheritance'), 'pkg')
|
||||
whatever_path = os.path.join(base_path, 'NOT_EXISTING.py')
|
||||
|
||||
script = Script(code, path=whatever_path)
|
||||
if goto_assignment is None:
|
||||
if goto is None:
|
||||
func, = script.infer()
|
||||
else:
|
||||
func, = script.goto_assignments(follow_imports=goto_assignment)
|
||||
func, = script.goto(follow_imports=goto)
|
||||
assert func.type == 'function'
|
||||
assert func.name == name
|
||||
assert func.module_path == os.path.join(base_path, file_name)
|
||||
|
||||
@@ -5,13 +5,13 @@ Test of keywords and ``jedi.keywords``
|
||||
import pytest
|
||||
|
||||
|
||||
def test_goto_assignments_keyword(Script):
|
||||
def test_goto_keyword(Script):
|
||||
"""
|
||||
Bug: goto assignments on ``in`` used to raise AttributeError::
|
||||
|
||||
'unicode' object has no attribute 'generate_call_path'
|
||||
"""
|
||||
Script('in').goto_assignments()
|
||||
Script('in').goto()
|
||||
|
||||
|
||||
def test_keyword(Script, environment):
|
||||
@@ -22,7 +22,7 @@ def test_keyword(Script, environment):
|
||||
else:
|
||||
assert [d.docstring() for d in defs]
|
||||
|
||||
assert Script("import").goto_assignments() == []
|
||||
assert Script("import").goto() == []
|
||||
|
||||
completions = Script("import").complete(1, 1)
|
||||
assert len(completions) > 10 and 'if' in [c.name for c in completions]
|
||||
|
||||
@@ -21,7 +21,7 @@ _tuple_code = 'from typing import Tuple\ndef f(x: Tuple[int]): ...\nf'
|
||||
]
|
||||
)
|
||||
def test_param_annotation(Script, code, expected_params, execute_annotation, skip_python2):
|
||||
func, = Script(code).goto_assignments()
|
||||
func, = Script(code).goto()
|
||||
sig, = func.get_signatures()
|
||||
for p, expected in zip(sig.params, expected_params):
|
||||
annotations = p.infer_annotation(execute_annotation=execute_annotation)
|
||||
@@ -40,7 +40,7 @@ def test_param_annotation(Script, code, expected_params, execute_annotation, ski
|
||||
]
|
||||
)
|
||||
def test_param_default(Script, code, expected_params):
|
||||
func, = Script(code).goto_assignments()
|
||||
func, = Script(code).goto()
|
||||
sig, = func.get_signatures()
|
||||
for p, expected in zip(sig.params, expected_params):
|
||||
annotations = p.infer_default()
|
||||
@@ -62,7 +62,7 @@ def test_param_default(Script, code, expected_params):
|
||||
]
|
||||
)
|
||||
def test_param_kind_and_name(code, index, param_code, kind, Script, skip_python2):
|
||||
func, = Script(code).goto_assignments()
|
||||
func, = Script(code).goto()
|
||||
sig, = func.get_signatures()
|
||||
param = sig.params[index]
|
||||
assert param.to_string() == param_code
|
||||
|
||||
Reference in New Issue
Block a user