[PATCH 4/6] lac_tests: Cover list and delete

Richard Maw richard.maw at codethink.co.uk
Fri Jun 7 18:04:07 BST 2013


---
 morphlib/localartifactcache.py       |    4 ++--
 morphlib/localartifactcache_tests.py |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/morphlib/localartifactcache.py b/morphlib/localartifactcache.py
index d8abf2a..76d085d 100644
--- a/morphlib/localartifactcache.py
+++ b/morphlib/localartifactcache.py
@@ -116,7 +116,7 @@ class LocalArtifactCache(object):
             for basename in basenames:
                 os.remove(os.path.join(dirname, basename))
 
-    def list_contents(self): # pragma: no cover
+    def list_contents(self):
         '''Return the set of sources cached and related information.
 
            returns a [(cache_key, set(artifacts), last_used)]
@@ -137,7 +137,7 @@ class LocalArtifactCache(object):
                 for cache_key, info in contents.iteritems())
 
 
-    def remove(self, cachekey): # pragma: no cover
+    def remove(self, cachekey):
         '''Remove all artifacts associated with the given cachekey.'''
         for dirpath, dirnames, filenames in os.walk(self.cachedir):
             for filename in filenames:
diff --git a/morphlib/localartifactcache_tests.py b/morphlib/localartifactcache_tests.py
index 10f3ab6..082b926 100644
--- a/morphlib/localartifactcache_tests.py
+++ b/morphlib/localartifactcache_tests.py
@@ -157,3 +157,35 @@ class LocalArtifactCacheTests(unittest.TestCase):
         cache.clear()
         self.assertFalse(cache.has(self.runtime_artifact))
 
+    def test_put_artifacts_and_list_them_afterwards(self):
+        cache = morphlib.localartifactcache.LocalArtifactCache(
+            self.tempdir.dirname)
+
+        handle = cache.put(self.runtime_artifact)
+        handle.write('runtime')
+        handle.close()
+
+        self.assertTrue(len(list(cache.list_contents())) == 1)
+
+        handle = cache.put(self.devel_artifact)
+        handle.write('devel')
+        handle.close()
+
+        self.assertTrue(len(list(cache.list_contents())) == 1)
+
+    def test_put_artifacts_and_remove_them_afterwards(self):
+        cache = morphlib.localartifactcache.LocalArtifactCache(
+            self.tempdir.dirname)
+
+        handle = cache.put(self.runtime_artifact)
+        handle.write('runtime')
+        handle.close()
+
+        handle = cache.put(self.devel_artifact)
+        handle.write('devel')
+        handle.close()
+
+        key = list(cache.list_contents())[0][0]
+        cache.remove(key)
+
+        self.assertTrue(len(list(cache.list_contents())) == 0)
-- 
1.7.10.4




More information about the baserock-dev mailing list