forked from VimPlug/jedi
Use complete instead of completions in test_api/
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
def test_keyword_doc(Script):
|
||||
r = list(Script("or", 1, 1).goto_definitions())
|
||||
r = list(Script("or").infer(1, 1))
|
||||
assert len(r) == 1
|
||||
assert len(r[0].doc) > 100
|
||||
|
||||
r = list(Script("asfdasfd", 1, 1).goto_definitions())
|
||||
r = list(Script("asfdasfd").infer(1, 1))
|
||||
assert len(r) == 0
|
||||
|
||||
k = Script("fro").completions()[0]
|
||||
@@ -13,17 +13,17 @@ def test_keyword_doc(Script):
|
||||
|
||||
|
||||
def test_blablabla(Script):
|
||||
defs = Script("import").goto_definitions()
|
||||
defs = Script("import").infer()
|
||||
assert len(defs) == 1 and [1 for d in defs if d.doc]
|
||||
# unrelated to #44
|
||||
|
||||
|
||||
def test_operator_doc(Script):
|
||||
r = list(Script("a == b", 1, 3).goto_definitions())
|
||||
r = list(Script("a == b").infer(1, 3))
|
||||
assert len(r) == 1
|
||||
assert len(r[0].doc) > 100
|
||||
|
||||
|
||||
def test_lambda(Script):
|
||||
defs = Script('lambda x: x', column=0).goto_definitions()
|
||||
defs = Script('lambda x: x').infer(column=0)
|
||||
assert [d.type for d in defs] == ['keyword']
|
||||
|
||||
@@ -56,29 +56,29 @@ def test_line_number_errors(Script):
|
||||
s = 'hello'
|
||||
# lines
|
||||
with raises(ValueError):
|
||||
Script(s, 2, 0)
|
||||
Script(s).complete(2, 0)
|
||||
with raises(ValueError):
|
||||
Script(s, 0, 0)
|
||||
Script(s).complete(0, 0)
|
||||
|
||||
# columns
|
||||
with raises(ValueError):
|
||||
Script(s, 1, len(s) + 1)
|
||||
Script(s).infer(1, len(s) + 1)
|
||||
with raises(ValueError):
|
||||
Script(s, 1, -1)
|
||||
Script(s).goto(1, -1)
|
||||
|
||||
# ok
|
||||
Script(s, 1, 0)
|
||||
Script(s, 1, len(s))
|
||||
Script(s).find_signatures(1, 0)
|
||||
Script(s).find_references(1, len(s))
|
||||
|
||||
|
||||
def _check_number(Script, source, result='float'):
|
||||
completions = Script(source).completions()
|
||||
completions = Script(source).complete()
|
||||
assert completions[0].parent().name == result
|
||||
|
||||
|
||||
def test_completion_on_number_literals(Script):
|
||||
# No completions on an int literal (is a float).
|
||||
assert [c.name for c in Script('1. ').completions()] \
|
||||
assert [c.name for c in Script('1. ').complete()] \
|
||||
== ['and', 'if', 'in', 'is', 'not', 'or']
|
||||
|
||||
# Multiple points after an int literal basically mean that there's a float
|
||||
@@ -90,27 +90,27 @@ def test_completion_on_number_literals(Script):
|
||||
_check_number(Script, '1.e14.')
|
||||
_check_number(Script, '1.e-3.')
|
||||
_check_number(Script, '9e3.')
|
||||
assert Script('1.e3..').completions() == []
|
||||
assert Script('1.e-13..').completions() == []
|
||||
assert Script('1.e3..').complete() == []
|
||||
assert Script('1.e-13..').complete() == []
|
||||
|
||||
|
||||
def test_completion_on_hex_literals(Script):
|
||||
assert Script('0x1..').completions() == []
|
||||
assert Script('0x1..').complete() == []
|
||||
_check_number(Script, '0x1.', 'int') # hexdecimal
|
||||
# Completing binary literals doesn't work if they are not actually binary
|
||||
# (invalid statements).
|
||||
assert Script('0b2.b').completions() == []
|
||||
assert Script('0b2.b').complete() == []
|
||||
_check_number(Script, '0b1.', 'int') # binary
|
||||
|
||||
_check_number(Script, '0x2e.', 'int')
|
||||
_check_number(Script, '0xE7.', 'int')
|
||||
_check_number(Script, '0xEa.', 'int')
|
||||
# theoretically, but people can just check for syntax errors:
|
||||
assert Script('0x.').completions() == []
|
||||
assert Script('0x.').complete() == []
|
||||
|
||||
|
||||
def test_completion_on_complex_literals(Script):
|
||||
assert Script('1j..').completions() == []
|
||||
assert Script('1j..').complete() == []
|
||||
_check_number(Script, '1j.', 'complex')
|
||||
_check_number(Script, '44.j.', 'complex')
|
||||
_check_number(Script, '4.0j.', 'complex')
|
||||
@@ -118,8 +118,8 @@ def test_completion_on_complex_literals(Script):
|
||||
# which a keyword like or is allowed. Good times, haha!
|
||||
# However this has been disabled again, because it apparently annoyed
|
||||
# users. So no completion after j without a space :)
|
||||
assert not Script('4j').completions()
|
||||
assert ({c.name for c in Script('4j ').completions()} ==
|
||||
assert not Script('4j').complete()
|
||||
assert ({c.name for c in Script('4j ').complete()} ==
|
||||
{'if', 'and', 'in', 'is', 'not', 'or'})
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ def test_usage_description(Script):
|
||||
|
||||
def test_get_line_code(Script):
|
||||
def get_line_code(source, line=None, **kwargs):
|
||||
return Script(source, line=line).completions()[0].get_line_code(**kwargs)
|
||||
return Script(source).complete(line=line)[0].get_line_code(**kwargs)
|
||||
|
||||
# On builtin
|
||||
assert get_line_code('abs') == 'def abs(__n: SupportsAbs[_T]) -> _T: ...\n'
|
||||
@@ -191,7 +191,7 @@ def test_get_line_code(Script):
|
||||
|
||||
|
||||
def test_get_line_code_on_builtin(Script, disable_typeshed):
|
||||
abs_ = Script('abs').completions()[0]
|
||||
abs_ = Script('abs').complete()[0]
|
||||
assert abs_.name == 'abs'
|
||||
assert abs_.get_line_code() == ''
|
||||
assert abs_.line is None
|
||||
@@ -316,14 +316,14 @@ def test_goto_follow_builtin_imports(Script):
|
||||
|
||||
|
||||
def test_docstrings_for_completions(Script):
|
||||
for c in Script('').completions():
|
||||
for c in Script('').complete():
|
||||
assert isinstance(c.docstring(), (str, unicode))
|
||||
|
||||
|
||||
def test_fuzzy_completion(Script):
|
||||
script = Script('string = "hello"\nstring.upper')
|
||||
assert ['isupper',
|
||||
'upper'] == [comp.name for comp in script.completions(fuzzy=True)]
|
||||
'upper'] == [comp.name for comp in script.complete(fuzzy=True)]
|
||||
|
||||
|
||||
def test_math_fuzzy_completion(Script, environment):
|
||||
@@ -331,7 +331,7 @@ def test_math_fuzzy_completion(Script, environment):
|
||||
expected = ['copysign', 'log', 'log10', 'log1p']
|
||||
if environment.version_info.major >= 3:
|
||||
expected.append('log2')
|
||||
completions = script.completions(fuzzy=True)
|
||||
completions = script.complete(fuzzy=True)
|
||||
assert expected == [comp.name for comp in completions]
|
||||
for c in completions:
|
||||
assert c.complete is None
|
||||
@@ -341,7 +341,7 @@ def test_file_fuzzy_completion(Script):
|
||||
path = os.path.join(test_dir, 'completion')
|
||||
script = Script('"{}/ep08_i'.format(path))
|
||||
assert ['pep0484_basic.py"', 'pep0484_typing.py"'] \
|
||||
== [comp.name for comp in script.completions(fuzzy=True)]
|
||||
== [comp.name for comp in script.complete(fuzzy=True)]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -6,14 +6,14 @@ from ..helpers import cwd_at
|
||||
|
||||
def test_import_empty(Script):
|
||||
""" github #340, return the full word. """
|
||||
completion = Script("import ").completions()[0]
|
||||
completion = Script("import ").complete()[0]
|
||||
definition = completion.infer()[0]
|
||||
assert definition
|
||||
|
||||
|
||||
def check_follow_definition_types(Script, source):
|
||||
# nested import
|
||||
completions = Script(source, path='some_path.py').completions()
|
||||
completions = Script(source, path='some_path.py').complete()
|
||||
defs = chain.from_iterable(c.infer() for c in completions)
|
||||
return [d.type for d in defs]
|
||||
|
||||
@@ -27,7 +27,7 @@ def test_follow_import_incomplete(Script, environment):
|
||||
assert datetime == ['module']
|
||||
|
||||
# empty `from * import` parts
|
||||
itert = jedi.Script("from itertools import ").completions()
|
||||
itert = jedi.Script("from itertools import ").complete()
|
||||
definitions = [d for d in itert if d.name == 'chain']
|
||||
assert len(definitions) == 1
|
||||
assert [d.type for d in definitions[0].infer()] == ['class']
|
||||
|
||||
@@ -28,7 +28,7 @@ def test_valid_call(Script):
|
||||
assert_signature(Script, 'bool()', 'bool', column=5)
|
||||
|
||||
|
||||
class TestCallSignatures(TestCase):
|
||||
class TestSignatures(TestCase):
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, Script):
|
||||
self.Script = Script
|
||||
@@ -313,7 +313,7 @@ def test_signature_is_definition(Script):
|
||||
signature.line == 1
|
||||
signature.column == 6
|
||||
|
||||
# Now compare all the attributes that a CallSignature must also have.
|
||||
# Now compare all the attributes that a Signature must also have.
|
||||
for attr_name in dir(definition):
|
||||
dont_scan = ['defined_names', 'parent', 'goto_assignments', 'infer',
|
||||
'params', 'get_signatures', 'execute', 'goto']
|
||||
@@ -364,7 +364,7 @@ def test_completion_interference(Script):
|
||||
assert Script('open(').call_signatures()
|
||||
|
||||
# complete something usual, before doing the same call_signatures again.
|
||||
assert Script('from datetime import ').completions()
|
||||
assert Script('from datetime import ').complete()
|
||||
|
||||
assert Script('open(').call_signatures()
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ def test_basedefinition_type(Script, names):
|
||||
|
||||
)
|
||||
def test_basedefinition_type_import(Script, src, expected_result, column):
|
||||
types = {t.type for t in Script(src, column=column).completions()}
|
||||
types = {t.type for t in Script(src).complete(column=column)}
|
||||
assert types == {expected_result}
|
||||
|
||||
|
||||
@@ -129,10 +129,10 @@ def test_completion_docstring(Script, jedi_path):
|
||||
Jedi should follow imports in certain conditions
|
||||
"""
|
||||
def docstr(src, result):
|
||||
c = Script(src, sys_path=[jedi_path]).completions()[0]
|
||||
c = Script(src, sys_path=[jedi_path]).complete()[0]
|
||||
assert c.docstring(raw=True, fast=False) == cleandoc(result)
|
||||
|
||||
c = Script('import jedi\njed', sys_path=[jedi_path]).completions()[0]
|
||||
c = Script('import jedi\njed', sys_path=[jedi_path]).complete()[0]
|
||||
assert c.docstring(fast=False) == cleandoc(jedi_doc)
|
||||
|
||||
docstr('import jedi\njedi.Scr', cleandoc(jedi.Script.__doc__))
|
||||
@@ -174,12 +174,12 @@ def test_completion_docstring(Script, jedi_path):
|
||||
|
||||
|
||||
def test_completion_params(Script):
|
||||
c = Script('import string; string.capwords').completions()[0]
|
||||
c = Script('import string; string.capwords').complete()[0]
|
||||
assert [p.name for p in c.params] == ['s', 'sep']
|
||||
|
||||
|
||||
def test_functions_should_have_params(Script):
|
||||
for c in Script('bool.').completions():
|
||||
for c in Script('bool.').complete():
|
||||
if c.type == 'function':
|
||||
assert isinstance(c.params, list)
|
||||
|
||||
@@ -189,7 +189,7 @@ def test_hashlib_params(Script, environment):
|
||||
pytest.skip()
|
||||
|
||||
script = Script(source='from hashlib import sha256')
|
||||
c, = script.completions()
|
||||
c, = script.complete()
|
||||
assert [p.name for p in c.params] == ['arg']
|
||||
|
||||
|
||||
@@ -280,11 +280,11 @@ def test_parent_on_completion(Script):
|
||||
parent = Script(dedent('''\
|
||||
class Foo():
|
||||
def bar(): pass
|
||||
Foo().bar''')).completions()[0].parent()
|
||||
Foo().bar''')).complete()[0].parent()
|
||||
assert parent.name == 'Foo'
|
||||
assert parent.type == 'class'
|
||||
|
||||
parent = Script('str.join').completions()[0].parent()
|
||||
parent = Script('str.join').complete()[0].parent()
|
||||
assert parent.name == 'str'
|
||||
assert parent.type == 'class'
|
||||
|
||||
@@ -304,17 +304,17 @@ def test_parent_on_comprehension():
|
||||
|
||||
|
||||
def test_type(Script):
|
||||
for c in Script('a = [str()]; a[0].').completions():
|
||||
for c in Script('a = [str()]; a[0].').complete():
|
||||
if c.name == '__class__' and False: # TODO fix.
|
||||
assert c.type == 'class'
|
||||
else:
|
||||
assert c.type in ('function', 'statement')
|
||||
|
||||
for c in Script('list.').completions():
|
||||
for c in Script('list.').complete():
|
||||
assert c.type
|
||||
|
||||
# Github issue #397, type should never raise an error.
|
||||
for c in Script('import os; os.path.').completions():
|
||||
for c in Script('import os; os.path.').complete():
|
||||
assert c.type
|
||||
|
||||
|
||||
@@ -322,7 +322,7 @@ def test_type_II(Script):
|
||||
"""
|
||||
GitHub Issue #833, `keyword`s are seen as `module`s
|
||||
"""
|
||||
for c in Script('f').completions():
|
||||
for c in Script('f').complete():
|
||||
if c.name == 'for':
|
||||
assert c.type == 'keyword'
|
||||
|
||||
@@ -432,7 +432,7 @@ def test_added_equals_to_params(Script):
|
||||
def foo(bar, baz):
|
||||
pass
|
||||
""")
|
||||
results = Script(source + rest_source).completions()
|
||||
results = Script(source + rest_source).complete()
|
||||
assert len(results) == 1
|
||||
return results[0]
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ def test_in_whitespace(Script):
|
||||
code = dedent('''
|
||||
def x():
|
||||
pass''')
|
||||
assert len(Script(code, column=2).completions()) > 20
|
||||
assert len(Script(code).complete(column=2)) > 20
|
||||
|
||||
|
||||
def test_empty_init(Script):
|
||||
|
||||
@@ -103,12 +103,12 @@ def test_sub_module(Script, jedi_path):
|
||||
|
||||
|
||||
def test_os_path(Script):
|
||||
d, = Script('from os.path import join').completions()
|
||||
d, = Script('from os.path import join').complete()
|
||||
assert d.full_name == 'os.path.join'
|
||||
d, = Script('import os.p').completions()
|
||||
d, = Script('import os.p').complete()
|
||||
assert d.full_name == 'os.path'
|
||||
|
||||
|
||||
def test_os_issues(Script):
|
||||
"""Issue #873"""
|
||||
assert [c.name for c in Script('import os\nos.nt''').completions()] == ['nt']
|
||||
assert [c.name for c in Script('import os\nos.nt''').complete()] == ['nt']
|
||||
|
||||
@@ -26,7 +26,7 @@ class _GlobalNameSpace:
|
||||
|
||||
def get_completion(source, namespace):
|
||||
i = jedi.Interpreter(source, [namespace])
|
||||
completions = i.completions()
|
||||
completions = i.complete()
|
||||
assert len(completions) == 1
|
||||
return completions[0]
|
||||
|
||||
@@ -310,7 +310,7 @@ def test_param_completion():
|
||||
lambd = lambda xyz: 3
|
||||
|
||||
_assert_interpreter_complete('foo(bar', locals(), ['bar'])
|
||||
assert bool(jedi.Interpreter('lambd(xyz', [locals()]).completions()) == is_py3
|
||||
assert bool(jedi.Interpreter('lambd(xyz', [locals()]).complete()) == is_py3
|
||||
|
||||
|
||||
def test_endless_yield():
|
||||
@@ -325,7 +325,7 @@ def test_completion_params():
|
||||
foo = lambda a, b=3: None
|
||||
|
||||
script = jedi.Interpreter('foo', [locals()])
|
||||
c, = script.completions()
|
||||
c, = script.complete()
|
||||
assert [p.name for p in c.params] == ['a', 'b']
|
||||
assert c.params[0].infer() == []
|
||||
t, = c.params[1].infer()
|
||||
@@ -339,7 +339,7 @@ def test_completion_param_annotations():
|
||||
code = 'def foo(a: 1, b: str, c: int = 1.0) -> bytes: pass'
|
||||
exec_(code, locals())
|
||||
script = jedi.Interpreter('foo', [locals()])
|
||||
c, = script.completions()
|
||||
c, = script.complete()
|
||||
a, b, c = c.params
|
||||
assert a.infer() == []
|
||||
assert [d.name for d in b.infer()] == ['str']
|
||||
@@ -354,7 +354,7 @@ def test_keyword_argument():
|
||||
def f(some_keyword_argument):
|
||||
pass
|
||||
|
||||
c, = jedi.Interpreter("f(some_keyw", [{'f': f}]).completions()
|
||||
c, = jedi.Interpreter("f(some_keyw", [{'f': f}]).complete()
|
||||
assert c.name == 'some_keyword_argument'
|
||||
assert c.complete == 'ord_argument='
|
||||
|
||||
@@ -362,7 +362,7 @@ def test_keyword_argument():
|
||||
if is_py3:
|
||||
# Make it impossible for jedi to find the source of the function.
|
||||
f.__name__ = 'xSOMETHING'
|
||||
c, = jedi.Interpreter("x(some_keyw", [{'x': f}]).completions()
|
||||
c, = jedi.Interpreter("x(some_keyw", [{'x': f}]).complete()
|
||||
assert c.name == 'some_keyword_argument'
|
||||
|
||||
|
||||
@@ -376,12 +376,12 @@ def test_more_complex_instances():
|
||||
return Something()
|
||||
|
||||
#script = jedi.Interpreter('Base().wow().foo', [locals()])
|
||||
#c, = script.completions()
|
||||
#c, = script.complete()
|
||||
#assert c.name == 'foo'
|
||||
|
||||
x = Base()
|
||||
script = jedi.Interpreter('x.wow().foo', [locals()])
|
||||
c, = script.completions()
|
||||
c, = script.complete()
|
||||
assert c.name == 'foo'
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ def test_dir_magic_method(allow_unsafe_getattr):
|
||||
return ['foo', 'bar'] + names
|
||||
|
||||
itp = jedi.Interpreter("ca.", [{'ca': CompleteAttrs()}])
|
||||
completions = itp.completions()
|
||||
completions = itp.complete()
|
||||
names = [c.name for c in completions]
|
||||
assert ('__dir__' in names) == is_py3
|
||||
assert '__class__' in names
|
||||
@@ -447,7 +447,7 @@ def test_name_not_findable():
|
||||
|
||||
setattr(X, 'NOT_FINDABLE', X.hidden)
|
||||
|
||||
assert jedi.Interpreter("X.NOT_FINDA", [locals()]).completions()
|
||||
assert jedi.Interpreter("X.NOT_FINDA", [locals()]).complete()
|
||||
|
||||
|
||||
def test_stubs_working():
|
||||
@@ -458,8 +458,8 @@ def test_stubs_working():
|
||||
|
||||
def test_sys_path_docstring(): # Was an issue in #1298
|
||||
import jedi
|
||||
s = jedi.Interpreter("from sys import path\npath", line=2, column=4, namespaces=[locals()])
|
||||
s.completions()[0].docstring()
|
||||
s = jedi.Interpreter("from sys import path\npath", namespaces=[locals()])
|
||||
s.complete(line=2, column=4)[0].docstring()
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL")
|
||||
@@ -504,7 +504,7 @@ def test_simple_completions(code, completions):
|
||||
counter = collections.Counter(['asdf'])
|
||||
string = ''
|
||||
|
||||
defs = jedi.Interpreter(code, [locals()]).completions()
|
||||
defs = jedi.Interpreter(code, [locals()]).complete()
|
||||
assert [d.name for d in defs] == completions
|
||||
|
||||
|
||||
@@ -516,7 +516,7 @@ def test__wrapped__():
|
||||
def syslogs_to_df():
|
||||
pass
|
||||
|
||||
c, = jedi.Interpreter('syslogs_to_df', [locals()]).completions()
|
||||
c, = jedi.Interpreter('syslogs_to_df', [locals()]).complete()
|
||||
# Apparently the function starts on the line where the decorator starts.
|
||||
assert c.line == syslogs_to_df.__wrapped__.__code__.co_firstlineno + 1
|
||||
|
||||
@@ -525,7 +525,7 @@ def test__wrapped__():
|
||||
@pytest.mark.parametrize('module_name', ['sys', 'time', 'unittest.mock'])
|
||||
def test_core_module_completes(module_name):
|
||||
module = import_module(module_name)
|
||||
assert jedi.Interpreter('module.', [locals()]).completions()
|
||||
assert jedi.Interpreter('module.', [locals()]).complete()
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL")
|
||||
@@ -573,5 +573,5 @@ def test_param_annotation_completion(class_is_findable):
|
||||
Foo.__name__ = 'asdf'
|
||||
|
||||
code = 'def CallFoo(x: Foo):\n x.ba'
|
||||
def_, = jedi.Interpreter(code, [locals()]).completions()
|
||||
def_, = jedi.Interpreter(code, [locals()]).complete()
|
||||
assert def_.name == 'bar'
|
||||
|
||||
@@ -24,13 +24,13 @@ def test_keyword(Script, environment):
|
||||
|
||||
assert Script("import").goto_assignments() == []
|
||||
|
||||
completions = Script("import", 1, 1).completions()
|
||||
completions = Script("import").complete(1, 1)
|
||||
assert len(completions) > 10 and 'if' in [c.name for c in completions]
|
||||
assert Script("assert").goto_definitions() == []
|
||||
|
||||
|
||||
def test_keyword_attributes(Script):
|
||||
def_, = Script('def').completions()
|
||||
def_, = Script('def').complete()
|
||||
assert def_.name == 'def'
|
||||
assert def_.complete == ''
|
||||
assert def_.is_keyword is True
|
||||
@@ -55,6 +55,6 @@ def test_none_keyword(Script, environment):
|
||||
# Just don't care about Python 2 anymore, it's almost gone.
|
||||
pytest.skip()
|
||||
|
||||
none, = Script('None').completions()
|
||||
none, = Script('None').complete()
|
||||
assert not none.docstring()
|
||||
assert none.name == 'None'
|
||||
|
||||
@@ -11,7 +11,7 @@ def test_django_default_project(Script):
|
||||
"from app import models\nmodels.SomeMo",
|
||||
path=os.path.join(dir, 'models/x.py')
|
||||
)
|
||||
c, = script.completions()
|
||||
c, = script.complete()
|
||||
assert c.name == "SomeModel"
|
||||
assert script._inference_state.project._django is True
|
||||
|
||||
|
||||
@@ -30,5 +30,5 @@ def test_add_bracket_after_function(monkeypatch, Script):
|
||||
def foo():
|
||||
pass
|
||||
foo''')
|
||||
completions = script.completions()
|
||||
completions = script.complete()
|
||||
assert completions[0].complete == '('
|
||||
|
||||
Reference in New Issue
Block a user