From: Eduardo Robles Elvira Date: Thu, 1 Aug 2013 08:55:44 +0000 (+0200) Subject: adding unit tests for filter function X-Git-Tag: v2.2~132 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=862b372617ba7c7b52593194fcf27942a230bd3c;p=python-delta-tar adding unit tests for filter function --- 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