summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2002-06-27 20:23:45 +0000
committerben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2002-06-27 20:23:45 +0000
commitb12c8c861ee1be9fd157212cdd9cca1d6e1e127d (patch)
tree8eeb24a813ba7f7b88ea7957e4dc9a9824872ce4
parent0f383c16278f6ef0959a6d3aa7fcf21cd2c4c730 (diff)
downloadrdiff-backup-b12c8c861ee1be9fd157212cdd9cca1d6e1e127d.tar.gz
New tests for librsync wrapper.
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@152 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
-rw-r--r--rdiff-backup/testing/librsynctest.py118
1 files changed, 118 insertions, 0 deletions
diff --git a/rdiff-backup/testing/librsynctest.py b/rdiff-backup/testing/librsynctest.py
new file mode 100644
index 0000000..e2cdeb3
--- /dev/null
+++ b/rdiff-backup/testing/librsynctest.py
@@ -0,0 +1,118 @@
+import unittest, random
+from commontest import *
+import librsync
+
+def MakeRandomFile(path):
+ """Writes a random file of length between 10000 and 100000"""
+ fp = open(path, "w")
+ randseq = []
+ for i in xrange(random.randrange(5000, 30000)):
+ randseq.append(chr(random.randrange(256)))
+ fp.write("".join(randseq))
+ fp.close()
+
+
+class LibrsyncTest(unittest.TestCase):
+ """Test various librsync wrapper functions"""
+ basis = RPath(Globals.local_connection, "testfiles/basis")
+ new = RPath(Globals.local_connection, "testfiles/new")
+ new2 = RPath(Globals.local_connection, "testfiles/new2")
+ sig = RPath(Globals.local_connection, "testfiles/signature")
+ delta = RPath(Globals.local_connection, "testfiles/delta")
+ def testSigFile(self):
+ """Make sure SigFile generates same data as rdiff"""
+ for i in range(5):
+ MakeRandomFile(self.basis.path)
+ self.sig.delete()
+ assert not os.system("rdiff signature %s %s" %
+ (self.basis.path, self.sig.path))
+ fp = self.sig.open("rb")
+ rdiff_sig = fp.read()
+ fp.close()
+
+ sf = librsync.SigFile(self.basis.open("rb"))
+ librsync_sig = sf.read()
+ sf.close()
+
+ assert rdiff_sig == librsync_sig, \
+ (len(rdiff_sig), len(librsync_sig))
+
+ def OldtestDelta(self):
+ """Test delta generation against Rdiff"""
+ MakeRandomFile(self.basis.path)
+ assert not os.system("rdiff signature %s %s" %
+ (self.basis.path, self.sig.path))
+ for i in range(5):
+ MakeRandomFile(self.new.path)
+ assert not os.system("rdiff delta %s %s %s" %
+ (self.sig.path, self.new.path, self.delta.path))
+ fp = self.delta.open("rb")
+ rdiff_delta = fp.read()
+ fp.close()
+
+ df = librsync.DeltaFile(self.sig.open("rb"), self.new.open("rb"))
+ librsync_delta = df.read()
+ df.close()
+
+ print len(rdiff_delta), len(librsync_delta)
+ print repr(rdiff_delta[:100])
+ print repr(librsync_delta[:100])
+ assert rdiff_delta == librsync_delta
+
+ def testDelta(self):
+ """Test delta generation by making sure rdiff can process output
+
+ There appears to be some undeterminism so we can't just
+ byte-compare the deltas produced by rdiff and DeltaFile.
+
+ """
+ MakeRandomFile(self.basis.path)
+ assert not os.system("rdiff signature %s %s" %
+ (self.basis.path, self.sig.path))
+ for i in range(5):
+ MakeRandomFile(self.new.path)
+ df = librsync.DeltaFile(self.sig.open("rb"), self.new.open("rb"))
+ librsync_delta = df.read()
+ df.close()
+ fp = self.delta.open("wb")
+ fp.write(librsync_delta)
+ fp.close()
+
+ assert not os.system("rdiff patch %s %s %s" %
+ (self.basis.path, self.delta.path,
+ self.new2.path))
+ new_fp = self.new.open("rb")
+ new = new_fp.read()
+ new_fp.close()
+
+ new2_fp = self.new2.open("rb")
+ new2 = new2_fp.read()
+ new2_fp.close()
+
+ assert new == new2, (len(new), len(new2))
+
+ def testPatch(self):
+ """Test patching against Rdiff"""
+ MakeRandomFile(self.basis.path)
+ assert not os.system("rdiff signature %s %s" %
+ (self.basis.path, self.sig.path))
+ for i in range(5):
+ MakeRandomFile(self.new.path)
+ assert not os.system("rdiff delta %s %s %s" %
+ (self.sig.path, self.new.path, self.delta.path))
+ fp = self.new.open("rb")
+ real_new = fp.read()
+ fp.close()
+
+ pf = librsync.PatchedFile(self.basis.open("rb"),
+ self.delta.open("rb"))
+ librsync_new = pf.read()
+ pf.close()
+
+ assert real_new == librsync_new, \
+ (len(real_new), len(librsync_new))
+
+
+
+if __name__ == "__main__": unittest.main()
+