forked from smartfile/python-librsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
66 lines (46 loc) · 1.73 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
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)
if __name__ == '__main__':
unittest.main()