diff --git a/casimport/__init__.py b/casimport/__init__.py index 13520c0..c290e92 100644 --- a/casimport/__init__.py +++ b/casimport/__init__.py @@ -144,6 +144,7 @@ class FileDirCAS(object): def __init__(self, path): self._path = pathlib.Path(path) + self._path.mkdir(exist_ok=True) self._hashes = {} def refresh_dir(self): @@ -343,10 +344,10 @@ class CASFinder(MetaPathFinder, Loader): def defaultinit(casf): basedir = pathlib.Path.home() / '.casimport' + basedir.mkdir(exist_ok=True) conffile = basedir / 'casimport.conf' if not conffile.exists(): - basedir.mkdir(exist_ok=True) import casimport with importlib.resources.path(casimport, 'default.conf') as defconf: @@ -434,6 +435,12 @@ class Test(unittest.TestCase): shutil.rmtree(self.basetempdir) self.tempdir = None + def test_filedircas(self): + cachedir = self.tempdir / 'cache' + fd = FileDirCAS(cachedir) + + self.assertTrue(cachedir.exists()) + def test_filedircas_limit_refresh(self): # XXX - only refresh when the dir has changed, and each # file has changed @@ -529,7 +536,8 @@ class Test(unittest.TestCase): # setup the cache temphome = self.tempdir / 'home' temphome.mkdir() - cachedir = temphome / '.casimport_cache' + cachedir = temphome / '.casimport' / 'cache' + cachedir.mkdir(parents=True) # add the test module's path fixdir = str(self.fixtures) @@ -540,11 +548,7 @@ class Test(unittest.TestCase): with CASFinder() as f, \ tempattrset(sys.modules[__name__], 'load_mod_aliases', f.load_mod_aliases): - defaultinit(f) - - # XXX - fix this so this is properly - # used. It's using other methods to - # work currently + f.register(FileDirCAS(cachedir)) # and that hello.py is in the cache shutil.copy(self.fixtures / 'hello.py', @@ -588,6 +592,8 @@ class Test(unittest.TestCase): f.register(fakeipfsloader) + self.assertNotIn('randpkg', sys.modules) + # that the import is successful import randpkg