forked from smartfile/python-librsync
/
tests.py
80 lines (56 loc) · 2.16 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
import unittest
import librsync
try:
from StringIO import StringIO
except ImportError:
from io import BytesIO as StringIO
class TraceLevelTestCase(unittest.TestCase):
def test_set(self):
librsync.debug()
def test_set_invalid(self):
self.assertRaises(AssertionError, librsync.debug, level=40)
class SingleFileTestCase(unittest.TestCase):
def setUp(self):
self.rand = StringIO(os.urandom(1024**2))
class DoubleFileTestCase(unittest.TestCase):
def setUp(self):
self.rand1 = StringIO(os.urandom(1024**2))
self.rand2 = StringIO(os.urandom(1024**2))
class SignatureTestCase(SingleFileTestCase):
def test_signature(self):
s = librsync.signature(self.rand)
class DeltaTestCase(DoubleFileTestCase):
def test_signature(self):
s = librsync.signature(self.rand1)
d = librsync.delta(self.rand2, s)
def test_failure(self):
"Ensure delta aborts when provided invalid signature."
self.assertRaises(librsync.LibrsyncError, librsync.delta, self.rand2,
self.rand1)
class PatchTestCase(DoubleFileTestCase):
def test_patch(self):
s = librsync.signature(self.rand1)
d = librsync.delta(self.rand2, s)
self.rand1.seek(0)
self.rand2.seek(0)
o = librsync.patch(self.rand1, d)
self.assertEqual(o.read(), self.rand2.read())
def test_nonseek(self):
self.assertRaises(AssertionError, librsync.patch, None, self.rand2)
def test_failure(self):
"Ensure patch aborts when provided invalid delta."
self.assertRaises(librsync.LibrsyncError, librsync.patch, self.rand1,
self.rand2)
class BigPatchTestCase(PatchTestCase):
def setUp(self):
"Use large enough test files to cause temp files to hit disk."
self.rand1 = StringIO(os.urandom(1024**2*5))
self.rand2 = StringIO(os.urandom(1024**2*5))
class Issue3TestCase(PatchTestCase):
def setUp(self):
"Use test data provided in issue #3."
self.rand1 = StringIO('Text.')
self.rand2 = StringIO('New text.\nText.')
if __name__ == '__main__':
unittest.main()