summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/localartifactcache.py4
-rw-r--r--morphlib/localartifactcache_tests.py32
2 files changed, 34 insertions, 2 deletions
diff --git a/morphlib/localartifactcache.py b/morphlib/localartifactcache.py
index d8abf2ad..76d085d1 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 10f3ab6b..082b926a 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)