From d6d92862426581e99635e854c7981ab96cc97281 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 21 Mar 2020 02:07:53 +0100 Subject: [PATCH] Get rid of deprecations in tests --- sith.py | 2 +- test/test_api/test_call_signatures.py | 3 ++- test/test_api/test_classes.py | 2 +- test/test_api/test_completion.py | 4 ++-- test/test_api/test_unicode.py | 6 ------ test/test_deprecation.py | 20 +++++++++++++++++++ .../test_implicit_namespace_package.py | 20 +++++++++---------- test/test_inference/test_imports.py | 4 ++-- test/test_inference/test_namespace_package.py | 4 +--- test/test_parso_integration/test_basic.py | 2 +- 10 files changed, 40 insertions(+), 27 deletions(-) diff --git a/sith.py b/sith.py index 746bac4a..4718b8c1 100755 --- a/sith.py +++ b/sith.py @@ -168,7 +168,7 @@ class TestCase(object): def show_definitions(self): for completion in self.objects: - print(completion.desc_with_module) + print(completion.full_name) if completion.module_path is None: continue if os.path.abspath(completion.module_path) == os.path.abspath(self.path): diff --git a/test/test_api/test_call_signatures.py b/test/test_api/test_call_signatures.py index 9d6b43ef..d880dc4c 100644 --- a/test/test_api/test_call_signatures.py +++ b/test/test_api/test_call_signatures.py @@ -316,7 +316,8 @@ def test_signature_is_definition(Script): # 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'] + 'params', 'get_signatures', 'execute', 'goto', + 'desc_with_module'] if attr_name.startswith('_') or attr_name in dont_scan: continue diff --git a/test/test_api/test_classes.py b/test/test_api/test_classes.py index 6163a9af..17265293 100644 --- a/test/test_api/test_classes.py +++ b/test/test_api/test_classes.py @@ -193,7 +193,7 @@ def test_hashlib_params(Script, environment): if environment.version_info < (3,): pytest.skip() - script = Script(source='from hashlib import sha256') + script = Script('from hashlib import sha256') c, = script.complete() sig, = c.get_signatures() assert [p.name for p in sig.params] == ['arg'] diff --git a/test/test_api/test_completion.py b/test/test_api/test_completion.py index 6e1c9393..8f7db085 100644 --- a/test/test_api/test_completion.py +++ b/test/test_api/test_completion.py @@ -92,11 +92,11 @@ def test_complete_expanduser(Script): non_dots = [p for p in possibilities if not p.name.startswith('.') and len(p.name) > 1] item = non_dots[0] line = "'~%s%s'" % (os.sep, item.name) - s = Script(line, line=1, column=len(line)-1) + s = Script(line) expected_name = item.name if item.is_dir(): expected_name += os.path.sep - assert expected_name in [c.name for c in s.completions()] + assert expected_name in [c.name for c in s.completions(column=len(line)-1)] def test_fake_subnodes(Script): diff --git a/test/test_api/test_unicode.py b/test/test_api/test_unicode.py index f7f7ec45..91090d1a 100644 --- a/test/test_api/test_unicode.py +++ b/test/test_api/test_unicode.py @@ -74,9 +74,3 @@ def test_wrong_encoding(Script, tmpdir): project = Project('.', sys_path=[tmpdir.strpath]) c, = Script('import x; x.foo', project=project).complete() assert c.name == 'foobar' - - -def test_encoding_parameter(Script): - name = u('hö') - s = Script(name.encode('latin-1'), encoding='latin-1') - assert s._module_node.get_code() == name diff --git a/test/test_deprecation.py b/test/test_deprecation.py index ed3603e6..86706ac2 100644 --- a/test/test_deprecation.py +++ b/test/test_deprecation.py @@ -1,3 +1,17 @@ +import warnings + +import pytest + +from jedi._compatibility import u + + +@pytest.fixture(autouse=True) +def check_for_warning(recwarn): + warnings.simplefilter("always") + with pytest.warns(DeprecationWarning): + yield + + def test_goto_definitions(Script): int_, = Script('x = 1\nx, y\ny', line=2, column=0).goto_definitions() assert int_.name == 'int' @@ -25,3 +39,9 @@ def test_usages(Script): def test_call_signatures(Script): d1, = Script('abs(float(\nstr(', line=1, column=4).call_signatures() assert d1.name == 'abs' + + +def test_encoding_parameter(Script): + name = u('hö') + s = Script(name.encode('latin-1'), encoding='latin-1') + assert s._module_node.get_code() == name diff --git a/test/test_inference/test_implicit_namespace_package.py b/test/test_inference/test_implicit_namespace_package.py index 3fa2b09a..452375b3 100644 --- a/test/test_inference/test_implicit_namespace_package.py +++ b/test/test_inference/test_implicit_namespace_package.py @@ -58,9 +58,9 @@ def test_implicit_nested_namespace_package(Script): code = 'from implicit_nested_namespaces.namespace.pkg.module import CONST' project = Project('.', sys_path=[example_dir]) - script = Script(project=project, source=code, line=1, column=61) + script = Script(code, project=project) - result = script.infer() + result = script.infer(line=1, column=61) assert len(result) == 1 @@ -70,41 +70,41 @@ def test_implicit_nested_namespace_package(Script): def test_implicit_namespace_package_import_autocomplete(Script): - CODE = 'from implicit_name' + code = 'from implicit_name' project = Project('.', sys_path=[example_dir]) - script = Script(project=project, source=CODE) + script = Script(code, project=project) compl = script.complete() assert [c.name for c in compl] == ['implicit_namespace_package'] def test_namespace_package_in_multiple_directories_autocompletion(Script): - CODE = 'from pkg.' + code = 'from pkg.' sys_path = [get_example_dir('implicit_namespace_package', 'ns1'), get_example_dir('implicit_namespace_package', 'ns2')] project = Project('.', sys_path=sys_path) - script = Script(project=project, source=CODE) + script = Script(code, project=project) compl = script.complete() assert set(c.name for c in compl) == set(['ns1_file', 'ns2_file']) def test_namespace_package_in_multiple_directories_goto_definition(Script): - CODE = 'from pkg import ns1_file' + code = 'from pkg import ns1_file' sys_path = [get_example_dir('implicit_namespace_package', 'ns1'), get_example_dir('implicit_namespace_package', 'ns2')] project = Project('.', sys_path=sys_path) - script = Script(project=project, source=CODE) + script = Script(code, project=project) result = script.infer() assert len(result) == 1 def test_namespace_name_autocompletion_full_name(Script): - CODE = 'from pk' + code = 'from pk' sys_path = [get_example_dir('implicit_namespace_package', 'ns1'), get_example_dir('implicit_namespace_package', 'ns2')] project = Project('.', sys_path=sys_path) - script = Script(project=project, source=CODE) + script = Script(code, project=project) 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 dd528167..f5097f21 100644 --- a/test/test_inference/test_imports.py +++ b/test/test_inference/test_imports.py @@ -259,7 +259,7 @@ def test_goto_following_on_imports(Script): def test_goto(Script): - sys, = Script("import sys", 1, 10).goto(follow_imports=True) + sys, = Script("import sys").goto(follow_imports=True) assert sys.type == 'module' @@ -472,6 +472,6 @@ def test_relative_import_star(Script): from . import * furl.c """ - script = Script(source, 'export.py') + script = Script(source, path='export.py') assert script.complete(3, len("furl.c")) diff --git a/test/test_inference/test_namespace_package.py b/test/test_inference/test_namespace_package.py index 3cbd8d6e..67fa49b6 100644 --- a/test/test_inference/test_namespace_package.py +++ b/test/test_inference/test_namespace_package.py @@ -71,9 +71,7 @@ def test_nested_namespace_package(Script): sys_path = [example_dir] project = Project('.', sys_path=sys_path) - script = Script(project=project, source=code) - - result = script.infer(line=1, column=45) + result = Script(code, project=project).infer(line=1, column=45) assert len(result) == 1 diff --git a/test/test_parso_integration/test_basic.py b/test/test_parso_integration/test_basic.py index efedc827..f2831dc5 100644 --- a/test/test_parso_integration/test_basic.py +++ b/test/test_parso_integration/test_basic.py @@ -70,7 +70,7 @@ def test_add_to_end(Script): " self." def complete(code, line=None, column=None): - script = Script(code, 'example.py') + script = Script(code, path='example.py') assert script.complete(line, column) complete(a, 7, 12)