From 862b372617ba7c7b52593194fcf27942a230bd3c Mon Sep 17 00:00:00 2001 From: Eduardo Robles Elvira Date: Thu, 1 Aug 2013 10:55:44 +0200 Subject: [PATCH] adding unit tests for filter function --- testing/test_deltatar.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) diff --git a/testing/test_deltatar.py b/testing/test_deltatar.py index 4368ba8..b844beb 100644 --- a/testing/test_deltatar.py +++ b/testing/test_deltatar.py @@ -321,6 +321,86 @@ class DeltaTarTest(BaseTest): assert not os.path.exists("./source_dir/test/huge") assert not os.path.exists("./source_dir/big") + def test_create_filter_func(self): + ''' + Tests create backup basic filtering. + ''' + visited_paths = [] + def filter_func(visited_paths, path): + if path not in visited_paths: + visited_paths.append(path) + return True + + filter_func = partial(filter_func, visited_paths) + deltatar = DeltaTar(mode=self.MODE, password=self.PASSWORD, + logger=self.consoleLogger, + included_files=["/test", "/small"], + excluded_files=["/test/huge"], + filter_func=filter_func) + + # create first backup + deltatar.create_full_backup( + source_path="source_dir", + backup_path="backup_dir") + + assert os.path.exists("backup_dir") + shutil.rmtree("source_dir") + + tar_filename = deltatar.volume_name_func('backup_dir', True, 0) + tar_path = os.path.join("backup_dir", tar_filename) + + deltatar.restore_backup(target_path="source_dir", + backup_tar_path=tar_path) + assert visited_paths == [ + '/small', + '/test', + '/test/huge2', + '/test/test2' + ] + + def test_create_filter_out_func(self): + ''' + Tests create backup basic filtering. + ''' + visited_paths = [] + def filter_func(visited_paths, path): + ''' + Filter out everything + ''' + if path not in visited_paths: + visited_paths.append(path) + return False + + filter_func = partial(filter_func, visited_paths) + deltatar = DeltaTar(mode=self.MODE, password=self.PASSWORD, + logger=self.consoleLogger, + included_files=["/test", "/small"], + excluded_files=["/test/huge"], + filter_func=filter_func) + + # create first backup + deltatar.create_full_backup( + source_path="source_dir", + backup_path="backup_dir") + + assert os.path.exists("backup_dir") + shutil.rmtree("source_dir") + + tar_filename = deltatar.volume_name_func('backup_dir', True, 0) + tar_path = os.path.join("backup_dir", tar_filename) + + deltatar.restore_backup(target_path="source_dir", + backup_tar_path=tar_path) + assert visited_paths == [ + '/small', + '/test' + ] + + # check that effectively no file was backed up + assert not os.path.exists("./source_dir/small") + assert not os.path.exists("./source_dir/big") + assert not os.path.exists("./source_dir/test") + class DeltaTar2Test(DeltaTarTest): ''' Same as DeltaTar but with specific ":" mode -- 1.7.1