-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtests.py
93 lines (65 loc) · 2.52 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
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
import unittest
import librsync
try:
from BytesIO import BytesIO
except ImportError:
from io import BytesIO
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 = BytesIO(os.urandom(1024**2))
class DoubleFileTestCase(unittest.TestCase):
def setUp(self):
self.rand1 = BytesIO(os.urandom(1024**2))
self.rand2 = BytesIO(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 = BytesIO(os.urandom(1024**2*5))
self.rand2 = BytesIO(os.urandom(1024**2*5))
class Issue3TestCase(PatchTestCase):
def setUp(self):
"Use test data provided in issue #3."
self.rand1 = BytesIO(b'Text.')
self.rand2 = BytesIO(b'New text.\nText.')
class SimpleStringTestCase(unittest.TestCase):
def setUp(self):
self.src = b'FF'
self.dst = b'FF123FF'
def test_string_patch(self):
src_sig = librsync.signature(BytesIO(self.src))
delta = librsync.delta(BytesIO(self.dst), src_sig).read()
out = librsync.patch(BytesIO(self.src), BytesIO(delta))
self.assertEqual(self.dst, out.read())
if __name__ == '__main__':
unittest.main()