def test_lib2to3importer__ctypes(self): from lib2to3import import lib2to3importer from lib2to3import import prepending with prepending(lib2to3importer([], "foo.bar")): import _ctypes assert _ctypes
def test_lib2to3importer(self, fixers, prefix, modname): from lib2to3import import lib2to3importer from lib2to3import import prepending sys.modules.pop(modname, None) self.assertRaises(SyntaxError, import_module, modname) with prepending(lib2to3importer(fixers, prefix)): self.assertNotEqual(sys.path_hooks, self.path_hooks) with mock.patch("sys.stdout", new_callable=StringIO): import_module(modname) self.assertSequenceEqual(sys.path_hooks, self.path_hooks)
def test_lib2to3importer_pysandbox(self): from lib2to3import import lib2to3importer from lib2to3import import prepending fixers = [ "lib2to3.fixes.fix_exec", "lib2to3.fixes.fix_long", "lib2to3.fixes.fix_unicode", "lib2to3.fixes.fix_imports", "lib2to3.fixes.fix_dict", ] with prepending(lib2to3importer(fixers, "sandbox")): from sandbox import Sandbox from sandbox import SandboxConfig from sandbox import SandboxError box = Sandbox(SandboxConfig(use_subprocess=True)) self.assertRaises(SandboxError, box.call, print, "123")