Merge branch 'refactor'

This commit is contained in:
Dave Halter
2020-03-21 02:54:07 +01:00
116 changed files with 4326 additions and 2483 deletions

View File

@@ -67,7 +67,7 @@ def test_path_from_sys_path_assignment(Script):
import sys
sys.path[0:0] = [
'/usr/lib/python3.4/site-packages',
'/usr/lib/python3.8/site-packages',
'/home/test/.buildout/eggs/important_package.egg'
]

View File

@@ -33,9 +33,9 @@ def test_get_signatures_stdlib(Script):
assert len(sigs[0].params) == 1
# Check only on linux 64 bit platform and Python3.4.
# Check only on linux 64 bit platform and Python3.8.
@pytest.mark.parametrize('load_unsafe_extensions', [False, True])
@pytest.mark.skipif('sys.platform != "linux" or sys.maxsize <= 2**32 or sys.version_info[:2] != (3, 4)')
@pytest.mark.skipif('sys.platform != "linux" or sys.maxsize <= 2**32 or sys.version_info[:2] != (3, 8)')
def test_init_extension_module(Script, load_unsafe_extensions):
"""
``__init__`` extension modules are also packages and Jedi should understand
@@ -45,10 +45,10 @@ def test_init_extension_module(Script, load_unsafe_extensions):
This test was built by the module.c and setup.py combination you can find
in the init_extension_module folder. You can easily build the
`__init__.cpython-34m.so` by compiling it (create a virtualenv and run
`__init__.cpython-38m.so` by compiling it (create a virtualenv and run
`setup.py install`.
This is also why this test only runs on certain systems (and Python 3.4).
This is also why this test only runs on certain systems and Python 3.8.
"""
project = jedi.Project(get_example_dir(), load_unsafe_extensions=load_unsafe_extensions)

View File

@@ -45,7 +45,7 @@ def test_infer_and_goto(Script, code, full_name, has_stub, has_python, way,
kwargs, type_, options, environment):
if environment.version_info < (3, 5):
# We just don't care about much of the detailed Python 2 failures
# anymore, because its end-of-life soon. (same for 3.4)
# anymore, because its end-of-life soon.
pytest.skip()
if type_ == 'infer' and full_name == 'typing.Sequence' and environment.version_info >= (3, 7):

View File

@@ -24,9 +24,6 @@ def test_get_typeshed_directories():
dirs = get_dirs(PythonVersionInfo(2, 7))
assert dirs == transform({'stdlib/2and3', 'stdlib/2', 'third_party/2and3', 'third_party/2'})
dirs = get_dirs(PythonVersionInfo(3, 4))
assert dirs == transform({'stdlib/2and3', 'stdlib/3', 'third_party/2and3', 'third_party/3'})
dirs = get_dirs(PythonVersionInfo(3, 5))
assert dirs == transform({'stdlib/2and3', 'stdlib/3',
'third_party/2and3', 'third_party/3'})
@@ -139,10 +136,13 @@ def test_math(Script):
assert value
def test_type_var(Script):
def test_type_var(Script, environment):
def_, = Script('import typing; T = typing.TypeVar("T1")').infer()
assert def_.name == 'TypeVar'
assert def_.description == 'TypeVar = object()'
if environment.version_info.major == 2:
assert def_.description == 'TypeVar = object()'
else:
assert def_.description == 'class TypeVar'
@pytest.mark.parametrize(

View File

@@ -8,7 +8,7 @@ from jedi import Project
@pytest.fixture(autouse=True)
def skip_not_supported_versions(environment):
if environment.version_info < (3, 4):
if environment.version_info < (3, 5):
pytest.skip()
@@ -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'])

View File

@@ -7,7 +7,7 @@ import os
import pytest
from jedi.file_io import FileIO, KnownContentFileIO
from jedi.file_io import FileIO
from jedi._compatibility import find_module_py33, find_module
from jedi.inference import compiled
from jedi.inference import imports
@@ -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'
@@ -344,23 +344,6 @@ def test_get_modules_containing_name(inference_state, path, goal, is_package):
assert found_module.string_names == goal
@pytest.mark.parametrize(
('path', 'base_names', 'is_package', 'names'), [
('/foo/bar.py', ('foo',), False, ('foo', 'bar')),
('/foo/bar.py', ('foo', 'baz'), False, ('foo', 'baz', 'bar')),
('/foo/__init__.py', ('foo',), True, ('foo',)),
('/__init__.py', ('foo',), True, ('foo',)),
('/foo/bar/__init__.py', ('foo',), True, ('foo',)),
('/foo/bar/__init__.py', ('foo', 'bar'), True, ('foo', 'bar')),
]
)
def test_load_module_from_path(inference_state, path, base_names, is_package, names):
file_io = KnownContentFileIO(path, '')
m = imports.load_module_from_path(inference_state, file_io, base_names)
assert m.is_package() == is_package
assert m.string_names == names
@pytest.mark.parametrize(
'path', ('api/whatever/test_this.py', 'api/whatever/file'))
@pytest.mark.parametrize('empty_sys_path', (False, True))
@@ -489,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"))

View File

@@ -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
@@ -82,7 +80,7 @@ def test_relative_import(Script, environment, tmpdir):
"""
Attempt a relative import in a very simple namespace package.
"""
if environment.version_info < (3, 4):
if environment.version_info < (3, 5):
pytest.skip()
directory = get_example_dir('namespace_package_relative_import')

View File

@@ -29,11 +29,11 @@ def pyc_project_path(tmpdir):
path = tmpdir.strpath
dummy_package_path = os.path.join(path, "dummy_package")
os.mkdir(dummy_package_path)
with open(os.path.join(dummy_package_path, "__init__.py"), 'w'):
with open(os.path.join(dummy_package_path, "__init__.py"), 'w', newline=''):
pass
dummy_path = os.path.join(dummy_package_path, 'dummy.py')
with open(dummy_path, 'w') as f:
with open(dummy_path, 'w', newline='') as f:
f.write(SRC)
import compileall
compileall.compile_file(dummy_path)
@@ -56,6 +56,7 @@ def pyc_project_path(tmpdir):
@pytest.mark.parametrize('load_unsafe_extensions', [False, True])
@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL")
def test_pyc(pyc_project_path, environment, load_unsafe_extensions):
"""
The list of completion must be greater than 2.