|
@@ -66,6 +66,12 @@ class CASFinder(MetaPathFinder, Loader): |
|
|
|
|
|
|
|
|
sys.meta_path.append(self) |
|
|
sys.meta_path.append(self) |
|
|
|
|
|
|
|
|
|
|
|
def disconnect(self): |
|
|
|
|
|
try: |
|
|
|
|
|
sys.meta_path.remove(self) |
|
|
|
|
|
except ValueError: |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
def register(self, loader): |
|
|
def register(self, loader): |
|
|
self._loaders.append(loader) |
|
|
self._loaders.append(loader) |
|
|
|
|
|
|
|
@@ -98,12 +104,26 @@ import unittest |
|
|
|
|
|
|
|
|
class Test(unittest.TestCase): |
|
|
class Test(unittest.TestCase): |
|
|
def test_casimport(self): |
|
|
def test_casimport(self): |
|
|
|
|
|
# That a CASFinder |
|
|
f = CASFinder() |
|
|
f = CASFinder() |
|
|
|
|
|
|
|
|
|
|
|
# when registering the fixtures directory |
|
|
f.register(FileDirCAS(os.path.join(os.path.dirname(__file__), '..', 'fixtures'))) |
|
|
f.register(FileDirCAS(os.path.join(os.path.dirname(__file__), '..', 'fixtures'))) |
|
|
|
|
|
|
|
|
import cas |
|
|
import cas |
|
|
|
|
|
|
|
|
|
|
|
# can import the function |
|
|
from cas.v1_f_330884aa2febb5e19fb7194ec6a69ed11dd3d77122f1a5175ee93e73cf0161c3 import hello |
|
|
from cas.v1_f_330884aa2febb5e19fb7194ec6a69ed11dd3d77122f1a5175ee93e73cf0161c3 import hello |
|
|
|
|
|
|
|
|
name = 'Olof' |
|
|
name = 'Olof' |
|
|
|
|
|
# and run the code |
|
|
self.assertEqual(hello(name), 'hello ' + name) |
|
|
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() |