Beispiel #1
0
 def test_loader_methods(self):
     t = TempFS()
     self._init_modules(t)
     ih = FSImportHook(t)
     sys.meta_path.append(ih)
     try:
         self.assertEquals(ih.find_module("fsih_hello"), ih)
         self.assertEquals(ih.find_module("fsih_helo"), None)
         self.assertEquals(ih.find_module("fsih_pkg"), ih)
         self.assertEquals(ih.find_module("fsih_pkg.sub1"), ih)
         self.assertEquals(ih.find_module("fsih_pkg.sub2"), ih)
         self.assertEquals(ih.find_module("fsih_pkg.sub3"), None)
         m = ih.load_module("fsih_hello")
         self.assertEquals(m.message, "hello world!")
         self.assertRaises(ImportError, ih.load_module, "fsih_helo")
         m = ih.load_module("fsih_pkg.sub1")
         self.assertEquals(m.message, "hello world!")
         self.assertEquals(m.a, 42)
         m = ih.load_module("fsih_pkg.sub2")
         self.assertEquals(m.message, "hello world!")
         self.assertEquals(m.a, 42 * 2)
         self.assertRaises(ImportError, ih.load_module, "fsih_pkg.sub3")
     finally:
         sys.meta_path.remove(ih)
         t.close()
 def test_loader_methods(self):
     t = TempFS()
     self._init_modules(t)
     ih = FSImportHook(t)
     sys.meta_path.append(ih)
     try:
         self.assertEquals(ih.find_module("fsih_hello"),ih)
         self.assertEquals(ih.find_module("fsih_helo"),None)
         self.assertEquals(ih.find_module("fsih_pkg"),ih)
         self.assertEquals(ih.find_module("fsih_pkg.sub1"),ih)
         self.assertEquals(ih.find_module("fsih_pkg.sub2"),ih)
         self.assertEquals(ih.find_module("fsih_pkg.sub3"),None)
         m = ih.load_module("fsih_hello")
         self.assertEquals(m.message,"hello world!")
         self.assertRaises(ImportError,ih.load_module,"fsih_helo")
         m = ih.load_module("fsih_pkg.sub1")
         self.assertEquals(m.message,"hello world!")
         self.assertEquals(m.a,42)
         m = ih.load_module("fsih_pkg.sub2")
         self.assertEquals(m.message,"hello world!")
         self.assertEquals(m.a,42 * 2)
         self.assertRaises(ImportError,ih.load_module,"fsih_pkg.sub3")
     finally:
         sys.meta_path.remove(ih)
         t.close()
Beispiel #3
0
 def test_url_on_sys_path(self):
     t = TempFS()
     zpath = t.getsyspath("modules.zip")
     z = ZipFS(zpath, "w")
     self._init_modules(z)
     z.close()
     z = ZipFS(zpath, "r")
     assert z.isfile("fsih_hello.py")
     z.close()
     sys.path.append("zip://" + zpath)
     FSImportHook.install()
     try:
         self._check_imports_are_working()
     finally:
         sys.path_hooks.remove(FSImportHook)
         sys.path.pop()
         t.close()
 def test_url_on_sys_path(self):
     t = TempFS()
     zpath = t.getsyspath("modules.zip")
     z = ZipFS(zpath,"w")
     self._init_modules(z)
     z.close()
     z = ZipFS(zpath,"r")
     assert z.isfile("fsih_hello.py")
     z.close()
     sys.path.append("zip://" + zpath)
     FSImportHook.install()
     try:
         self._check_imports_are_working()
     finally:
         sys.path_hooks.remove(FSImportHook)
         sys.path.pop()
         t.close()
Beispiel #5
0
 def test_importer_on_meta_path(self):
     t = TempFS()
     self._init_modules(t)
     ih = FSImportHook(t)
     sys.meta_path.append(ih)
     try:
         self._check_imports_are_working()
     finally:
         sys.meta_path.remove(ih)
         t.close()