def test_reset_after_import(self): with ImportEnvironment() as sys: polyloader.install(compiler("2"), ['2']) polyloader.install(compiler("3"), ['3']) from tests_py2.polytestmix.test3 import result as result3 polyloader.reset() with pytest.raises(ImportError): from tests_py2.polytestmix.test2 import result as result2
def test_uninstall_after_import(self): with ImportEnvironment() as sys: polyloader.install(compiler("3"), ['3']) polyloader.install(compiler("2"), ['2']) import tests_py2.polytestmix.test3 polyloader.uninstall('2') with pytest.raises(ImportError): import tests_py2.polytestmix.test2 import tests_py2.polytestmix.test1
def test_import1(self): with ImportEnvironment() as sys: polyloader.install(compiler("2"), ['2']) polyloader.install(compiler("3"), ['3']) from .polytestmix import test2 from .polytestmix import test3 from .polytestmix import test1 assert (test1.result == "Success for 1: Test One") assert (test2.result == "Success for 2: Test Two") assert (test3.result == "Success for 3: Test Three")
def test_import3(self): with ImportEnvironment() as sys: polyloader.install(compiler("3"), ['3']) polyloader.install(compiler("2"), ['2']) from tests_py2.polytestmix.test3 import result as result3 from tests_py2.polytestmix.test2 import result as result2 from tests_py2.polytestmix.test1 import result as result1 assert (result1 == "Success for 1: Test One") assert (result2 == "Success for 2: Test Two") assert (result3 == "Success for 3: Test Three")
def test_import3(self): with ImportEnvironment() as sys: polyloader.install(compiler("3"), ['3']) polyloader.install(compiler("2"), ['2']) from tests_py3.polytestmix.test3 import result as result3 from tests_py3.polytestmix.test2 import result as result2 from tests_py3.polytestmix.test1 import result as result1 assert(result1 == "Success for 1: Test One") assert(result2 == "Success for 2: Test Two") assert(result3 == "Success for 3: Test Three")
def test_import2(self): with ImportEnvironment() as sys: polyloader.install(compiler("2"), ['2']) polyloader.install(compiler("3"), ['3']) import tests_py3.polytestmix.test2 import tests_py3.polytestmix.test3 import tests_py3.polytestmix.test1 assert(tests_py3.polytestmix.test1.result == "Success for 1: Test One") assert(tests_py3.polytestmix.test2.result == "Success for 2: Test Two") assert(tests_py3.polytestmix.test3.result == "Success for 3: Test Three")
def test_iterator(self): with ImportEnvironment() as sys: import os import inspect polyloader.install(compiler("2"), ['2']) polyloader.install(compiler("3"), ['3']) import pkgutil target_dir = os.path.join( os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), 'polytestmix') modules = set([name for (_, name, is_pkg) in pkgutil.iter_modules([target_dir]) if not is_pkg and not name.startswith('_')]) assert(modules == set(['test1', 'test2', 'test3']))
def test_uninstall_before_import(self): with ImportEnvironment() as sys: polyloader.install(compiler("2"), ['2']) polyloader.install(compiler("3"), ['3']) assert (polyloader.is_installed('2')) assert (polyloader.is_installed('3')) polyloader.uninstall('2') polyloader.uninstall('3') assert (not polyloader.is_installed('2')) assert (not polyloader.is_installed('3')) with pytest.raises(ImportError): import tests_py2.polytestmix.test2 with pytest.raises(ImportError): import tests_py2.polytestmix.test3 import tests_py2.polytestmix.test1
class Compiler: def __init__(self, pt): self.pt = pt def __call__(self, source_text, filename, *extra): return compile( "result='Success for %s: %s'" % (self.pt, source_text.rstrip()), filename, "exec") def __repr__(self): return "Compiler %s" % (self.pt) polyloader.install(Compiler("2"), ['2']) TESTFN = '@test' def clean_tmpfiles(path): if os.path.exists(path): os.remove(path) if os.path.exists(path + 'c'): os.remove(path + 'c') if os.path.exists(path + 'o'): os.remove(path + 'o') def unload(name): try:
import imp import random import struct class Compiler: def __init__(self, pt): self.pt = pt def __call__(self, source_text, filename, *extra): return compile("result='Success for %s: %s'" % (self.pt, source_text.rstrip()), filename, "exec") def __repr__(self): return "Compiler %s" % (self.pt) polyloader.install(Compiler("2"), ['2']) TESTFN = '@test' def clean_tmpfiles(path): if os.path.exists(path): os.remove(path) if os.path.exists(path + 'c'): os.remove(path + 'c') if os.path.exists(path + 'o'): os.remove(path + 'o') def unload(name): try: del sys.modules[name] except KeyError: