Move the zip tests to the environment

This commit is contained in:
Dave Halter
2018-01-06 02:19:58 +01:00
parent 99eed91206
commit e42796ca10

View File

@@ -4,7 +4,6 @@ Tests".
""" """
import os import os
import sys
from subprocess import check_output from subprocess import check_output
import pytest import pytest
@@ -46,41 +45,43 @@ def has_zlib(environment):
# test since 3.3 is End-of-Life anyway. # test since 3.3 is End-of-Life anyway.
# ZLIB is not compiled with all Python versions and therefore zipimport is # ZLIB is not compiled with all Python versions and therefore zipimport is
# not possible in this one. # 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') path = os.path.join(os.path.dirname(__file__), 'zipped_imports/pkg.zip')
script = Script('import pkg; pkg.mod', 1, 19, sys_path=[path]) script = Script('import pkg; pkg.mod', 1, 19, sys_path=[path])
assert len(script.completions()) == int(has_zlib) assert len(script.completions()) == int(has_zlib)
if not has_zlib: if not has_zlib:
return return
sys.path.append(path)
try: code, path, is_package = evaluator.compiled_subprocess.get_module_info(
file, path, is_package = find_module('pkg') sys_path=[path],
assert file is not None string=u'pkg',
assert path.endswith('pkg.zip') full_name=u'pkg'
assert is_package is True )
finally: assert code is not None
sys.path.pop() 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') 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]) script = Script('import not_pkg; not_pkg.val', 1, 27, sys_path=[path])
assert len(script.completions()) == int(has_zlib) assert len(script.completions()) == int(has_zlib)
if not has_zlib: if not has_zlib:
return return
sys.path.append(path)
try: code, path, is_package = evaluator.compiled_subprocess.get_module_info(
file, path, is_package = find_module('not_pkg') sys_path=[path],
assert file is not None string=u'not_pkg',
assert path.endswith('not_pkg.zip') full_name=u'not_pkg'
assert is_package is False )
finally: assert code is not None
sys.path.pop() assert path.endswith('not_pkg.zip')
assert is_package is False
@cwd_at('test/test_evaluate/not_in_sys_path/pkg') @cwd_at('test/test_evaluate/not_in_sys_path/pkg')