mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Move the zip tests to the environment
This commit is contained in:
@@ -4,7 +4,6 @@ Tests".
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from subprocess import check_output
|
||||
|
||||
import pytest
|
||||
@@ -46,41 +45,43 @@ def has_zlib(environment):
|
||||
# test since 3.3 is End-of-Life anyway.
|
||||
# ZLIB is not compiled with all Python versions and therefore zipimport is
|
||||
# not possible in this one.
|
||||
return 'Modules/zlibmodule.o' in output
|
||||
return b'Modules/zlibmodule.o' in output
|
||||
|
||||
|
||||
def test_find_module_package_zipped(Script, environment, has_zlib):
|
||||
def test_find_module_package_zipped(Script, evaluator, has_zlib):
|
||||
path = os.path.join(os.path.dirname(__file__), 'zipped_imports/pkg.zip')
|
||||
script = Script('import pkg; pkg.mod', 1, 19, sys_path=[path])
|
||||
assert len(script.completions()) == int(has_zlib)
|
||||
|
||||
if not has_zlib:
|
||||
return
|
||||
sys.path.append(path)
|
||||
try:
|
||||
file, path, is_package = find_module('pkg')
|
||||
assert file is not None
|
||||
assert path.endswith('pkg.zip')
|
||||
assert is_package is True
|
||||
finally:
|
||||
sys.path.pop()
|
||||
|
||||
code, path, is_package = evaluator.compiled_subprocess.get_module_info(
|
||||
sys_path=[path],
|
||||
string=u'pkg',
|
||||
full_name=u'pkg'
|
||||
)
|
||||
assert code is not None
|
||||
assert path.endswith('pkg.zip')
|
||||
assert is_package is True
|
||||
|
||||
|
||||
def test_find_module_not_package_zipped(Script, environment, has_zlib):
|
||||
def test_find_module_not_package_zipped(Script, evaluator, has_zlib):
|
||||
path = os.path.join(os.path.dirname(__file__), 'zipped_imports/not_pkg.zip')
|
||||
script = Script('import not_pkg; not_pkg.val', 1, 27, sys_path=[path])
|
||||
assert len(script.completions()) == int(has_zlib)
|
||||
|
||||
if not has_zlib:
|
||||
return
|
||||
sys.path.append(path)
|
||||
try:
|
||||
file, path, is_package = find_module('not_pkg')
|
||||
assert file is not None
|
||||
assert path.endswith('not_pkg.zip')
|
||||
assert is_package is False
|
||||
finally:
|
||||
sys.path.pop()
|
||||
|
||||
code, path, is_package = evaluator.compiled_subprocess.get_module_info(
|
||||
sys_path=[path],
|
||||
string=u'not_pkg',
|
||||
full_name=u'not_pkg'
|
||||
)
|
||||
assert code is not None
|
||||
assert path.endswith('not_pkg.zip')
|
||||
assert is_package is False
|
||||
|
||||
|
||||
@cwd_at('test/test_evaluate/not_in_sys_path/pkg')
|
||||
|
||||
Reference in New Issue
Block a user