コード例 #1
0
ファイル: sandbox_test.py プロジェクト: girum11/hang
 def test_module_success(self):
   hook = sandbox.PathOverrideImportHook(['urllib'])
   self.assertEqual(hook, hook.find_module('urllib'))
   del sys.modules['urllib']
   hooked_urllib = hook.load_module('urllib')
   self.assertEqual(hooked_urllib.__file__.replace('.pyc', '.py'),
                    urllib.__file__.replace('.pyc', '.py'))
   self.assertEqual(hooked_urllib.__loader__, hook)
   self.assertNotIn('__path__', hooked_urllib.__dict__)
   self.assertFalse(hook.extra_accessible_paths)
   self.assertFalse(hook.extra_sys_paths)
コード例 #2
0
ファイル: sandbox_test.py プロジェクト: girum11/hang
 def test_package_success_pil_in_sys_path(self):
   hook = sandbox.PathOverrideImportHook(['PIL'])
   self.assertEqual(hook, hook.find_module('PIL'))
   del sys.modules['PIL']
   hooked_pil = hook.load_module('PIL')
   self.assertEqual(hooked_pil.__file__, PIL.__file__)
   self.assertEqual(hooked_pil.__path__, PIL.__path__)
   self.assertEqual(hooked_pil.__loader__, hook)
   self.assertFalse(hook.extra_accessible_paths)
   self.assertEqual([os.path.dirname(self.saved_pil.__file__)],
                    hook.extra_sys_paths)
コード例 #3
0
 def test_package_success(self):
     hook = sandbox.PathOverrideImportHook({'lxml'})
     self.assertEqual(hook, hook.find_module('lxml'))
     del sys.modules['lxml']
     hooked_lxml = hook.load_module('lxml')
     self.assertEqual(hooked_lxml.__file__, lxml.__file__)
     self.assertEqual(hooked_lxml.__path__, lxml.__path__)
     self.assertEqual(hooked_lxml.__loader__, hook)
     self.assertItemsEqual([
         os.path.dirname(self.saved_lxml.__file__),
         os.path.dirname(self.saved_cssselect.__file__)
     ], hook.extra_accessible_paths)
     self.assertFalse(hook.extra_sys_paths)
コード例 #4
0
ファイル: sandbox_test.py プロジェクト: girum11/hang
 def test_import_alread_in_sys_modules(self):
   hook = sandbox.PathOverrideImportHook(['lxml'])
   self.assertEqual(os, hook.load_module('os'))
コード例 #5
0
ファイル: sandbox_test.py プロジェクト: girum11/hang
 def test_module_not_installed(self):
   hook = sandbox.PathOverrideImportHook(['foo'])
   self.assertFalse(hook.find_module('foo'))
   self.assertFalse(hook.extra_accessible_paths)
   self.assertFalse(hook.extra_sys_paths)
コード例 #6
0
ファイル: sandbox_test.py プロジェクト: girum11/hang
 def test_disabled_modules(self):
   hook = sandbox.PathOverrideImportHook(['lxml'])
   self.assertFalse(hook.find_module('lxml.foo'))
   self.assertFalse(hook.find_module('numpy'))
   self.assertFalse(hook.find_module('os'))