diff --git a/casimport/__init__.py b/casimport/__init__.py index 52b2693..bfcb79d 100644 --- a/casimport/__init__.py +++ b/casimport/__init__.py @@ -66,6 +66,12 @@ class CASFinder(MetaPathFinder, Loader): sys.meta_path.append(self) + def disconnect(self): + try: + sys.meta_path.remove(self) + except ValueError: + pass + def register(self, loader): self._loaders.append(loader) @@ -98,12 +104,26 @@ import unittest class Test(unittest.TestCase): def test_casimport(self): + # That a CASFinder f = CASFinder() + + # when registering the fixtures directory f.register(FileDirCAS(os.path.join(os.path.dirname(__file__), '..', 'fixtures'))) import cas + # can import the function from cas.v1_f_330884aa2febb5e19fb7194ec6a69ed11dd3d77122f1a5175ee93e73cf0161c3 import hello name = 'Olof' + # and run the code self.assertEqual(hello(name), 'hello ' + name) + + # and when finished, can disconnect + f.disconnect() + + # and is no longer in the meta_path + self.assertNotIn(f, sys.meta_path) + + # and when disconnected as second time, nothing happens + f.disconnect()