From b15e549bbb866b292833d2527f065540205276e3 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 10 Aug 2017 14:39:40 +0200 Subject: [PATCH] track irrecoverable files in test_recover --- testing/test_recover.py | 31 +++++++++++++++++++------------ 1 files changed, 19 insertions(+), 12 deletions(-) diff --git a/testing/test_recover.py b/testing/test_recover.py index a5b37c4..5c84783 100644 --- a/testing/test_recover.py +++ b/testing/test_recover.py @@ -106,8 +106,8 @@ class RecoverTest (BaseTest): self.hash = dict () os.makedirs (src_path) for i in range (5): - f = "source_dir2/dummy_%rd" % i - self.hash [f] = self.create_file (f, 5 + i) + f = "dummy_%rd" % i + self.hash [f] = self.create_file ("%s/%s" % (src_path, f), 5 + i) dtar.create_full_backup \ (source_path=src_path, backup_path=bak_path) @@ -116,33 +116,40 @@ class RecoverTest (BaseTest): dtar.restore_backup(target_path=dst_path, backup_tar_path=backup_full) for key, value in self.hash.items (): - assert os.path.exists (key) - assert value == self.md5sum (key) + f = "%s/%s" % (dst_path, key) + assert os.path.exists (f) + assert value == self.md5sum (f) + shutil.rmtree (dst_path) shutil.rmtree (src_path) flip_bits (backup_full, gz_header_size (backup_full) + 1) # normal restore must fail curdir = os.getcwd () # not restored after below failure - with self.assertRaises (tarfile.ReadError): + with self.assertRaises (Exception) as cm: dtar.restore_backup(target_path=dst_path, backup_tar_path=backup_full) + assert type (cm.exception) in [ tarfile.CompressionError + , tarfile.ReadError + ] os.chdir (curdir) # but recover will succeed - dtar.recover_backup(target_path=dst_path, - backup_indexes_paths=[ - "%s/%s" % (bak_path, index_file) - ]) + failed = dtar.recover_backup(target_path=dst_path, + backup_indexes_paths=[ + "%s/%s" % (bak_path, index_file) + ]) + assert len (failed) == 1 # with one file missing missing = [] for key, value in self.hash.items (): - if os.path.exists (key): - assert value == self.md5sum (key) + kkey = "%s/%s" % (dst_path, key) + if os.path.exists (kkey): + assert value == self.md5sum (kkey) else: missing.append (key) assert len (missing) == 1 - shutil.rmtree (src_path) + shutil.rmtree (dst_path) -- 1.7.1