summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/localrepocache.py12
-rw-r--r--morphlib/localrepocache_tests.py11
2 files changed, 23 insertions, 0 deletions
diff --git a/morphlib/localrepocache.py b/morphlib/localrepocache.py
index 9aef13e4..a51a9ead 100644
--- a/morphlib/localrepocache.py
+++ b/morphlib/localrepocache.py
@@ -113,6 +113,15 @@ class LocalRepoCache(object):
except urllib2.URLError:
return False
+ def _mkdir(self, dirname): # pragma: no cover
+ '''Create a directory.
+
+ This method is meant to be overridden by unit tests.
+
+ '''
+
+ os.mkdir(dirname)
+
def _remove(self, filename): # pragma: no cover
'''Remove given file.
@@ -171,6 +180,9 @@ class LocalRepoCache(object):
'''
+ if not self._exists(self._cachedir):
+ self._mkdir(self._cachedir)
+
for repourl, path in self._base_iterate(reponame):
if self._exists(path):
break
diff --git a/morphlib/localrepocache_tests.py b/morphlib/localrepocache_tests.py
index 6ab5d7c5..72f000f9 100644
--- a/morphlib/localrepocache_tests.py
+++ b/morphlib/localrepocache_tests.py
@@ -40,6 +40,7 @@ class LocalRepoCacheTests(unittest.TestCase):
self.lrc._git = self.fake_git
self.lrc._exists = self.fake_exists
self.lrc._fetch = self.not_found
+ self.lrc._mkdir = self.fake_mkdir
self.lrc._remove = self.fake_remove
def fake_git(self, args):
@@ -57,6 +58,9 @@ class LocalRepoCacheTests(unittest.TestCase):
def fake_exists(self, filename):
return filename in self.cache
+ def fake_mkdir(self, dirname):
+ self.cache.add(dirname)
+
def fake_remove(self, filename):
self.removed.append(filename)
@@ -84,6 +88,13 @@ class LocalRepoCacheTests(unittest.TestCase):
self.assertTrue(self.lrc.has_repo(self.reponame))
self.assertTrue(self.lrc.has_repo(self.repourl))
+ def test_cachedir_does_not_exist_initially(self):
+ self.assertFalse(self.cachedir in self.cache)
+
+ def test_creates_cachedir_if_missing(self):
+ self.lrc.cache_repo(self.repourl)
+ self.assertTrue(self.cachedir in self.cache)
+
def test_happily_caches_same_repo_twice(self):
self.lrc.cache_repo(self.repourl)
self.lrc.cache_repo(self.repourl)