From 2cc898ba3546f41d8aea9bfc627e64a8cb82f0c5 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 20 Dec 2019 16:29:43 +0100 Subject: [PATCH] Get rid of completions in tests --- jedi/api/__init__.py | 2 +- jedi/api/completion.py | 2 +- jedi/api/file_name.py | 2 +- test/blabla_test_documentation.py | 2 +- test/completion/thirdparty/jedi_.py | 2 +- test/test_api/test_completion.py | 46 ++++++------ test/test_api/test_full_name.py | 4 +- test/test_api/test_interpreter.py | 2 +- test/test_api/test_unicode.py | 18 ++--- test/test_inference/test_absolute_import.py | 2 +- test/test_inference/test_compiled.py | 4 +- test/test_inference/test_context.py | 2 +- test/test_inference/test_docstring.py | 36 +++++----- test/test_inference/test_extension.py | 6 +- test/test_inference/test_fstring.py | 2 +- .../test_gradual/test_typeshed.py | 2 +- .../test_implicit_namespace_package.py | 10 +-- test/test_inference/test_imports.py | 70 +++++++++---------- test/test_inference/test_mixed.py | 2 +- test/test_inference/test_namespace_package.py | 4 +- test/test_inference/test_pyc.py | 2 +- test/test_inference/test_stdlib.py | 6 +- test/test_parso_integration/test_basic.py | 4 +- .../test_error_correction.py | 10 +-- test/test_settings.py | 4 +- test/test_speed.py | 4 +- test/test_utils.py | 38 +++++----- 27 files changed, 144 insertions(+), 144 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 56e83a59..698c194d 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -202,7 +202,7 @@ class Script(object): with debug.increase_indent_cm('completions'): completion = Completion( self._inference_state, self._get_module_context(), self._code_lines, - (line, column), self.call_signatures + (line, column), self.find_signatures ) return completion.completions(fuzzy) diff --git a/jedi/api/completion.py b/jedi/api/completion.py index 62e52ff1..8d87537e 100644 --- a/jedi/api/completion.py +++ b/jedi/api/completion.py @@ -229,7 +229,7 @@ class Completion: # 3. Decorators are very primitive and have an optional `(` with # optional arglist in them. if nodes[-1] in ['(', ','] and nonterminals[-1] in ('trailer', 'arglist', 'decorator'): - call_signatures = self._call_signatures_callback() + call_signatures = self._call_signatures_callback(*self._position) completion_names += get_call_signature_param_names(call_signatures) return completion_names diff --git a/jedi/api/file_name.py b/jedi/api/file_name.py index 1747c803..e32a87df 100644 --- a/jedi/api/file_name.py +++ b/jedi/api/file_name.py @@ -23,7 +23,7 @@ def file_name_completions(inference_state, module_context, start_leaf, string, must_start_with = os.path.basename(string) + like_name string = os.path.dirname(string) - sigs = call_signatures_callback() + sigs = call_signatures_callback(*position) is_in_os_path_join = sigs and all(s.full_name == 'os.path.join' for s in sigs) if is_in_os_path_join: to_be_added = _add_os_path_join(module_context, start_leaf, sigs[0].bracket_start) diff --git a/test/blabla_test_documentation.py b/test/blabla_test_documentation.py index 90fd04a3..c0625339 100644 --- a/test/blabla_test_documentation.py +++ b/test/blabla_test_documentation.py @@ -6,7 +6,7 @@ def test_keyword_doc(Script): r = list(Script("asfdasfd").infer(1, 1)) assert len(r) == 0 - k = Script("fro").completions()[0] + k = Script("fro").complete()[0] imp_start = '\nThe ``import' assert k.raw_doc.startswith(imp_start) assert k.doc.startswith(imp_start) diff --git a/test/completion/thirdparty/jedi_.py b/test/completion/thirdparty/jedi_.py index 59f21f75..f588f740 100644 --- a/test/completion/thirdparty/jedi_.py +++ b/test/completion/thirdparty/jedi_.py @@ -1,7 +1,7 @@ from jedi import functions, inference, parsing -el = functions.completions()[0] +el = functions.complete()[0] #? ['description'] el.description diff --git a/test/test_api/test_completion.py b/test/test_api/test_completion.py index 45c676af..039b28cd 100644 --- a/test/test_api/test_completion.py +++ b/test/test_api/test_completion.py @@ -4,7 +4,9 @@ import sys from textwrap import dedent import pytest + from ..helpers import root_dir +from jedi.api.helpers import start_match, fuzzy_match def test_in_whitespace(Script): @@ -19,7 +21,7 @@ def test_empty_init(Script): code = dedent('''\ class X(object): pass X(''') - assert Script(code).completions() + assert Script(code).complete() def test_in_empty_space(Script): @@ -28,7 +30,7 @@ def test_in_empty_space(Script): def __init__(self): hello ''') - comps = Script(code, 3, 7).completions() + comps = Script(code).complete(3, 7) self, = [c for c in comps if c.name == 'self'] assert self.name == 'self' def_, = self.infer() @@ -41,13 +43,13 @@ def test_indent_value(Script): complete. """ code = 'if 1:\nisinstanc' - comp, = Script(code).completions() + comp, = Script(code).complete() assert comp.name == 'isinstance' def test_keyword_value(Script): def get_names(*args, **kwargs): - return [d.name for d in Script(*args, **kwargs).completions()] + return [d.name for d in Script(*args, **kwargs).complete()] names = get_names('if 1:\n pass\n') assert 'if' in names @@ -56,7 +58,7 @@ def test_keyword_value(Script): def test_os_nowait(Script): """ github issue #45 """ - s = Script("import os; os.P_").completions() + s = Script("import os; os.P_").complete() assert 'P_NOWAIT' in [i.name for i in s] @@ -64,7 +66,7 @@ def test_points_in_completion(Script): """At some point, points were inserted into the completions, this caused problems, sometimes. """ - c = Script("if IndentationErr").completions() + c = Script("if IndentationErr").complete() assert c[0].name == 'IndentationError' assert c[0].complete == 'or' @@ -80,9 +82,8 @@ def test_loading_unicode_files_with_bad_global_charset(Script, monkeypatch, tmpd with open(filename1, "wb") as f: f.write(data) - s = Script("from test1 import foo\nfoo.", - line=2, column=4, path=filename2) - s.completions() + s = Script("from test1 import foo\nfoo.", path=filename2) + s.complete(line=2, column=4) def test_fake_subnodes(Script): @@ -100,7 +101,7 @@ def test_fake_subnodes(Script): return c limit = None for i in range(2): - completions = Script('').completions() + completions = Script('').complete() c = get_str_completion(completions) str_value, = c._name.infer() n = len(str_value.tree_node.children[-1].children) @@ -116,17 +117,17 @@ def test_generator(Script): s = "def abc():\n" \ " yield 1\n" \ "abc()." - assert Script(s).completions() + assert Script(s).complete() def test_in_comment(Script): - assert Script(" # Comment").completions() + assert Script(" # Comment").complete() # TODO this is a bit ugly, that the behaviors in comments are different. - assert not Script("max_attr_value = int(2) # Cast to int for spe").completions() + assert not Script("max_attr_value = int(2) # Cast to int for spe").complete() def test_in_comment_before_string(Script): - assert not Script(" # Foo\n'asdf'", line=1).completions() + assert not Script(" # Foo\n'asdf'").complete(line=1) def test_async(Script, environment): @@ -137,16 +138,15 @@ def test_async(Script, environment): foo = 3 async def x(): hey = 3 - ho''' - ) - comps = Script(code, column=4).completions() + ho''') + comps = Script(code).complete(column=4) names = [c.name for c in comps] assert 'foo' in names assert 'hey' in names def test_with_stmt_error_recovery(Script): - assert Script('with open('') as foo: foo.\na', line=1).completions() + assert Script('with open('') as foo: foo.\na').complete(line=1) @pytest.mark.parametrize( @@ -161,7 +161,7 @@ def test_with_stmt_error_recovery(Script): ) ) def test_keyword_completion(Script, code, has_keywords): - assert has_keywords == any(x.is_keyword for x in Script(code).completions()) + assert has_keywords == any(x.is_keyword for x in Script(code).complete()) f1 = join(root_dir, 'example.py') @@ -187,7 +187,7 @@ current_dirname = os.path.basename(dirname(dirname(dirname(__file__)))) ('test%sexample.py' % se, 'r"test%scomp"' % s, 5, ['t' + s]), ('test%sexample.py' % se, 'r"test%scomp"' % s, 11, ['letion' + s]), ('test%sexample.py' % se, '"%s"' % join('test', 'completion', 'basi'), 21, ['c.py']), - ('example.py', 'rb"'+ join('..', current_dirname, 'tes'), None, ['t' + s]), + ('example.py', 'rb"' + join('..', current_dirname, 'tes'), None, ['t' + s]), # Absolute paths (None, '"' + join(root_dir, 'test', 'test_ca'), None, ['che.py"']), @@ -266,17 +266,17 @@ def test_file_path_completions(Script, file, code, column, expected): line = None if isinstance(column, tuple): line, column = column - comps = Script(code, path=file, line=line, column=column).completions() + comps = Script(code, path=file).complete(line=line, column=column) if expected == "A LOT": assert len(comps) > 100 # This is basically global completions. else: assert [c.complete for c in comps] == expected -from jedi.api.helpers import start_match, fuzzy_match def test_start_match(): assert start_match('Condition', 'C') - + + def test_fuzzy_match(): assert fuzzy_match('Condition', 'i') assert not fuzzy_match('Condition', 'p') diff --git a/test/test_api/test_full_name.py b/test/test_api/test_full_name.py index 0bf3703a..e63b6d8d 100644 --- a/test/test_api/test_full_name.py +++ b/test/test_api/test_full_name.py @@ -31,7 +31,7 @@ class MixinTestFullName(object): def check(self, source, desired): script = self.Script(textwrap.dedent(source)) - definitions = getattr(script, type(self).operation)() + definitions = getattr(script, self.operation)() for d in definitions: self.assertEqual(d.full_name, desired) @@ -59,7 +59,7 @@ class TestFullNameWithGotoDefinitions(MixinTestFullName, TestCase): class TestFullNameWithCompletions(MixinTestFullName, TestCase): - operation = 'completions' + operation = 'complete' class TestFullDefinedName(TestCase): diff --git a/test/test_api/test_interpreter.py b/test/test_api/test_interpreter.py index b6e6bdeb..3a6ec869 100644 --- a/test/test_api/test_interpreter.py +++ b/test/test_api/test_interpreter.py @@ -111,7 +111,7 @@ def test_side_effect_completion(): def _assert_interpreter_complete(source, namespace, completions, **kwds): script = jedi.Interpreter(source, [namespace], **kwds) - cs = script.completions() + cs = script.complete() actual = [c.name for c in cs] assert sorted(actual) == sorted(completions) diff --git a/test/test_api/test_unicode.py b/test/test_api/test_unicode.py index 7fd28bb2..76b0f87e 100644 --- a/test/test_api/test_unicode.py +++ b/test/test_api/test_unicode.py @@ -8,18 +8,18 @@ from jedi._compatibility import u, unicode def test_unicode_script(Script): """ normally no unicode objects are being used. (<=2.7) """ s = unicode("import datetime; datetime.timedelta") - completions = Script(s).completions() + completions = Script(s).complete() assert len(completions) assert type(completions[0].description) is unicode s = u("author='öä'; author") - completions = Script(s).completions() + completions = Script(s).complete() x = completions[0].description assert type(x) is unicode s = u("#-*- coding: iso-8859-1 -*-\nauthor='öä'; author") s = s.encode('latin-1') - completions = Script(s).completions() + completions = Script(s).complete() assert type(completions[0].description) is unicode @@ -27,11 +27,11 @@ def test_unicode_attribute(Script): """ github jedi-vim issue #94 """ s1 = u('#-*- coding: utf-8 -*-\nclass Person():\n' ' name = "e"\n\nPerson().name.') - completions1 = Script(s1).completions() + completions1 = Script(s1).complete() assert 'strip' in [c.name for c in completions1] s2 = u('#-*- coding: utf-8 -*-\nclass Person():\n' ' name = "é"\n\nPerson().name.') - completions2 = Script(s2).completions() + completions2 = Script(s2).complete() assert 'strip' in [c.name for c in completions2] @@ -44,7 +44,7 @@ def test_multibyte_script(Script): except NameError: pass # python 3 has no unicode method else: - assert len(Script(s, 1, len(code)).completions()) + assert len(Script(s).complete(1, len(code))) def test_goto_definition_at_zero(Script): @@ -57,11 +57,11 @@ def test_goto_definition_at_zero(Script): def test_complete_at_zero(Script): - s = Script("str", 1, 3).completions() + s = Script("str").complete(1, 3) assert len(s) == 1 assert list(s)[0].name == 'str' - s = Script("", 1, 0).completions() + s = Script("").complete(1, 0) assert len(s) > 0 @@ -70,7 +70,7 @@ def test_wrong_encoding(Script, tmpdir): # Use both latin-1 and utf-8 (a really broken file). x.write_binary(u'foobar = 1\nä'.encode('latin-1') + u'ä'.encode('utf-8')) - c, = Script('import x; x.foo', sys_path=[tmpdir.strpath]).completions() + c, = Script('import x; x.foo', sys_path=[tmpdir.strpath]).complete() assert c.name == 'foobar' diff --git a/test/test_inference/test_absolute_import.py b/test/test_inference/test_absolute_import.py index 1052aa5d..9d3e518d 100644 --- a/test/test_inference/test_absolute_import.py +++ b/test/test_inference/test_absolute_import.py @@ -8,4 +8,4 @@ from .. import helpers @helpers.cwd_at("test/test_inference/absolute_import") def test_can_complete_when_shadowing(Script): script = Script(path="unittest.py") - assert script.completions() + assert script.complete() diff --git a/test/test_inference/test_compiled.py b/test/test_inference/test_compiled.py index e6e6991b..af1755f6 100644 --- a/test/test_inference/test_compiled.py +++ b/test/test_inference/test_compiled.py @@ -83,12 +83,12 @@ def test_method_completion(Script, environment): foo = Foo() foo.bar.__func__''') - assert [c.name for c in Script(code).completions()] == ['__func__'] + assert [c.name for c in Script(code).complete()] == ['__func__'] def test_time_docstring(Script): import time - comp, = Script('import time\ntime.sleep').completions() + comp, = Script('import time\ntime.sleep').complete() assert comp.docstring(raw=True) == time.sleep.__doc__ expected = 'sleep(secs: float) -> None\n\n' + time.sleep.__doc__ assert comp.docstring() == expected diff --git a/test/test_inference/test_context.py b/test/test_inference/test_context.py index 7a64014b..a365e1ce 100644 --- a/test/test_inference/test_context.py +++ b/test/test_inference/test_context.py @@ -2,7 +2,7 @@ from jedi._compatibility import force_unicode def test_module_attributes(Script): - def_, = Script('__name__').completions() + def_, = Script('__name__').complete() assert def_.name == '__name__' assert def_.line is None assert def_.column is None diff --git a/test/test_inference/test_docstring.py b/test/test_inference/test_docstring.py index a0ec9b7a..ccb081cc 100644 --- a/test/test_inference/test_docstring.py +++ b/test/test_inference/test_docstring.py @@ -91,7 +91,7 @@ def test_completion(Script): assert Script(''' class DocstringCompletion(): #? [] - """ asdfas """''').completions() + """ asdfas """''').complete() def test_docstrings_type_dotted_import(Script): @@ -101,7 +101,7 @@ def test_docstrings_type_dotted_import(Script): :type arg: random.Random ''' arg.""" - names = [c.name for c in Script(s).completions()] + names = [c.name for c in Script(s).complete()] assert 'seed' in names @@ -112,7 +112,7 @@ def test_docstrings_param_type(Script): :param str arg: some description ''' arg.""" - names = [c.name for c in Script(s).completions()] + names = [c.name for c in Script(s).complete()] assert 'join' in names @@ -124,7 +124,7 @@ def test_docstrings_type_str(Script): ''' arg.""" - names = [c.name for c in Script(s).completions()] + names = [c.name for c in Script(s).complete()] assert 'join' in names @@ -150,14 +150,14 @@ def test_docstring_instance(Script): c.""") - names = [c.name for c in Script(s).completions()] + names = [c.name for c in Script(s).complete()] assert 'a' in names assert '__init__' in names assert 'mro' not in names # Exists only for types. def test_docstring_keyword(Script): - completions = Script('assert').completions() + completions = Script('assert').complete() assert 'assert' in completions[0].docstring() @@ -185,7 +185,7 @@ def test_numpydoc_parameters(): y : str """ y.''') - names = [c.name for c in jedi.Script(s).completions()] + names = [c.name for c in jedi.Script(s).complete()] assert 'isupper' in names assert 'capitalize' in names @@ -201,7 +201,7 @@ def test_numpydoc_parameters_set_of_values(): x : {'foo', 'bar', 100500}, optional """ x.''') - names = [c.name for c in jedi.Script(s).completions()] + names = [c.name for c in jedi.Script(s).complete()] assert 'isupper' in names assert 'capitalize' in names assert 'numerator' in names @@ -218,7 +218,7 @@ def test_numpydoc_parameters_alternative_types(): x : int or str or list """ x.''') - names = [c.name for c in jedi.Script(s).completions()] + names = [c.name for c in jedi.Script(s).complete()] assert 'isupper' in names assert 'capitalize' in names assert 'numerator' in names @@ -237,7 +237,7 @@ def test_numpydoc_invalid(): """ x.''') - assert not jedi.Script(s).completions() + assert not jedi.Script(s).complete() @pytest.mark.skipif(numpydoc_unavailable, @@ -256,7 +256,7 @@ def test_numpydoc_returns(): def bazbiz(): z = foobar() z.''') - names = [c.name for c in jedi.Script(s).completions()] + names = [c.name for c in jedi.Script(s).complete()] assert 'isupper' in names assert 'capitalize' in names assert 'numerator' in names @@ -277,7 +277,7 @@ def test_numpydoc_returns_set_of_values(): def bazbiz(): z = foobar() z.''') - names = [c.name for c in jedi.Script(s).completions()] + names = [c.name for c in jedi.Script(s).complete()] assert 'isupper' in names assert 'capitalize' in names assert 'numerator' in names @@ -298,7 +298,7 @@ def test_numpydoc_returns_alternative_types(): def bazbiz(): z = foobar() z.''') - names = [c.name for c in jedi.Script(s).completions()] + names = [c.name for c in jedi.Script(s).complete()] assert 'isupper' not in names assert 'capitalize' not in names assert 'numerator' in names @@ -320,7 +320,7 @@ def test_numpydoc_returns_list_of(): def bazbiz(): z = foobar() z.''') - names = [c.name for c in jedi.Script(s).completions()] + names = [c.name for c in jedi.Script(s).complete()] assert 'append' in names assert 'isupper' not in names assert 'capitalize' not in names @@ -342,7 +342,7 @@ def test_numpydoc_returns_obj(): z = foobar(x, y) z.''') script = jedi.Script(s) - names = [c.name for c in script.completions()] + names = [c.name for c in script.complete()] assert 'numerator' in names assert 'seed' in names @@ -363,7 +363,7 @@ def test_numpydoc_yields(): def bazbiz(): z = foobar(): z.''') - names = [c.name for c in jedi.Script(s).completions()] + names = [c.name for c in jedi.Script(s).complete()] assert 'isupper' in names assert 'capitalize' in names assert 'numerator' in names @@ -377,7 +377,7 @@ def test_numpy_returns(): x = numpy.asarray([]) x.d''' ) - names = [c.name for c in jedi.Script(s).completions()] + names = [c.name for c in jedi.Script(s).complete()] assert 'diagonal' in names @@ -389,7 +389,7 @@ def test_numpy_comp_returns(): x = numpy.array([]) x.d''' ) - names = [c.name for c in jedi.Script(s).completions()] + names = [c.name for c in jedi.Script(s).complete()] assert 'diagonal' in names diff --git a/test/test_inference/test_extension.py b/test/test_inference/test_extension.py index fb7801a3..06b1ccfe 100644 --- a/test/test_inference/test_extension.py +++ b/test/test_inference/test_extension.py @@ -10,7 +10,7 @@ import pytest def test_completions(Script): s = Script('import _ctypes; _ctypes.') - assert len(s.completions()) >= 15 + assert len(s.complete()) >= 15 def test_call_signatures_extension(Script): @@ -51,7 +51,7 @@ def test_init_extension_module(Script): This is also why this test only runs on certain systems (and Python 3.4). """ s = jedi.Script('import init_extension_module as i\ni.', path='not_existing.py') - assert 'foo' in [c.name for c in s.completions()] + assert 'foo' in [c.name for c in s.complete()] s = jedi.Script('from init_extension_module import foo\nfoo', path='not_existing.py') - assert ['foo'] == [c.name for c in s.completions()] + assert ['foo'] == [c.name for c in s.complete()] diff --git a/test/test_inference/test_fstring.py b/test/test_inference/test_fstring.py index 2805e44b..2c755368 100644 --- a/test/test_inference/test_fstring.py +++ b/test/test_inference/test_fstring.py @@ -15,5 +15,5 @@ def test_fstring_multiline(Script): ''' """ ) - c, = Script(code, line=2, column=9).completions() + c, = Script(code).complete(line=2, column=9) assert c.name == 'upper' diff --git a/test/test_inference/test_gradual/test_typeshed.py b/test/test_inference/test_gradual/test_typeshed.py index a6f0060f..1228d185 100644 --- a/test/test_inference/test_gradual/test_typeshed.py +++ b/test/test_inference/test_gradual/test_typeshed.py @@ -124,7 +124,7 @@ def test_sys_getwindowsversion(Script, environment): def test_sys_hexversion(Script): script = Script('import sys; sys.hexversion') - def_, = script.completions() + def_, = script.complete() assert isinstance(def_._name, stub_value._StubName), def_._name assert typeshed.TYPESHED_PATH in def_.module_path def_, = script.goto_definitions() diff --git a/test/test_inference/test_implicit_namespace_package.py b/test/test_inference/test_implicit_namespace_package.py index 9dd5044f..0dec9f0c 100644 --- a/test/test_inference/test_implicit_namespace_package.py +++ b/test/test_inference/test_implicit_namespace_package.py @@ -32,7 +32,7 @@ def test_implicit_namespace_package(Script): assert ass[0].description == "foo = '%s'" % solution # completion - completions = script_with_path('from pkg import ').completions() + completions = script_with_path('from pkg import ').complete() names = [c.name for c in completions] compare = ['ns1_file', 'ns2_file'] # must at least contain these items, other items are not important @@ -43,7 +43,7 @@ def test_implicit_namespace_package(Script): 'from pkg import ns1_file as x': 'ns1_file!' } for source, solution in tests.items(): - for c in script_with_path(source + '; x.').completions(): + for c in script_with_path(source + '; x.').complete(): if c.name == 'foo': completion = c solution = "foo = '%s'" % solution @@ -72,7 +72,7 @@ def test_implicit_namespace_package_import_autocomplete(Script): sys_path = [dirname(__file__)] script = Script(sys_path=sys_path, source=CODE) - compl = script.completions() + compl = script.complete() assert [c.name for c in compl] == ['implicit_namespace_package'] @@ -82,7 +82,7 @@ def test_namespace_package_in_multiple_directories_autocompletion(Script): for d in ['implicit_namespace_package/ns1', 'implicit_namespace_package/ns2']] script = Script(sys_path=sys_path, source=CODE) - compl = script.completions() + compl = script.complete() assert set(c.name for c in compl) == set(['ns1_file', 'ns2_file']) @@ -101,5 +101,5 @@ def test_namespace_name_autocompletion_full_name(Script): for d in ['implicit_namespace_package/ns1', 'implicit_namespace_package/ns2']] script = Script(sys_path=sys_path, source=CODE) - compl = script.completions() + compl = script.complete() assert set(c.full_name for c in compl) == set(['pkg']) diff --git a/test/test_inference/test_imports.py b/test/test_inference/test_imports.py index 17c5a578..165dd9b8 100644 --- a/test/test_inference/test_imports.py +++ b/test/test_inference/test_imports.py @@ -46,7 +46,7 @@ pkg_zip_path = os.path.join(os.path.dirname(__file__), def test_find_module_package_zipped(Script, inference_state, environment): sys_path = environment.get_sys_path() + [pkg_zip_path] script = Script('import pkg; pkg.mod', sys_path=sys_path) - assert len(script.completions()) == 1 + assert len(script.complete()) == 1 file_io, is_package = inference_state.compiled_subprocess.get_module_info( sys_path=sys_path, @@ -100,7 +100,7 @@ def test_find_module_not_package_zipped(Script, inference_state, environment): path = os.path.join(os.path.dirname(__file__), 'zipped_imports/not_pkg.zip') sys_path = environment.get_sys_path() + [path] script = Script('import not_pkg; not_pkg.val', sys_path=sys_path) - assert len(script.completions()) == 1 + assert len(script.complete()) == 1 file_io, is_package = inference_state.compiled_subprocess.get_module_info( sys_path=sys_path, @@ -145,14 +145,14 @@ def test_flask_ext(Script, code, name): """flask.ext.foo is really imported from flaskext.foo or flask_foo. """ path = os.path.join(os.path.dirname(__file__), 'flask-site-packages') - completions = Script(code, sys_path=[path]).completions() + completions = Script(code, sys_path=[path]).complete() assert name in [c.name for c in completions] @cwd_at('test/test_inference/') def test_not_importable_file(Script): src = 'import not_importable_file as x; x.' - assert not Script(src, path='example.py').completions() + assert not Script(src, path='example.py').complete() def test_import_unique(Script): @@ -168,9 +168,9 @@ def test_cache_works_with_sys_path_param(Script, tmpdir): foo_path.join('module.py').write('foo = 123', ensure=True) bar_path.join('module.py').write('bar = 123', ensure=True) foo_completions = Script('import module; module.', - sys_path=[foo_path.strpath]).completions() + sys_path=[foo_path.strpath]).complete() bar_completions = Script('import module; module.', - sys_path=[bar_path.strpath]).completions() + sys_path=[bar_path.strpath]).complete() assert 'foo' in [c.name for c in foo_completions] assert 'bar' not in [c.name for c in foo_completions] @@ -181,7 +181,7 @@ def test_cache_works_with_sys_path_param(Script, tmpdir): def test_import_completion_docstring(Script): import abc s = Script('"""test"""\nimport ab') - abc_completions = [c for c in s.completions() if c.name == 'abc'] + abc_completions = [c for c in s.complete() if c.name == 'abc'] assert len(abc_completions) == 1 assert abc_completions[0].docstring(fast=False) == abc.__doc__ @@ -197,40 +197,40 @@ def test_goto_definition_on_import(Script): @cwd_at('jedi') def test_complete_on_empty_import(Script): - assert Script("from datetime import").completions()[0].name == 'import' + assert Script("from datetime import").complete()[0].name == 'import' # should just list the files in the directory - assert 10 < len(Script("from .", path='whatever.py').completions()) < 30 + assert 10 < len(Script("from .", path='whatever.py').complete()) < 30 # Global import - assert len(Script("from . import", 1, 5, 'whatever.py').completions()) > 30 + assert len(Script("from . import", 'whatever.py').complete(1, 5)) > 30 # relative import - assert 10 < len(Script("from . import", 1, 6, 'whatever.py').completions()) < 30 + assert 10 < len(Script("from . import", 'whatever.py').complete(1, 6)) < 30 # Global import - assert len(Script("from . import classes", 1, 5, 'whatever.py').completions()) > 30 + assert len(Script("from . import classes", 'whatever.py').complete(1, 5)) > 30 # relative import - assert 10 < len(Script("from . import classes", 1, 6, 'whatever.py').completions()) < 30 + assert 10 < len(Script("from . import classes", 'whatever.py').complete(1, 6)) < 30 wanted = {'ImportError', 'import', 'ImportWarning'} - assert {c.name for c in Script("import").completions()} == wanted - assert len(Script("import import", path='').completions()) > 0 + assert {c.name for c in Script("import").complete()} == wanted + assert len(Script("import import", path='').complete()) > 0 # 111 - assert Script("from datetime import").completions()[0].name == 'import' - assert Script("from datetime import ").completions() + assert Script("from datetime import").complete()[0].name == 'import' + assert Script("from datetime import ").complete() def test_imports_on_global_namespace_without_path(Script): """If the path is None, there shouldn't be any import problem""" - completions = Script("import operator").completions() + completions = Script("import operator").complete() assert [c.name for c in completions] == ['operator'] - completions = Script("import operator", path='example.py').completions() + completions = Script("import operator", path='example.py').complete() assert [c.name for c in completions] == ['operator'] # the first one has a path the second doesn't - completions = Script("import keyword", path='example.py').completions() + completions = Script("import keyword", path='example.py').complete() assert [c.name for c in completions] == ['keyword'] - completions = Script("import keyword").completions() + completions = Script("import keyword").complete() assert [c.name for c in completions] == ['keyword'] @@ -256,7 +256,7 @@ def test_goto_assignments(Script): def test_os_after_from(Script): def check(source, result, column=None): - completions = Script(source, column=column).completions() + completions = Script(source).complete(column=column) assert [c.name for c in completions] == result check('\nfrom os. ', ['path']) @@ -270,7 +270,7 @@ def test_os_after_from(Script): def test_os_issues(Script): def import_names(*args, **kwargs): - return [d.name for d in Script(*args, **kwargs).completions()] + return [d.name for d in Script(*args).complete(**kwargs)] # Github issue #759 s = 'import os, s' @@ -291,7 +291,7 @@ def test_path_issues(Script): See pull request #684 for details. """ source = '''from datetime import ''' - assert Script(source).completions() + assert Script(source).complete() def test_compiled_import_none(monkeypatch, Script): @@ -361,7 +361,7 @@ def test_relative_imports_with_multiple_similar_directories(Script, path, empty_ path=os.path.join(dir, path), _project=project, ) - name, import_ = script.completions() + name, import_ = script.complete() assert import_.name == 'import' assert name.name == 'api_test1' @@ -374,37 +374,37 @@ def test_relative_imports_with_outside_paths(Script): path=os.path.join(dir, 'api/whatever/test_this.py'), _project=project, ) - assert [c.name for c in script.completions()] == ['api', 'import', 'whatever'] + assert [c.name for c in script.complete()] == ['api', 'import', 'whatever'] script = Script( "from " + '.' * 100, path=os.path.join(dir, 'api/whatever/test_this.py'), _project=project, ) - assert [c.name for c in script.completions()] == ['import'] + assert [c.name for c in script.complete()] == ['import'] @cwd_at('test/examples/issue1209/api/whatever/') def test_relative_imports_without_path(Script): project = Project('.', sys_path=[], smart_sys_path=False) script = Script("from . ", _project=project) - assert [c.name for c in script.completions()] == ['api_test1', 'import'] + assert [c.name for c in script.complete()] == ['api_test1', 'import'] script = Script("from .. ", _project=project) - assert [c.name for c in script.completions()] == ['import', 'whatever'] + assert [c.name for c in script.complete()] == ['import', 'whatever'] script = Script("from ... ", _project=project) - assert [c.name for c in script.completions()] == ['api', 'import', 'whatever'] + assert [c.name for c in script.complete()] == ['api', 'import', 'whatever'] def test_relative_import_out_of_file_system(Script): script = Script("from " + '.' * 100) - import_, = script.completions() + import_, = script.complete() assert import_.name == 'import' script = Script("from " + '.' * 100 + 'abc import ABCMeta') assert not script.goto_definitions() - assert not script.completions() + assert not script.complete() @pytest.mark.parametrize( @@ -462,7 +462,7 @@ def test_import_needed_modules_by_jedi(Script, environment, tmpdir, name): def test_import_with_semicolon(Script): - names = [c.name for c in Script('xzy; from abc import ').completions()] + names = [c.name for c in Script('xzy; from abc import ').complete()] assert 'ABCMeta' in names assert 'abc' not in names @@ -475,6 +475,6 @@ def test_relative_import_star(Script): from . import * furl.c """ - script = jedi.Script(source, 3, len("furl.c"), 'export.py') + script = jedi.Script(source, 'export.py') - assert script.completions() + assert script.complete(3, len("furl.c")) diff --git a/test/test_inference/test_mixed.py b/test/test_inference/test_mixed.py index e9873c87..4feeb193 100644 --- a/test/test_inference/test_mixed.py +++ b/test/test_inference/test_mixed.py @@ -39,4 +39,4 @@ def test_generics(): self.stack.push(1) s = StackWrapper() - print(interpreter('s.stack.pop().', locals()).completions()) + print(interpreter('s.stack.pop().', locals()).complete()) diff --git a/test/test_inference/test_namespace_package.py b/test/test_inference/test_namespace_package.py index 1b156583..83da4b8c 100644 --- a/test/test_inference/test_namespace_package.py +++ b/test/test_inference/test_namespace_package.py @@ -38,7 +38,7 @@ def test_goto_assignment(Script, source, solution): def test_simple_completions(Script): # completion - completions = script_with_path(Script, 'from pkg import ').completions() + completions = script_with_path(Script, 'from pkg import ').complete() names = [str(c.name) for c in completions] # str because of unicode compare = ['foo', 'ns1_file', 'ns1_folder', 'ns2_folder', 'ns2_file', 'pkg_resources', 'pkgutil', '__name__', '__path__', @@ -58,7 +58,7 @@ def test_simple_completions(Script): ] ) def test_completions(Script, source, solution): - for c in script_with_path(Script, source + '; x.').completions(): + for c in script_with_path(Script, source + '; x.').complete(): if c.name == 'foo': completion = c solution = "foo = '%s'" % solution diff --git a/test/test_inference/test_pyc.py b/test/test_inference/test_pyc.py index 37449572..615fd1cd 100644 --- a/test/test_inference/test_pyc.py +++ b/test/test_inference/test_pyc.py @@ -70,4 +70,4 @@ def test_pyc(pyc_project_path, environment): "from dummy_package import dummy; dummy.", path=path, environment=environment) - assert len(s.completions()) >= 2 + assert len(s.complete()) >= 2 diff --git a/test/test_inference/test_stdlib.py b/test/test_inference/test_stdlib.py index fb98d8a4..a9697177 100644 --- a/test/test_inference/test_stdlib.py +++ b/test/test_inference/test_stdlib.py @@ -17,7 +17,7 @@ def test_namedtuple_str(letter, expected, Script): Person = collections.namedtuple('Person', 'name smart') dave = Person('Dave', False) dave.%s""") % letter - result = Script(source).completions() + result = Script(source).complete() completions = set(r.name for r in result) assert completions == set(expected) @@ -28,7 +28,7 @@ def test_namedtuple_list(Script): Cat = collections.namedtuple('Person', ['legs', u'length', 'large']) garfield = Cat(4, '85cm', True) garfield.l""") - result = Script(source).completions() + result = Script(source).complete() completions = set(r.name for r in result) assert completions == {'legs', 'length', 'large'} @@ -62,7 +62,7 @@ def test_nested_namedtuples(Script): train_x = Datasets(train=Dataset('data_value')) train_x.train.''' )) - assert 'data' in [c.name for c in s.completions()] + assert 'data' in [c.name for c in s.complete()] def test_namedtuple_goto_definitions(Script): diff --git a/test/test_parso_integration/test_basic.py b/test/test_parso_integration/test_basic.py index 289bad57..37f1d2c4 100644 --- a/test/test_parso_integration/test_basic.py +++ b/test/test_parso_integration/test_basic.py @@ -70,8 +70,8 @@ def test_add_to_end(Script): " self." def complete(code, line=None, column=None): - script = Script(code, line, column, 'example.py') - assert script.completions() + script = Script(code, 'example.py') + assert script.complete(line, column) complete(a, 7, 12) complete(a + b) diff --git a/test/test_parso_integration/test_error_correction.py b/test/test_parso_integration/test_error_correction.py index 02bd9af3..3ecb32e1 100644 --- a/test/test_parso_integration/test_error_correction.py +++ b/test/test_parso_integration/test_error_correction.py @@ -6,7 +6,7 @@ def test_error_correction_with(Script): with open() as f: try: f.""" - comps = Script(source).completions() + comps = Script(source).complete() assert len(comps) > 30 # `open` completions have a closed attribute. assert [1 for c in comps if c.name == 'closed'] @@ -23,14 +23,14 @@ def test_string_literals(Script): script = Script(dedent(source)) assert script._get_module_context().tree_node.end_pos == (6, 0) - assert script.completions() + assert script.complete() def test_incomplete_function(Script): source = '''return ImportErr''' - script = Script(dedent(source), 1, 3) - assert script.completions() + script = Script(dedent(source)) + assert script.complete(1, 3) def test_decorator_string_issue(Script): @@ -46,5 +46,5 @@ def test_decorator_string_issue(Script): bla.''') s = Script(source) - assert s.completions() + assert s.complete() assert s._get_module_context().tree_node.get_code() == source diff --git a/test/test_settings.py b/test/test_settings.py index 015d699e..5bf93b31 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -31,7 +31,7 @@ def test_additional_dynamic_modules(monkeypatch, Script): 'additional_dynamic_modules', ['/foo/bar/jedi_not_existing_file.py'] ) - assert not Script('def some_func(f):\n f.').completions() + assert not Script('def some_func(f):\n f.').complete() def test_cropped_file_size(monkeypatch, names, Script): @@ -48,4 +48,4 @@ def test_cropped_file_size(monkeypatch, names, Script): # It should just not crash if we are outside of the cropped range. script = Script(code + code + 'Foo') assert not script.goto_definitions() - assert 'Foo' in [c.name for c in script.completions()] + assert 'Foo' in [c.name for c in script.complete()] diff --git a/test/test_speed.py b/test/test_speed.py index ba5784ac..fc702bd9 100644 --- a/test/test_speed.py +++ b/test/test_speed.py @@ -33,7 +33,7 @@ def _check_speed(time_per_run, number=4, run_warm=True): @_check_speed(0.5) def test_os_path_join(Script): s = "from posixpath import join; join('', '')." - assert len(Script(s).completions()) > 10 # is a str completion + assert len(Script(s).complete()) > 10 # is a str completion @_check_speed(0.15) @@ -70,4 +70,4 @@ def test_no_repr_computation(Script): def __repr__(self): time.sleep(0.2) test = SlowRepr() - jedi.Interpreter('test.som', [locals()]).completions() + jedi.Interpreter('test.som', [locals()]).complete() diff --git a/test/test_utils.py b/test/test_utils.py index 3ac76389..a4c510e0 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -19,7 +19,7 @@ class TestSetupReadline(unittest.TestCase): self.namespace = self.NameSpace() utils.setup_readline(self.namespace) - def completions(self, text): + def complete(self, text): completer = readline.get_completer() i = 0 completions = [] @@ -32,18 +32,18 @@ class TestSetupReadline(unittest.TestCase): return completions def test_simple(self): - assert self.completions('list') == ['list'] - assert self.completions('importerror') == ['ImportError'] + assert self.complete('list') == ['list'] + assert self.complete('importerror') == ['ImportError'] s = "print(BaseE" - assert self.completions(s) == [s + 'xception'] + assert self.complete(s) == [s + 'xception'] def test_nested(self): - assert self.completions('list.Insert') == ['list.insert'] - assert self.completions('list().Insert') == ['list().insert'] + assert self.complete('list.Insert') == ['list.insert'] + assert self.complete('list().Insert') == ['list().insert'] def test_magic_methods(self): - assert self.completions('list.__getitem__') == ['list.__getitem__'] - assert self.completions('list().__getitem__') == ['list().__getitem__'] + assert self.complete('list.__getitem__') == ['list.__getitem__'] + assert self.complete('list().__getitem__') == ['list().__getitem__'] def test_modules(self): import sys @@ -52,31 +52,31 @@ class TestSetupReadline(unittest.TestCase): self.namespace.os = os try: - assert self.completions('os.path.join') == ['os.path.join'] + assert self.complete('os.path.join') == ['os.path.join'] string = 'os.path.join("a").upper' - assert self.completions(string) == [string] + assert self.complete(string) == [string] c = {'os.' + d for d in dir(os) if d.startswith('ch')} - assert set(self.completions('os.ch')) == set(c) + assert set(self.complete('os.ch')) == set(c) finally: del self.namespace.sys del self.namespace.os def test_calls(self): s = 'str(bytes' - assert self.completions(s) == [s, 'str(BytesWarning'] + assert self.complete(s) == [s, 'str(BytesWarning'] def test_import(self): s = 'from os.path import a' - assert set(self.completions(s)) == {s + 'ltsep', s + 'bspath'} - assert self.completions('import keyword') == ['import keyword'] + assert set(self.complete(s)) == {s + 'ltsep', s + 'bspath'} + assert self.complete('import keyword') == ['import keyword'] import os s = 'from os import ' goal = {s + el for el in dir(os)} # There are minor differences, e.g. the dir doesn't include deleted # items as well as items that are not only available on linux. - difference = set(self.completions(s)).symmetric_difference(goal) + difference = set(self.complete(s)).symmetric_difference(goal) difference = { x for x in difference if all(not x.startswith('from os import ' + s) @@ -89,11 +89,11 @@ class TestSetupReadline(unittest.TestCase): @cwd_at('test') def test_local_import(self): s = 'import test_utils' - assert self.completions(s) == [s] + assert self.complete(s) == [s] def test_preexisting_values(self): self.namespace.a = range(10) - assert set(self.completions('a.')) == {'a.' + n for n in dir(range(1))} + assert set(self.complete('a.')) == {'a.' + n for n in dir(range(1))} del self.namespace.a def test_colorama(self): @@ -110,8 +110,8 @@ class TestSetupReadline(unittest.TestCase): pass else: self.namespace.colorama = colorama - assert self.completions('colorama') - assert self.completions('colorama.Fore.BLACK') == ['colorama.Fore.BLACK'] + assert self.complete('colorama') + assert self.complete('colorama.Fore.BLACK') == ['colorama.Fore.BLACK'] del self.namespace.colorama