-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunit_tests.py
More file actions
111 lines (99 loc) · 3.7 KB
/
unit_tests.py
File metadata and controls
111 lines (99 loc) · 3.7 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import base64
import unittest
from hamcrest import *
from rest_api import diff
# TODO Improve the test methods creating common methods to decrease code duplication
class DiffLogicTest(unittest.TestCase):
"""
This class contains the unit tests for the diff logic.
"""
def test_equal_values(self):
"""
Test for the expected diff code and message when the data are equals
"""
a = b'THIS IS EQUAL'
b = b'THIS IS EQUAL'
left = base64.b64encode(a)
right = base64.b64encode(b)
diff_res = diff(left, right)
assert_that(diff_res[0], equal_to(0))
assert_that(diff_res[1], equal_to(u'The data are equals'))
def test_one_diff_session(self):
"""
Test for the expected diff code and message when the data has only one difference
"""
a = b'NOT EQUAL'
b = b'YES EQUAL'
left = base64.b64encode(a)
right = base64.b64encode(b)
diff_res = diff(left, right)
assert_that(diff_res[0], equal_to(1))
assert_that(diff_res[1], equal_to(u'Offset: 0, Length: 3\n'))
def test_two_diff_session(self):
"""
Test for the expected diff code and message when the data has two difference
"""
a = b'NOT EQUAL, BUT GOOD'
b = b'YES EQUAL, BUT WELL'
left = base64.b64encode(a)
right = base64.b64encode(b)
diff_res = diff(left, right)
assert_that(diff_res[0], equal_to(2))
assert_that(diff_res[1], equal_to(u'Offset: 0, Length: 3\nOffset: 15, Length: 4\n'))
def test_entire_diff(self):
"""
Test for the expected diff code and message when the data is completely different and has the same size
"""
a = b'ENTIRELYDIFFERENT'
b = b'DIFFERENTLYENTIRE'
left = base64.b64encode(a)
right = base64.b64encode(b)
diff_res = diff(left, right)
assert_that(diff_res[0], equal_to(1))
assert_that(diff_res[1], equal_to(u'Offset: 0, Length: 17\n'))
def test_diff_not_equal_size_left(self):
"""
Test for when the left data is bigger tha the right data
"""
a = b'ENTIRELYDIFFERENTAAA'
b = b'DIFFERENTLYENTIRE'
left = base64.b64encode(a)
right = base64.b64encode(b)
diff_res = diff(left, right)
assert_that(diff_res[0], equal_to(-1))
assert_that(diff_res[1], equal_to(u'The data to compare has different sizes'))
def test_diff_not_equal_size_right(self):
"""
Test for when the right data is bigger tha the left data
"""
a = b'ENTIRELYDIFFERENT'
b = b'DIFFERENTLYENTIREAAA'
left = base64.b64encode(a)
right = base64.b64encode(b)
diff_res = diff(left, right)
assert_that(diff_res[0], equal_to(-1))
assert_that(diff_res[1], equal_to(u'The data to compare has different sizes'))
def test_diff_none_left(self):
"""
Test for when the left data is blank
"""
a = b''
b = b'DIFFERENTLYENTIRE'
left = base64.b64encode(a)
right = base64.b64encode(b)
diff_res = diff(left, right)
assert_that(diff_res[0], equal_to(-1))
assert_that(diff_res[1], equal_to(u'The data to compare has different sizes'))
def test_diff_none_right(self):
"""
Test for when the right data is blank
"""
a = b'ENTIRELYDIFFERENT'
b = b''
left = base64.b64encode(a)
right = base64.b64encode(b)
diff_res = diff(left, right)
assert_that(diff_res[0], equal_to(-1))
assert_that(diff_res[1], equal_to(u'The data to compare has different sizes'))
if __name__ == '__main__':
unittest.main(verbosity=2)