summaryrefslogtreecommitdiff
path: root/obnam
diff options
context:
space:
mode:
authorLars Wirzenius <liw@gytha>2008-04-20 21:29:06 +0300
committerLars Wirzenius <liw@gytha>2008-04-20 21:29:06 +0300
commit2b416d957c9a86d4db0ec12fc1236c788a4b2c4b (patch)
tree623cbba2f6244a0ba755963927bc0f101afa8eae /obnam
parent67170467426779de6cd925b544fe2140e65a27bb (diff)
downloadobnam-2b416d957c9a86d4db0ec12fc1236c788a4b2c4b.tar.gz
Implemented Application.get_file_in_previous_generation.
Diffstat (limited to 'obnam')
-rw-r--r--obnam/app.py8
-rw-r--r--obnam/appTests.py32
2 files changed, 40 insertions, 0 deletions
diff --git a/obnam/app.py b/obnam/app.py
index 19e2cc54..a84ea939 100644
--- a/obnam/app.py
+++ b/obnam/app.py
@@ -241,6 +241,14 @@ class Application:
return unchanged
+ def get_file_in_previous_generation(self, pathname):
+ """Return non-directory file in previous generation, or None."""
+ gen = self.get_previous_generation()
+ if gen:
+ return self.get_store().lookup_file(gen, pathname)
+ else:
+ return None
+
def add_to_filegroup(self, fg, filename):
"""Add a file to a filegroup."""
self._context.progress.update_current_action(filename)
diff --git a/obnam/appTests.py b/obnam/appTests.py
index 290b4850..4e6629f0 100644
--- a/obnam/appTests.py
+++ b/obnam/appTests.py
@@ -426,6 +426,38 @@ class ApplicationGetDirInPreviousGenerationTests(unittest.TestCase):
self.failUnlessEqual(dir.get_name(), "pink")
+class ApplicationGetFileInPreviousGenerationTests(unittest.TestCase):
+
+ class MockStore:
+
+ def __init__(self):
+ self.dict = {
+ "pink": obnam.cmp.Component(obnam.cmp.FILE, [])
+ }
+
+ def lookup_file(self, gen, pathname):
+ return self.dict.get(pathname, None)
+
+ def setUp(self):
+ context = obnam.context.Context()
+ self.app = obnam.Application(context)
+ self.app._store = self.MockStore()
+ self.app.set_previous_generation("prevgen")
+
+ def testReturnsNoneIfPreviousGenerationIsUnset(self):
+ self.app.set_previous_generation(None)
+ self.failUnlessEqual(self.app.get_file_in_previous_generation("xx"),
+ None)
+
+ def testReturnsNoneIfFileDidNotExist(self):
+ self.failUnlessEqual(self.app.get_file_in_previous_generation("xx"),
+ None)
+
+ def testReturnsFileComponentIfFileDidExist(self):
+ cmp = self.app.get_file_in_previous_generation("pink")
+ self.failUnlessEqual(cmp.get_kind(), obnam.cmp.FILE)
+
+
class ApplicationSelectFilesToBackUpTests(unittest.TestCase):
class MockStore: