Commit 570d612b authored by ben's avatar ben

Added testcases for gzipped increments, fixed some increment test cases.


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@24 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent c25339ca
...@@ -73,6 +73,8 @@ def InternalBackup(source_local, dest_local, src_dir, dest_dir, ...@@ -73,6 +73,8 @@ def InternalBackup(source_local, dest_local, src_dir, dest_dir,
% (SourceDir, dest_dir) % (SourceDir, dest_dir)
rpin, rpout = SetConnections.InitRPs([src_dir, dest_dir], remote_schema) 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().Backup(rpin, rpout)
_get_main().cleanup() _get_main().cleanup()
......
...@@ -12,6 +12,7 @@ def getrp(ending): ...@@ -12,6 +12,7 @@ def getrp(ending):
return RPath(lc, "testfiles/various_file_types/" + ending) return RPath(lc, "testfiles/various_file_types/" + ending)
rf = getrp("regular_file") rf = getrp("regular_file")
rf2 = getrp("two_hardlinked_files1")
exec1 = getrp("executable") exec1 = getrp("executable")
exec2 = getrp("executable2") exec2 = getrp("executable2")
sig = getrp("regular_file.sig") sig = getrp("regular_file.sig")
...@@ -22,12 +23,17 @@ sym = getrp("symbolic_link") ...@@ -22,12 +23,17 @@ sym = getrp("symbolic_link")
nothing = getrp("nothing") nothing = getrp("nothing")
target = RPath(lc, "testfiles/out") target = RPath(lc, "testfiles/out")
out2 = RPath(lc, "testfiles/out2")
out_gz = RPath(lc, "testfiles/out.gz")
Time.setprevtime(999424113.24931) Time.setprevtime(999424113.24931)
prevtimestr = "2001-09-02T02:48:33-07:00" prevtimestr = "2001-09-02T02:48:33-07:00"
t_pref = "testfiles/out.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" 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): class inctest(unittest.TestCase):
"""Test the incrementRP function""" """Test the incrementRP function"""
def setUp(self): def setUp(self):
...@@ -35,9 +41,15 @@ class inctest(unittest.TestCase): ...@@ -35,9 +41,15 @@ class inctest(unittest.TestCase):
def testreg(self): def testreg(self):
"""Test increment of regular files""" """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) 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) assert RPath.cmp_attribs(rpd, exec1)
rpd.delete() rpd.delete()
...@@ -50,20 +62,47 @@ class inctest(unittest.TestCase): ...@@ -50,20 +62,47 @@ class inctest(unittest.TestCase):
def testsnapshot(self): def testsnapshot(self):
"""Test making of a snapshot""" """Test making of a snapshot"""
Inc.Increment(rf, sym, target) Globals.compression = None
rp = RPath(lc, t_pref + ".snapshot") rp = RPath(lc, t_pref + ".snapshot")
if rp.lstat(): rp.delete()
Inc.Increment(rf, sym, target)
rp.setdata()
assert rp.lstat() assert rp.lstat()
assert RPath.cmp_attribs(rp, sym) assert RPath.cmp_attribs(rp, sym)
assert RPath.cmp(rp, sym) assert RPath.cmp(rp, sym)
rp.delete() rp.delete()
Inc.Increment(sym, rf, target)
rp = RPath(lc, t_pref + ".snapshot") rp = RPath(lc, t_pref + ".snapshot")
if rp.lstat(): rp.delete()
Inc.Increment(sym, rf, target)
rp.setdata()
assert rp.lstat() assert rp.lstat()
assert RPath.cmp_attribs(rp, rf) assert RPath.cmp_attribs(rp, rf)
assert RPath.cmp(rp, rf) assert RPath.cmp(rp, rf)
rp.delete() 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): def testdir(self):
"""Test increment on dir""" """Test increment on dir"""
Inc.Increment(sym, dir, target) Inc.Increment(sym, dir, target)
...@@ -76,25 +115,51 @@ class inctest(unittest.TestCase): ...@@ -76,25 +115,51 @@ class inctest(unittest.TestCase):
rp.delete() rp.delete()
target.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") def testGzipRegexp(self):
inc2rp = RPath(lc, "testfiles/increment2") """Here a .gz file shouldn't be compressed"""
inc3rp = RPath(lc, "testfiles/increment3") Globals.compression = 1
inc4rp = RPath(lc, "testfiles/increment4") RPath.copy(rf, out_gz)
rpout = RPath(lc, "testfiles/output") assert out_gz.lstat()
#class IncTreeTest(unittest.TestCase): rp = RPath(lc, t_pref + '.diff')
# def setUp(self): if rp.lstat(): rp.delete()
# os.system("./myrm testfiles/output*")
# def testinctree(self): Inc.Increment(rf, out_gz, target)
# """Test tree incrementing""" rp.setdata()
# rpt1 = RPTriple(inc2rp, inc1rp, rpout) assert rp.lstat()
# rpt2 = RPTriple(inc3rp, inc2rp, rpout) assert RPath.cmp_attribs(rp, out_gz)
# rpt3 = RPTriple(inc4rp, inc3rp, rpout) Rdiff.patch_action(rf, rp, out2).execute()
# for rpt in [rpt1, rpt2, rpt3]: assert RPath.cmp(out_gz, out2)
# Time.setprevtime(Time.prevtime + 10000) rp.delete()
# Inc.IncrementTTree(TripleTree(rpt).destructive_stepping()) out2.delete()
# Time.setprevtime(999424113.24931) out_gz.delete()
if __name__ == "__main__": unittest.main() if __name__ == '__main__': unittest.main()
...@@ -37,7 +37,7 @@ class RdiffTest(unittest.TestCase): ...@@ -37,7 +37,7 @@ class RdiffTest(unittest.TestCase):
def testRdiffDeltaPatch(self): def testRdiffDeltaPatch(self):
"""Test making deltas and patching files""" """Test making deltas and patching files"""
rplist = [self.basis, self.new, self.delta, rplist = [self.basis, self.new, self.delta,
self.signature, self.output] self.signature, self.output]
for rp in rplist: for rp in rplist:
if rp.lstat(): rp.delete() if rp.lstat(): rp.delete()
...@@ -55,6 +55,31 @@ class RdiffTest(unittest.TestCase): ...@@ -55,6 +55,31 @@ class RdiffTest(unittest.TestCase):
assert RPath.cmp(self.new, self.output) assert RPath.cmp(self.new, self.output)
map(RPath.delete, rplist) 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): def testWriteDelta(self):
"""Test write delta feature of rdiff""" """Test write delta feature of rdiff"""
rplist = [self.basis, self.new, self.delta, self.output] rplist = [self.basis, self.new, self.delta, self.output]
...@@ -69,6 +94,25 @@ class RdiffTest(unittest.TestCase): ...@@ -69,6 +94,25 @@ class RdiffTest(unittest.TestCase):
assert RPath.cmp(self.new, self.output) assert RPath.cmp(self.new, self.output)
map(RPath.delete, rplist) 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): def testRdiffRename(self):
"""Rdiff replacing original file with patch outfile""" """Rdiff replacing original file with patch outfile"""
rplist = [self.basis, self.new, self.delta, self.signature] rplist = [self.basis, self.new, self.delta, self.signature]
......
...@@ -131,6 +131,15 @@ class PathSetter(unittest.TestCase): ...@@ -131,6 +131,15 @@ class PathSetter(unittest.TestCase):
class IncrementTest1(unittest.TestCase): class IncrementTest1(unittest.TestCase):
dirlist = ["testfiles/increment1", "testfiles/increment2", dirlist = ["testfiles/increment1", "testfiles/increment2",
"testfiles/increment3", "testfiles/increment4"] "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): def testLocalinc(self):
"""Test self.incrementing, and then restoring, local""" """Test self.incrementing, and then restoring, local"""
......
...@@ -225,6 +225,47 @@ class FileIO(RPathTest): ...@@ -225,6 +225,47 @@ class FileIO(RPathTest):
fp_input.close() fp_input.close()
rp.delete() 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): class FileCopying(RPathTest):
"""Test file copying and comparison""" """Test file copying and comparison"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment