summaryrefslogtreecommitdiff
path: root/rdiff-backup/testing
diff options
context:
space:
mode:
authorbescoto <bescoto@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2005-10-31 04:53:31 +0000
committerbescoto <bescoto@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2005-10-31 04:53:31 +0000
commita5c03feacbbd9361eb3e2abe367b75529c83459b (patch)
treebcb8f86bf8cfc61bd771b6e45d557bdda7604e80 /rdiff-backup/testing
parenta2705f514b471e2b74c98a0cde588863e3ff22c6 (diff)
downloadrdiff-backup-a5c03feacbbd9361eb3e2abe367b75529c83459b.tar.gz
Added various compare options like --compare-full and --compare-hash
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@664 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
Diffstat (limited to 'rdiff-backup/testing')
-rw-r--r--rdiff-backup/testing/commontest.py7
-rw-r--r--rdiff-backup/testing/comparetest.py102
-rw-r--r--rdiff-backup/testing/connectiontest.py15
-rw-r--r--rdiff-backup/testing/finaltest.py16
-rw-r--r--rdiff-backup/testing/iterfiletest.py46
5 files changed, 144 insertions, 42 deletions
diff --git a/rdiff-backup/testing/commontest.py b/rdiff-backup/testing/commontest.py
index 3113b21..b205c0a 100644
--- a/rdiff-backup/testing/commontest.py
+++ b/rdiff-backup/testing/commontest.py
@@ -40,7 +40,8 @@ def MakeOutputDir():
return rp
def rdiff_backup(source_local, dest_local, src_dir, dest_dir,
- current_time = None, extra_options = ""):
+ current_time = None, extra_options = "",
+ check_return_val = 1):
"""Run rdiff-backup with the given options
source_local and dest_local are boolean values. If either is
@@ -70,7 +71,9 @@ def rdiff_backup(source_local, dest_local, src_dir, dest_dir,
cmdargs.extend([src_dir, dest_dir])
cmdline = " ".join(cmdargs)
print "Executing: ", cmdline
- assert not os.system(cmdline)
+ ret_val = os.system(cmdline)
+ if check_return_val: assert not ret_val, ret_val
+ return ret_val
def InternalBackup(source_local, dest_local, src_dir, dest_dir,
current_time = None, eas = None, acls = None):
diff --git a/rdiff-backup/testing/comparetest.py b/rdiff-backup/testing/comparetest.py
new file mode 100644
index 0000000..1d0b67d
--- /dev/null
+++ b/rdiff-backup/testing/comparetest.py
@@ -0,0 +1,102 @@
+import unittest
+from commontest import *
+from rdiff_backup import compare
+
+"""Test the compare.py module and overall compare functionality"""
+
+class CompareTest(unittest.TestCase):
+ def setUp(self):
+ Myrm("testfiles/output")
+ rdiff_backup(1, 1, 'testfiles/increment2', 'testfiles/output',
+ current_time = 10000)
+ rdiff_backup(1, 1, 'testfiles/increment3', 'testfiles/output',
+ current_time = 20000)
+
+ def generic_test(self, local, compare_option):
+ """Used for 6 tests below"""
+ rdiff_backup(local, local, 'testfiles/increment3', 'testfiles/output',
+ extra_options = compare_option)
+ ret_val = rdiff_backup(local, local, 'testfiles/increment2',
+ 'testfiles/output', extra_options = compare_option,
+ check_return_val = 0)
+ assert ret_val, ret_val
+ rdiff_backup(local, local, 'testfiles/increment2', 'testfiles/output',
+ extra_options = compare_option + "-at-time 10000")
+ ret_val = rdiff_backup(local, local, 'testfiles/increment3',
+ 'testfiles/output',
+ extra_options = compare_option + "-at-time 10000",
+ check_return_val = 0)
+ assert ret_val, ret_val
+
+ def testBasicLocal(self):
+ """Test basic --compare and --compare-at-time modes"""
+ self.generic_test(1, "--compare")
+
+ def testBasicRemote(self):
+ """Test basic --compare and --compare-at-time modes, both remote"""
+ self.generic_test(0, "--compare")
+
+ def testHashLocal(self):
+ """Test --compare-hash and --compare-hash-at-time modes local"""
+ self.generic_test(1, "--compare-hash")
+
+ def testHashRemote(self):
+ """Test --compare-hash and -at-time remotely"""
+ self.generic_test(0, "--compare-hash")
+
+ def testFullLocal(self):
+ """Test --compare-full and --compare-full-at-time"""
+ self.generic_test(1, "--compare-full")
+
+ def testFullRemote(self):
+ """Test full file compare remotely"""
+ self.generic_test(0, "--compare-full")
+
+ def generic_selective_test(self, local, compare_option):
+ """Used for selective tests--just compare part of a backup"""
+ rdiff_backup(local, local, 'testfiles/increment3/various_file_types',
+ 'testfiles/output/various_file_types',
+ extra_options = compare_option)
+ ret_val = rdiff_backup(local, local,
+ 'testfiles/increment2/increment1',
+ 'testfiles/output/increment1',
+ extra_options = compare_option,
+ check_return_val = 0)
+ assert ret_val, ret_val
+
+ rdiff_backup(local, local, 'testfiles/increment2/newdir',
+ 'testfiles/output/newdir',
+ extra_options = compare_option + "-at-time 10000")
+ ret_val = rdiff_backup(local, local,
+ 'testfiles/increment3/newdir',
+ 'testfiles/output/newdir',
+ extra_options = compare_option + "-at-time 10000",
+ check_return_val = 0)
+ assert ret_val, ret_val
+
+ def testSelLocal(self):
+ """Test basic local compare of single subdirectory"""
+ self.generic_selective_test(1, "--compare")
+
+ def testSelRemote(self):
+ """Test --compare of single directory, remote"""
+ self.generic_selective_test(0, "--compare")
+
+ def testSelHashLocal(self):
+ """Test --compare-hash of subdirectory, local"""
+ self.generic_selective_test(1, "--compare-hash")
+
+ def testSelHashRemote(self):
+ """Test --compare-hash of subdirectory, remote"""
+ self.generic_selective_test(0, "--compare-hash")
+
+ def testSelFullLocal(self):
+ """Test --compare-full of subdirectory, local"""
+ self.generic_selective_test(1, "--compare-full")
+
+ def testSelFullRemote(self):
+ """Test --compare-full of subdirectory, remote"""
+ self.generic_selective_test(0, "--compare-full")
+
+if __name__ == "__main__": unittest.main()
+
diff --git a/rdiff-backup/testing/connectiontest.py b/rdiff-backup/testing/connectiontest.py
index d0f10f1..6537729 100644
--- a/rdiff-backup/testing/connectiontest.py
+++ b/rdiff-backup/testing/connectiontest.py
@@ -133,10 +133,10 @@ class PipeConnectionTest(unittest.TestCase):
def testIterators(self):
"""Test transmission of iterators"""
- i = iter(map(RORPsubstitute, range(10)))
+ i = iter([5, 10, 15]*100)
assert self.conn.hasattr(i, "next")
- datastring = self.conn.reval("lambda i: i.next().data", i)
- assert datastring == "Hello, there 0", datastring
+ ret_val = self.conn.reval("lambda i: i.next()*i.next()", i)
+ assert ret_val == 50, ret_val
def testRPaths(self):
"""Test transmission of rpaths"""
@@ -212,12 +212,5 @@ class RedirectedConnectionTest(unittest.TestCase):
def tearDown(self):
SetConnections.CloseConnections()
-class RORPsubstitute:
- """Used in testIterators above to simulate a RORP"""
- def __init__(self, i):
- self.index = i
- self.data = "Hello, there %d" % i
- self.file = None
-if __name__ == "__main__":
- unittest.main()
+if __name__ == "__main__": unittest.main()
diff --git a/rdiff-backup/testing/finaltest.py b/rdiff-backup/testing/finaltest.py
index 79f788c..8fe04f1 100644
--- a/rdiff-backup/testing/finaltest.py
+++ b/rdiff-backup/testing/finaltest.py
@@ -447,22 +447,6 @@ class FinalMisc(PathSetter):
for inc in self.get_all_increments(rbdir):
assert inc.getinctime() >= 20000
- def testCompare(self):
- """Test --compare and --compare-older-than modes"""
- Myrm("testfiles/output")
- self.set_connections(None, None, None, None)
- self.exec_rb(10000, 'testfiles/increment1', 'testfiles/output')
- self.exec_rb(20000, 'testfiles/increment2', 'testfiles/output')
-
- self.exec_rb_extra_args_retval(20000, '--compare', 0,
- 'testfiles/increment2', 'testfiles/output')
- self.exec_rb_extra_args_retval(20000, '--compare', 1,
- 'testfiles/increment1', 'testfiles/output')
- self.exec_rb_extra_args_retval(20000, '--compare-at-time 10000', 1,
- 'testfiles/increment2', 'testfiles/output')
- self.exec_rb_extra_args_retval(20000, '--compare-at-time 10000', 0,
- 'testfiles/increment1', 'testfiles/output')
-
class FinalSelection(PathSetter):
"""Test selection options"""
diff --git a/rdiff-backup/testing/iterfiletest.py b/rdiff-backup/testing/iterfiletest.py
index 4f3083d..a0a3260 100644
--- a/rdiff-backup/testing/iterfiletest.py
+++ b/rdiff-backup/testing/iterfiletest.py
@@ -53,7 +53,7 @@ class testIterFile(unittest.TestCase):
self.assertRaises(StopIteration, new_iter.next)
-class testRORPIters(unittest.TestCase):
+class testMiscIters(unittest.TestCase):
"""Test sending rorpiter back and forth"""
def setUp(self):
"""Make testfiles/output directory and a few files"""
@@ -83,7 +83,7 @@ class testRORPIters(unittest.TestCase):
self.regfile2.setdata()
self.regfile3.setdata()
- def print_RORPIterFile(self, rpiter_file):
+ def print_MiscIterFile(self, rpiter_file):
"""Print the given rorpiter file"""
while 1:
buf = rpiter_file.read()
@@ -93,7 +93,7 @@ class testRORPIters(unittest.TestCase):
def testBasic(self):
"""Test basic conversion"""
l = [self.outputrp, self.regfile1, self.regfile2, self.regfile3]
- i_out = FileToRORPIter(RORPIterToFile(iter(l)))
+ i_out = FileToMiscIter(MiscIterToFile(iter(l)))
out1 = i_out.next()
assert out1 == self.outputrp
@@ -113,34 +113,54 @@ class testRORPIters(unittest.TestCase):
i_out.next()
self.assertRaises(StopIteration, i_out.next)
+ def testMix(self):
+ """Test a mix of RPs and ordinary objects"""
+ l = [5, self.regfile3, "hello"]
+ s = MiscIterToFile(iter(l)).read()
+ i_out = FileToMiscIter(StringIO.StringIO(s))
+
+ out1 = i_out.next()
+ assert out1 == 5, out1
+
+ out2 = i_out.next()
+ assert out2 == self.regfile3
+ fp = out2.open("rb")
+ assert fp.read() == "goodbye"
+ assert not fp.close()
+
+ out3 = i_out.next()
+ assert out3 == "hello", out3
+
+ self.assertRaises(StopIteration, i_out.next)
+
def testFlush(self):
- """Test flushing property of RORPIterToFile"""
- l = [self.outputrp, RORPIterFlush, self.outputrp]
- filelike = RORPIterToFile(iter(l))
+ """Test flushing property of MiscIterToFile"""
+ l = [self.outputrp, MiscIterFlush, self.outputrp]
+ filelike = MiscIterToFile(iter(l))
new_filelike = StringIO.StringIO((filelike.read() + "z" +
C.long2str(0L)))
- i_out = FileToRORPIter(new_filelike)
+ i_out = FileToMiscIter(new_filelike)
assert i_out.next() == self.outputrp
self.assertRaises(StopIteration, i_out.next)
- i_out2 = FileToRORPIter(filelike)
+ i_out2 = FileToMiscIter(filelike)
assert i_out2.next() == self.outputrp
self.assertRaises(StopIteration, i_out2.next)
def testFlushRepeat(self):
"""Test flushing like above, but have Flush obj emerge from iter"""
- l = [self.outputrp, RORPIterFlushRepeat, self.outputrp]
- filelike = RORPIterToFile(iter(l))
+ l = [self.outputrp, MiscIterFlushRepeat, self.outputrp]
+ filelike = MiscIterToFile(iter(l))
new_filelike = StringIO.StringIO((filelike.read() + "z" +
C.long2str(0L)))
- i_out = FileToRORPIter(new_filelike)
+ i_out = FileToMiscIter(new_filelike)
assert i_out.next() == self.outputrp
- assert i_out.next() is RORPIterFlushRepeat
+ assert i_out.next() is MiscIterFlushRepeat
self.assertRaises(StopIteration, i_out.next)
- i_out2 = FileToRORPIter(filelike)
+ i_out2 = FileToMiscIter(filelike)
assert i_out2.next() == self.outputrp
self.assertRaises(StopIteration, i_out2.next)