From 0c361a33a9a4b009b3ada9dd88ccef43e299ed65 Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 25 Mar 2002 07:52:04 +0000 Subject: Added testcases for gzipped increments, fixed some increment test cases. git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@24 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109 --- rdiff-backup/testing/commontest.py | 2 + rdiff-backup/testing/incrementtest.py | 109 ++++++++++++++++++++++++++------- rdiff-backup/testing/rdifftest.py | 46 +++++++++++++- rdiff-backup/testing/regressiontest.py | 9 +++ rdiff-backup/testing/rpathtest.py | 41 +++++++++++++ 5 files changed, 184 insertions(+), 23 deletions(-) (limited to 'rdiff-backup') diff --git a/rdiff-backup/testing/commontest.py b/rdiff-backup/testing/commontest.py index ac6f109..3ce6c0c 100644 --- a/rdiff-backup/testing/commontest.py +++ b/rdiff-backup/testing/commontest.py @@ -73,6 +73,8 @@ def InternalBackup(source_local, dest_local, src_dir, dest_dir, % (SourceDir, dest_dir) rpin, rpout = SetConnections.InitRPs([src_dir, dest_dir], remote_schema) + Globals.postset_regexp('no_compression_regexp', + Globals.no_compression_regexp_string, re.I) _get_main().Backup(rpin, rpout) _get_main().cleanup() diff --git a/rdiff-backup/testing/incrementtest.py b/rdiff-backup/testing/incrementtest.py index d6cd17f..95c6b5b 100644 --- a/rdiff-backup/testing/incrementtest.py +++ b/rdiff-backup/testing/incrementtest.py @@ -12,6 +12,7 @@ def getrp(ending): return RPath(lc, "testfiles/various_file_types/" + ending) rf = getrp("regular_file") +rf2 = getrp("two_hardlinked_files1") exec1 = getrp("executable") exec2 = getrp("executable2") sig = getrp("regular_file.sig") @@ -22,12 +23,17 @@ sym = getrp("symbolic_link") nothing = getrp("nothing") target = RPath(lc, "testfiles/out") +out2 = RPath(lc, "testfiles/out2") +out_gz = RPath(lc, "testfiles/out.gz") Time.setprevtime(999424113.24931) prevtimestr = "2001-09-02T02:48:33-07:00" t_pref = "testfiles/out.2001-09-02T02:48:33-07:00" t_diff = "testfiles/out.2001-09-02T02:48:33-07:00.diff" +Globals.no_compression_regexp = \ + re.compile(Globals.no_compression_regexp_string, re.I) + class inctest(unittest.TestCase): """Test the incrementRP function""" def setUp(self): @@ -35,9 +41,15 @@ class inctest(unittest.TestCase): def testreg(self): """Test increment of regular files""" - Inc.Increment(rf, exec1, target) + Globals.compression = None + target.setdata() + if target.lstat(): target.delete() rpd = RPath(lc, t_diff) - assert rpd.isreg() + if rpd.lstat(): rpd.delete() + + Inc.Increment(rf, exec1, target) + rpd.setdata() + assert rpd.isreg(), rpd assert RPath.cmp_attribs(rpd, exec1) rpd.delete() @@ -50,20 +62,47 @@ class inctest(unittest.TestCase): def testsnapshot(self): """Test making of a snapshot""" - Inc.Increment(rf, sym, target) + Globals.compression = None rp = RPath(lc, t_pref + ".snapshot") + if rp.lstat(): rp.delete() + Inc.Increment(rf, sym, target) + rp.setdata() assert rp.lstat() assert RPath.cmp_attribs(rp, sym) assert RPath.cmp(rp, sym) rp.delete() - Inc.Increment(sym, rf, target) rp = RPath(lc, t_pref + ".snapshot") + if rp.lstat(): rp.delete() + Inc.Increment(sym, rf, target) + rp.setdata() assert rp.lstat() assert RPath.cmp_attribs(rp, rf) assert RPath.cmp(rp, rf) rp.delete() + def testGzipsnapshot(self): + """Test making a compressed snapshot""" + Globals.compression = 1 + rp = RPath(lc, t_pref + ".snapshot") + if rp.lstat(): rp.delete() + Inc.Increment(rf, sym, target) + rp.setdata() + assert rp.lstat() + assert RPath.cmp_attribs(rp, sym) + assert RPath.cmp(rp, sym) + rp.delete() + + rp = RPath(lc, t_pref + ".snapshot.gz") + if rp.lstat(): rp.delete() + Inc.Increment(sym, rf, target) + rp.setdata() + + assert rp.lstat() + assert RPath.cmp_attribs(rp, rf) + assert RPath.cmpfileobj(rp.open("rb", 1), rf.open("rb")) + rp.delete() + def testdir(self): """Test increment on dir""" Inc.Increment(sym, dir, target) @@ -76,25 +115,51 @@ class inctest(unittest.TestCase): rp.delete() target.delete() + def testDiff(self): + """Test making diffs""" + Globals.compression = None + rp = RPath(lc, t_pref + '.diff') + if rp.lstat(): rp.delete() + Inc.Increment(rf, rf2, target) + rp.setdata() + assert rp.lstat() + assert RPath.cmp_attribs(rp, rf2) + Rdiff.patch_action(rf, rp, out2).execute() + assert RPath.cmp(rf2, out2) + rp.delete() + out2.delete() + + def testGzipDiff(self): + """Test making gzipped diffs""" + Globals.compression = 1 + rp = RPath(lc, t_pref + '.diff.gz') + if rp.lstat(): rp.delete() + Inc.Increment(rf, rf2, target) + rp.setdata() + assert rp.lstat() + assert RPath.cmp_attribs(rp, rf2) + Rdiff.patch_action(rf, rp, out2, delta_compressed = 1).execute() + assert RPath.cmp(rf2, out2) + rp.delete() + out2.delete() -inc1rp = RPath(lc, "testfiles/increment1") -inc2rp = RPath(lc, "testfiles/increment2") -inc3rp = RPath(lc, "testfiles/increment3") -inc4rp = RPath(lc, "testfiles/increment4") -rpout = RPath(lc, "testfiles/output") + def testGzipRegexp(self): + """Here a .gz file shouldn't be compressed""" + Globals.compression = 1 + RPath.copy(rf, out_gz) + assert out_gz.lstat() -#class IncTreeTest(unittest.TestCase): -# def setUp(self): -# os.system("./myrm testfiles/output*") + rp = RPath(lc, t_pref + '.diff') + if rp.lstat(): rp.delete() -# def testinctree(self): -# """Test tree incrementing""" -# rpt1 = RPTriple(inc2rp, inc1rp, rpout) -# rpt2 = RPTriple(inc3rp, inc2rp, rpout) -# rpt3 = RPTriple(inc4rp, inc3rp, rpout) -# for rpt in [rpt1, rpt2, rpt3]: -# Time.setprevtime(Time.prevtime + 10000) -# Inc.IncrementTTree(TripleTree(rpt).destructive_stepping()) -# Time.setprevtime(999424113.24931) + Inc.Increment(rf, out_gz, target) + rp.setdata() + assert rp.lstat() + assert RPath.cmp_attribs(rp, out_gz) + Rdiff.patch_action(rf, rp, out2).execute() + assert RPath.cmp(out_gz, out2) + rp.delete() + out2.delete() + out_gz.delete() -if __name__ == "__main__": unittest.main() +if __name__ == '__main__': unittest.main() diff --git a/rdiff-backup/testing/rdifftest.py b/rdiff-backup/testing/rdifftest.py index 471eab7..1c307ab 100644 --- a/rdiff-backup/testing/rdifftest.py +++ b/rdiff-backup/testing/rdifftest.py @@ -37,7 +37,7 @@ class RdiffTest(unittest.TestCase): def testRdiffDeltaPatch(self): """Test making deltas and patching files""" rplist = [self.basis, self.new, self.delta, - self.signature, self.output] + self.signature, self.output] for rp in rplist: if rp.lstat(): rp.delete() @@ -55,6 +55,31 @@ class RdiffTest(unittest.TestCase): assert RPath.cmp(self.new, self.output) map(RPath.delete, rplist) + def testRdiffDeltaPatchGzip(self): + """Same as above by try gzipping patches""" + rplist = [self.basis, self.new, self.delta, + self.signature, self.output] + for rp in rplist: + if rp.lstat(): rp.delete() + + MakeRandomFile(self.basis.path) + MakeRandomFile(self.new.path) + map(RPath.setdata, [self.basis, self.new]) + assert self.basis.lstat() and self.new.lstat() + self.signature.write_from_fileobj(Rdiff.get_signature(self.basis)) + assert self.signature.lstat() + self.delta.write_from_fileobj(Rdiff.get_delta(self.signature, + self.new)) + assert self.delta.lstat() + os.system("gzip " + self.delta.path) + os.system("mv %s %s" % (self.delta.path + ".gz", self.delta.path)) + self.delta.setdata() + + Rdiff.patch_action(self.basis, self.delta, self.output, + delta_compressed = 1).execute() + assert RPath.cmp(self.new, self.output) + map(RPath.delete, rplist) + def testWriteDelta(self): """Test write delta feature of rdiff""" rplist = [self.basis, self.new, self.delta, self.output] @@ -69,6 +94,25 @@ class RdiffTest(unittest.TestCase): assert RPath.cmp(self.new, self.output) map(RPath.delete, rplist) + def testWriteDeltaGzip(self): + """Same as above but delta is written gzipped""" + rplist = [self.basis, self.new, self.delta, self.output] + MakeRandomFile(self.basis.path) + MakeRandomFile(self.new.path) + map(RPath.setdata, [self.basis, self.new]) + assert self.basis.lstat() and self.new.lstat() + delta_gz = RPath(self.delta.conn, self.delta.path + ".gz") + if delta_gz.lstat(): delta_gz.delete() + + Rdiff.write_delta(self.basis, self.new, delta_gz, 1) + assert delta_gz.lstat() + os.system("gunzip " + delta_gz.path) + delta_gz.setdata() + self.delta.setdata() + Rdiff.patch_action(self.basis, self.delta, self.output).execute() + assert RPath.cmp(self.new, self.output) + map(RPath.delete, rplist) + def testRdiffRename(self): """Rdiff replacing original file with patch outfile""" rplist = [self.basis, self.new, self.delta, self.signature] diff --git a/rdiff-backup/testing/regressiontest.py b/rdiff-backup/testing/regressiontest.py index 354cbbb..ea90230 100644 --- a/rdiff-backup/testing/regressiontest.py +++ b/rdiff-backup/testing/regressiontest.py @@ -131,6 +131,15 @@ class PathSetter(unittest.TestCase): class IncrementTest1(unittest.TestCase): dirlist = ["testfiles/increment1", "testfiles/increment2", "testfiles/increment3", "testfiles/increment4"] + gzip_dirlist = ["testfiles/gzips/inc1", "testfiles/gzips/inc2"] + + def testLocalGzipinc(self): + """Local test small archive which exercises gzip options""" + BackupRestoreSeries(1, 1, self.gzip_dirlist) + + def testRemoteBothGzipinc(self): + """Remote test small archive which exercises gzip options""" + BackupRestoreSeries(None, None, self.gzip_dirlist) def testLocalinc(self): """Test self.incrementing, and then restoring, local""" diff --git a/rdiff-backup/testing/rpathtest.py b/rdiff-backup/testing/rpathtest.py index 0b28f14..9a24e6c 100644 --- a/rdiff-backup/testing/rpathtest.py +++ b/rdiff-backup/testing/rpathtest.py @@ -225,6 +225,47 @@ class FileIO(RPathTest): fp_input.close() rp.delete() + def testGzipWrite(self): + """Test writing of gzipped files""" + try: os.mkdir("testfiles/output") + except OSError: pass + rp_gz = RPath(self.lc, "testfiles/output/file.gz") + rp = RPath(self.lc, "testfiles/output/file") + if rp.lstat(): rp.delete() + s = "Hello, world!" + + fp_out = rp_gz.open("wb", compress = 1) + fp_out.write(s) + assert not fp_out.close() + assert not os.system("gunzip testfiles/output/file.gz") + fp_in = rp.open("rb") + assert fp_in.read() == s + fp_in.close() + + def testGzipRead(self): + """Test reading of gzipped files""" + try: os.mkdir("testfiles/output") + except OSError: pass + rp_gz = RPath(self.lc, "testfiles/output/file.gz") + if rp_gz.lstat(): rp_gz.delete() + rp = RPath(self.lc, "testfiles/output/file") + s = "Hello, world!" + + fp_out = rp.open("wb") + fp_out.write(s) + assert not fp_out.close() + rp.setdata() + assert rp.lstat() + + assert not os.system("gzip testfiles/output/file") + rp.setdata() + rp_gz.setdata() + assert not rp.lstat() + assert rp_gz.lstat() + fp_in = rp_gz.open("rb", compress = 1) + assert fp_in.read() == s + assert not fp_in.close() + class FileCopying(RPathTest): """Test file copying and comparison""" -- cgit v1.2.1