mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Get rid of deprecations in tests
This commit is contained in:
2
sith.py
2
sith.py
@@ -168,7 +168,7 @@ class TestCase(object):
|
|||||||
|
|
||||||
def show_definitions(self):
|
def show_definitions(self):
|
||||||
for completion in self.objects:
|
for completion in self.objects:
|
||||||
print(completion.desc_with_module)
|
print(completion.full_name)
|
||||||
if completion.module_path is None:
|
if completion.module_path is None:
|
||||||
continue
|
continue
|
||||||
if os.path.abspath(completion.module_path) == os.path.abspath(self.path):
|
if os.path.abspath(completion.module_path) == os.path.abspath(self.path):
|
||||||
|
|||||||
@@ -316,7 +316,8 @@ def test_signature_is_definition(Script):
|
|||||||
# Now compare all the attributes that a Signature must also have.
|
# Now compare all the attributes that a Signature must also have.
|
||||||
for attr_name in dir(definition):
|
for attr_name in dir(definition):
|
||||||
dont_scan = ['defined_names', 'parent', 'goto_assignments', 'infer',
|
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:
|
if attr_name.startswith('_') or attr_name in dont_scan:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ def test_hashlib_params(Script, environment):
|
|||||||
if environment.version_info < (3,):
|
if environment.version_info < (3,):
|
||||||
pytest.skip()
|
pytest.skip()
|
||||||
|
|
||||||
script = Script(source='from hashlib import sha256')
|
script = Script('from hashlib import sha256')
|
||||||
c, = script.complete()
|
c, = script.complete()
|
||||||
sig, = c.get_signatures()
|
sig, = c.get_signatures()
|
||||||
assert [p.name for p in sig.params] == ['arg']
|
assert [p.name for p in sig.params] == ['arg']
|
||||||
|
|||||||
@@ -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]
|
non_dots = [p for p in possibilities if not p.name.startswith('.') and len(p.name) > 1]
|
||||||
item = non_dots[0]
|
item = non_dots[0]
|
||||||
line = "'~%s%s'" % (os.sep, item.name)
|
line = "'~%s%s'" % (os.sep, item.name)
|
||||||
s = Script(line, line=1, column=len(line)-1)
|
s = Script(line)
|
||||||
expected_name = item.name
|
expected_name = item.name
|
||||||
if item.is_dir():
|
if item.is_dir():
|
||||||
expected_name += os.path.sep
|
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):
|
def test_fake_subnodes(Script):
|
||||||
|
|||||||
@@ -74,9 +74,3 @@ def test_wrong_encoding(Script, tmpdir):
|
|||||||
project = Project('.', sys_path=[tmpdir.strpath])
|
project = Project('.', sys_path=[tmpdir.strpath])
|
||||||
c, = Script('import x; x.foo', project=project).complete()
|
c, = Script('import x; x.foo', project=project).complete()
|
||||||
assert c.name == 'foobar'
|
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
|
|
||||||
|
|||||||
@@ -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):
|
def test_goto_definitions(Script):
|
||||||
int_, = Script('x = 1\nx, y\ny', line=2, column=0).goto_definitions()
|
int_, = Script('x = 1\nx, y\ny', line=2, column=0).goto_definitions()
|
||||||
assert int_.name == 'int'
|
assert int_.name == 'int'
|
||||||
@@ -25,3 +39,9 @@ def test_usages(Script):
|
|||||||
def test_call_signatures(Script):
|
def test_call_signatures(Script):
|
||||||
d1, = Script('abs(float(\nstr(', line=1, column=4).call_signatures()
|
d1, = Script('abs(float(\nstr(', line=1, column=4).call_signatures()
|
||||||
assert d1.name == 'abs'
|
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
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ def test_implicit_nested_namespace_package(Script):
|
|||||||
code = 'from implicit_nested_namespaces.namespace.pkg.module import CONST'
|
code = 'from implicit_nested_namespaces.namespace.pkg.module import CONST'
|
||||||
|
|
||||||
project = Project('.', sys_path=[example_dir])
|
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
|
assert len(result) == 1
|
||||||
|
|
||||||
@@ -70,41 +70,41 @@ def test_implicit_nested_namespace_package(Script):
|
|||||||
|
|
||||||
|
|
||||||
def test_implicit_namespace_package_import_autocomplete(Script):
|
def test_implicit_namespace_package_import_autocomplete(Script):
|
||||||
CODE = 'from implicit_name'
|
code = 'from implicit_name'
|
||||||
|
|
||||||
project = Project('.', sys_path=[example_dir])
|
project = Project('.', sys_path=[example_dir])
|
||||||
script = Script(project=project, source=CODE)
|
script = Script(code, project=project)
|
||||||
compl = script.complete()
|
compl = script.complete()
|
||||||
assert [c.name for c in compl] == ['implicit_namespace_package']
|
assert [c.name for c in compl] == ['implicit_namespace_package']
|
||||||
|
|
||||||
|
|
||||||
def test_namespace_package_in_multiple_directories_autocompletion(Script):
|
def test_namespace_package_in_multiple_directories_autocompletion(Script):
|
||||||
CODE = 'from pkg.'
|
code = 'from pkg.'
|
||||||
sys_path = [get_example_dir('implicit_namespace_package', 'ns1'),
|
sys_path = [get_example_dir('implicit_namespace_package', 'ns1'),
|
||||||
get_example_dir('implicit_namespace_package', 'ns2')]
|
get_example_dir('implicit_namespace_package', 'ns2')]
|
||||||
|
|
||||||
project = Project('.', sys_path=sys_path)
|
project = Project('.', sys_path=sys_path)
|
||||||
script = Script(project=project, source=CODE)
|
script = Script(code, project=project)
|
||||||
compl = script.complete()
|
compl = script.complete()
|
||||||
assert set(c.name for c in compl) == set(['ns1_file', 'ns2_file'])
|
assert set(c.name for c in compl) == set(['ns1_file', 'ns2_file'])
|
||||||
|
|
||||||
|
|
||||||
def test_namespace_package_in_multiple_directories_goto_definition(Script):
|
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'),
|
sys_path = [get_example_dir('implicit_namespace_package', 'ns1'),
|
||||||
get_example_dir('implicit_namespace_package', 'ns2')]
|
get_example_dir('implicit_namespace_package', 'ns2')]
|
||||||
project = Project('.', sys_path=sys_path)
|
project = Project('.', sys_path=sys_path)
|
||||||
script = Script(project=project, source=CODE)
|
script = Script(code, project=project)
|
||||||
result = script.infer()
|
result = script.infer()
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_namespace_name_autocompletion_full_name(Script):
|
def test_namespace_name_autocompletion_full_name(Script):
|
||||||
CODE = 'from pk'
|
code = 'from pk'
|
||||||
sys_path = [get_example_dir('implicit_namespace_package', 'ns1'),
|
sys_path = [get_example_dir('implicit_namespace_package', 'ns1'),
|
||||||
get_example_dir('implicit_namespace_package', 'ns2')]
|
get_example_dir('implicit_namespace_package', 'ns2')]
|
||||||
|
|
||||||
project = Project('.', sys_path=sys_path)
|
project = Project('.', sys_path=sys_path)
|
||||||
script = Script(project=project, source=CODE)
|
script = Script(code, project=project)
|
||||||
compl = script.complete()
|
compl = script.complete()
|
||||||
assert set(c.full_name for c in compl) == set(['pkg'])
|
assert set(c.full_name for c in compl) == set(['pkg'])
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ def test_goto_following_on_imports(Script):
|
|||||||
|
|
||||||
|
|
||||||
def test_goto(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'
|
assert sys.type == 'module'
|
||||||
|
|
||||||
|
|
||||||
@@ -472,6 +472,6 @@ def test_relative_import_star(Script):
|
|||||||
from . import *
|
from . import *
|
||||||
furl.c
|
furl.c
|
||||||
"""
|
"""
|
||||||
script = Script(source, 'export.py')
|
script = Script(source, path='export.py')
|
||||||
|
|
||||||
assert script.complete(3, len("furl.c"))
|
assert script.complete(3, len("furl.c"))
|
||||||
|
|||||||
@@ -71,9 +71,7 @@ def test_nested_namespace_package(Script):
|
|||||||
|
|
||||||
sys_path = [example_dir]
|
sys_path = [example_dir]
|
||||||
project = Project('.', sys_path=sys_path)
|
project = Project('.', sys_path=sys_path)
|
||||||
script = Script(project=project, source=code)
|
result = Script(code, project=project).infer(line=1, column=45)
|
||||||
|
|
||||||
result = script.infer(line=1, column=45)
|
|
||||||
|
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ def test_add_to_end(Script):
|
|||||||
" self."
|
" self."
|
||||||
|
|
||||||
def complete(code, line=None, column=None):
|
def complete(code, line=None, column=None):
|
||||||
script = Script(code, 'example.py')
|
script = Script(code, path='example.py')
|
||||||
assert script.complete(line, column)
|
assert script.complete(line, column)
|
||||||
|
|
||||||
complete(a, 7, 12)
|
complete(a, 7, 12)
|
||||||
|
|||||||
Reference in New Issue
Block a user