1
0
forked from VimPlug/jedi

Make sure to not load unsafe modules anymore if they are not on the sys path, fixes #760

This commit is contained in:
Dave Halter
2020-01-31 13:09:28 +01:00
parent e7a77e438d
commit 8ff2ea4b38
6 changed files with 56 additions and 23 deletions

View File

@@ -35,8 +35,9 @@ def test_get_signatures_stdlib(Script):
# Check only on linux 64 bit platform and Python3.4.
@pytest.mark.skipif('sys.platform != "linux" or sys.maxsize <= 2**32 or sys.version_info[:2] != (3, 4)')
@pytest.mark.parametrize('load_unsafe_extensions', [False, True])
@cwd_at('test/examples')
def test_init_extension_module(Script):
def test_init_extension_module(Script, load_unsafe_extensions):
"""
``__init__`` extension modules are also packages and Jedi should understand
that.
@@ -50,8 +51,25 @@ 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.complete()]
project = jedi.Project('.', load_unsafe_extensions=load_unsafe_extensions)
s = jedi.Script(
'import init_extension_module as i\ni.',
path='not_existing.py',
project=project,
)
if load_unsafe_extensions:
assert 'foo' in [c.name for c in s.complete()]
else:
assert 'foo' not 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.complete()]
s = jedi.Script(
'from init_extension_module import foo\nfoo',
path='not_existing.py',
project=project,
)
c, = s.complete()
assert c.name == 'foo'
if load_unsafe_extensions:
assert c.infer()
else:
assert not c.infer()

View File

@@ -55,7 +55,8 @@ def pyc_project_path(tmpdir):
shutil.rmtree(path)
def test_pyc(pyc_project_path, environment):
@pytest.mark.parametrize('load_unsafe_extensions', [False, True])
def test_pyc(pyc_project_path, environment, load_unsafe_extensions):
"""
The list of completion must be greater than 2.
"""
@@ -66,8 +67,14 @@ def test_pyc(pyc_project_path, environment):
# we also have the same version and it's easier to debug.
environment = SameEnvironment()
environment = environment
project = jedi.Project(pyc_project_path, load_unsafe_extensions=load_unsafe_extensions)
s = jedi.Script(
"from dummy_package import dummy; dummy.",
path=path,
environment=environment)
assert len(s.complete()) >= 2
environment=environment,
project=project,
)
if load_unsafe_extensions:
assert len(s.complete()) >= 2
else:
assert not s.complete()