Browse Source

add a few comments, and a disconnect method

main
John-Mark Gurney 4 years ago
parent
commit
523e9498fb
1 changed files with 20 additions and 0 deletions
  1. +20
    -0
      casimport/__init__.py

+ 20
- 0
casimport/__init__.py View File

@@ -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()

Loading…
Cancel
Save