diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-01-02 12:48:25 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-01-02 12:48:25 +0000 |
commit | 5b39572858adfa97bae6b1f53d0de0f8cf451e4d (patch) | |
tree | 9777e8a55463b4223014ed024b751ab385ff5a44 | |
parent | 42b396f0d124c710b0eef4568e7fe65f6ccab869 (diff) | |
download | genbackupdata-5b39572858adfa97bae6b1f53d0de0f8cf451e4d.tar.gz |
Add test that right amount of data gets created.
-rwxr-xr-x | blackboxtest | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/blackboxtest b/blackboxtest index b9e5114..ee5ef30 100755 --- a/blackboxtest +++ b/blackboxtest @@ -32,8 +32,6 @@ import tempfile import traceback import unittest -import obnamlib - class GenbackupdataTestCase(unittest.TestCase): @@ -64,6 +62,9 @@ class GenbackupdataTestCase(unittest.TestCase): def tearDownHook(self): pass + def path(self, *relatives): + return os.path.join(self.tempdir, *relatives) + def mkdir(self, dirname): abs_dirname = os.path.join(self.tempdir, dirname) os.makedirs(abs_dirname) @@ -153,15 +154,17 @@ class GenbackupdataTestCase(unittest.TestCase): result.append(self.get_info(root, pathname)) return [x for x in result if x] - def open_store(self): - '''Open the store.''' - - fs = obnamlib.LocalFS(self.store) - s = obnamlib.Store(fs, obnamlib.DEFAULT_NODE_SIZE, - obnamlib.DEFAULT_UPLOAD_QUEUE_SIZE, - obnamlib.DEFAULT_LRU_SIZE) - s.open_client(self.client_name) - return s + def apparent_size(self, root): + '''Return sum of length of regular files in directory, recursively.''' + + size = 0 + for dirname, subdirs, filenames in os.walk(self.path(root)): + for filename in filenames: + pathname = self.path(dirname, filename) + st = os.lstat(pathname) + if stat.S_ISREG(st.st_mode): + size += st.st_size + return size def assert_equal_stat_fields(self, filename, stat1, stat2, fieldname): field1 = getattr(stat1, fieldname) @@ -232,6 +235,11 @@ class GenbackupdataTests(GenbackupdataTestCase): def test_returns_success_with_help_option(self): self.genbackupdata(['--help']) self.assertTrue(True) + + def test_creates_requested_amount_of_data(self): + kilobytes = 4096 + self.genbackupdata([self.path('data'), '--create=%dk' % kilobytes]) + self.assertEqual(self.apparent_size('data'), kilobytes * 1024) if __name__ == '__main__': |