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