bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.9.1
by Aaron Bentley
Get trivial case passing |
1 |
from unittest import TestCase |
2 |
||
3 |
import multiparent |
|
4 |
||
|
0.9.3
by Aaron Bentley
Get three-parent comparisions under test |
5 |
|
|
0.9.1
by Aaron Bentley
Get trivial case passing |
6 |
LINES_1 = "a\nb\nc\nd\ne\n".splitlines(True) |
|
0.9.2
by Aaron Bentley
Get single-parent comparison working |
7 |
LINES_2 = "a\nc\nd\ne\n".splitlines(True) |
|
0.9.3
by Aaron Bentley
Get three-parent comparisions under test |
8 |
LINES_3 = "a\nb\nc\nd\n".splitlines(True) |
|
0.9.2
by Aaron Bentley
Get single-parent comparison working |
9 |
|
10 |
||
11 |
class Mock(object): |
|
12 |
||
13 |
def __init__(self, **kwargs): |
|
14 |
self.__dict__ = kwargs |
|
15 |
||
|
0.9.1
by Aaron Bentley
Get trivial case passing |
16 |
|
17 |
class TestMulti(TestCase): |
|
18 |
||
|
0.9.2
by Aaron Bentley
Get single-parent comparison working |
19 |
def test_compare_no_parent(self): |
20 |
diff = multiparent.MultiParent.from_lines(LINES_1) |
|
21 |
self.assertEqual([multiparent.NewText(LINES_1)], diff.hunks) |
|
22 |
||
23 |
def test_compare_one_parent(self): |
|
24 |
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2]) |
|
25 |
self.assertEqual([multiparent.ParentText(0, 0, 0, 1), |
|
26 |
multiparent.NewText(['b\n']), |
|
27 |
multiparent.ParentText(0, 1, 2, 3)], |
|
28 |
diff.hunks) |
|
29 |
||
|
0.9.3
by Aaron Bentley
Get three-parent comparisions under test |
30 |
def test_compare_two_parents(self): |
31 |
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3]) |
|
32 |
self.assertEqual([multiparent.ParentText(1, 0, 0, 4), |
|
33 |
multiparent.ParentText(0, 3, 4, 1)], |
|
34 |
diff.hunks) |
|
35 |
||
|
0.9.9
by Aaron Bentley
Much progress on non-naive text reconstruction |
36 |
def test_range_iterator(self): |
37 |
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3]) |
|
38 |
diff.hunks.append(multiparent.NewText(['q\n'])) |
|
39 |
self.assertEqual([(0, 4, 'parent', (1, 0, 4)), |
|
40 |
(4, 5, 'parent', (0, 3, 4)), |
|
41 |
(5, 6, 'new', ['q\n'])], |
|
42 |
list(diff.range_iterator())) |
|
43 |
||
|
0.9.2
by Aaron Bentley
Get single-parent comparison working |
44 |
def test_eq(self): |
45 |
diff = multiparent.MultiParent.from_lines(LINES_1) |
|
46 |
diff2 = multiparent.MultiParent.from_lines(LINES_1) |
|
47 |
self.assertEqual(diff, diff2) |
|
48 |
diff3 = multiparent.MultiParent.from_lines(LINES_2) |
|
49 |
self.assertFalse(diff == diff3) |
|
50 |
self.assertFalse(diff == Mock(hunks=[multiparent.NewText(LINES_1)])) |
|
51 |
self.assertEqual(multiparent.MultiParent( |
|
52 |
[multiparent.NewText(LINES_1), |
|
53 |
multiparent.ParentText(0, 1, 2, 3)]), |
|
54 |
multiparent.MultiParent( |
|
55 |
[multiparent.NewText(LINES_1), |
|
56 |
multiparent.ParentText(0, 1, 2, 3)])) |
|
|
0.9.1
by Aaron Bentley
Get trivial case passing |
57 |
|
|
0.9.4
by Aaron Bentley
Start supporting serialization |
58 |
def test_to_patch(self): |
59 |
self.assertEqual(['i 1\n', 'a\n', '\n', 'c 0 1 2 3\n'], |
|
60 |
list(multiparent.MultiParent([multiparent.NewText(['a\n']), |
|
61 |
multiparent.ParentText(0, 1, 2, 3)]).to_patch())) |
|
62 |
||
|
0.9.18
by Aaron Bentley
Implement from_patch |
63 |
def test_from_patch(self): |
64 |
self.assertEqual(multiparent.MultiParent( |
|
65 |
[multiparent.NewText(['a\n']), |
|
66 |
multiparent.ParentText(0, 1, 2, 3)]), |
|
67 |
multiparent.MultiParent.from_patch( |
|
68 |
['i 1\n', 'a\n', '\n', 'c 0 1 2 3\n'])) |
|
69 |
self.assertEqual(multiparent.MultiParent( |
|
70 |
[multiparent.NewText(['a']), |
|
71 |
multiparent.ParentText(0, 1, 2, 3)]), |
|
72 |
multiparent.MultiParent.from_patch( |
|
73 |
['i 1\n', 'a\n', 'c 0 1 2 3\n'])) |
|
74 |
||
|
0.9.11
by Aaron Bentley
Implement reconstruct_version, handle all hunks through that |
75 |
def test_num_lines(self): |
76 |
mp = multiparent.MultiParent([multiparent.NewText(['a\n'])]) |
|
77 |
self.assertEqual(1, mp.num_lines()) |
|
78 |
mp.hunks.append(multiparent.NewText(['b\n', 'c\n'])) |
|
79 |
self.assertEqual(3, mp.num_lines()) |
|
80 |
mp.hunks.append(multiparent.ParentText(0, 0, 3, 2)) |
|
81 |
self.assertEqual(5, mp.num_lines()) |
|
82 |
mp.hunks.append(multiparent.NewText(['f\n', 'g\n'])) |
|
83 |
self.assertEqual(7, mp.num_lines()) |
|
84 |
||
|
0.9.1
by Aaron Bentley
Get trivial case passing |
85 |
|
86 |
class TestNewText(TestCase): |
|
87 |
||
88 |
def test_eq(self): |
|
89 |
self.assertEqual(multiparent.NewText([]), multiparent.NewText([])) |
|
90 |
self.assertFalse(multiparent.NewText(['a']) == |
|
91 |
multiparent.NewText(['b'])) |
|
|
0.9.2
by Aaron Bentley
Get single-parent comparison working |
92 |
self.assertFalse(multiparent.NewText(['a']) == Mock(lines=['a'])) |
93 |
||
|
0.9.4
by Aaron Bentley
Start supporting serialization |
94 |
def test_to_patch(self): |
95 |
self.assertEqual(['i 0\n', '\n'], |
|
96 |
list(multiparent.NewText([]).to_patch())) |
|
97 |
self.assertEqual(['i 1\n', 'a', '\n'], |
|
98 |
list(multiparent.NewText(['a']).to_patch())) |
|
99 |
self.assertEqual(['i 1\n', 'a\n', '\n'], |
|
100 |
list(multiparent.NewText(['a\n']).to_patch())) |
|
101 |
||
|
0.9.2
by Aaron Bentley
Get single-parent comparison working |
102 |
|
103 |
class TestParentText(TestCase): |
|
104 |
||
105 |
def test_eq(self): |
|
106 |
self.assertEqual(multiparent.ParentText(1, 2, 3, 4), |
|
107 |
multiparent.ParentText(1, 2, 3, 4)) |
|
108 |
self.assertFalse(multiparent.ParentText(1, 2, 3, 4) == |
|
109 |
multiparent.ParentText(2, 2, 3, 4)) |
|
110 |
self.assertFalse(multiparent.ParentText(1, 2, 3, 4) == |
|
111 |
Mock(parent=1, parent_pos=2, child_pos=3, |
|
112 |
num_lines=4)) |
|
|
0.9.4
by Aaron Bentley
Start supporting serialization |
113 |
|
114 |
def test_to_patch(self): |
|
115 |
self.assertEqual(['c 0 1 2 3\n'], |
|
116 |
list(multiparent.ParentText(0, 1, 2, 3).to_patch())) |
|
|
0.9.8
by Aaron Bentley
get add_version working |
117 |
|
118 |
||
|
0.9.9
by Aaron Bentley
Much progress on non-naive text reconstruction |
119 |
REV_A = ['a\n', 'b\n', 'c\n', 'd\n'] |
120 |
REV_B = ['a\n', 'c\n', 'd\n', 'e\n'] |
|
121 |
REV_C = ['a\n', 'b\n', 'e\n', 'f\n'] |
|
122 |
||
123 |
||
|
0.9.8
by Aaron Bentley
get add_version working |
124 |
class TestVersionedFile(TestCase): |
125 |
||
126 |
def add_version(self, vf, text, version_id, parent_ids): |
|
127 |
vf.add_version([(t+'\n') for t in text], version_id, parent_ids) |
|
128 |
||
|
0.9.9
by Aaron Bentley
Much progress on non-naive text reconstruction |
129 |
def make_vf(self): |
|
0.9.30
by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile |
130 |
vf = multiparent.MultiMemoryVersionedFile() |
|
0.9.8
by Aaron Bentley
get add_version working |
131 |
self.add_version(vf, 'abcd', 'rev-a', []) |
|
0.9.9
by Aaron Bentley
Much progress on non-naive text reconstruction |
132 |
self.add_version(vf, 'acde', 'rev-b', []) |
133 |
self.add_version(vf, 'abef', 'rev-c', ['rev-a', 'rev-b']) |
|
134 |
return vf |
|
135 |
||
136 |
def test_add_version(self): |
|
137 |
vf = self.make_vf() |
|
138 |
self.assertEqual(REV_A, vf._lines['rev-a']) |
|
|
0.9.8
by Aaron Bentley
get add_version working |
139 |
vf.clear_cache() |
140 |
self.assertEqual(vf._lines, {}) |
|
|
0.9.9
by Aaron Bentley
Much progress on non-naive text reconstruction |
141 |
|
142 |
def test_get_line_list(self): |
|
143 |
vf = self.make_vf() |
|
144 |
vf.clear_cache() |
|
145 |
self.assertEqual(REV_A, vf.get_line_list(['rev-a'])[0]) |
|
146 |
self.assertEqual([REV_B, REV_C], vf.get_line_list(['rev-b', 'rev-c'])) |
|
147 |
||
148 |
@staticmethod
|
|
149 |
def reconstruct(vf, revision_id, start, end): |
|
|
0.9.30
by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile |
150 |
reconstructor = multiparent._Reconstructor(vf, vf._lines, |
|
0.9.9
by Aaron Bentley
Much progress on non-naive text reconstruction |
151 |
vf._parents) |
152 |
lines = [] |
|
153 |
reconstructor._reconstruct(lines, revision_id, start, end) |
|
154 |
return lines |
|
155 |
||
|
0.9.11
by Aaron Bentley
Implement reconstruct_version, handle all hunks through that |
156 |
@staticmethod
|
157 |
def reconstruct_version(vf, revision_id): |
|
|
0.9.30
by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile |
158 |
reconstructor = multiparent._Reconstructor(vf, vf._lines, |
|
0.9.11
by Aaron Bentley
Implement reconstruct_version, handle all hunks through that |
159 |
vf._parents) |
160 |
lines = [] |
|
161 |
reconstructor.reconstruct_version(lines, revision_id) |
|
162 |
return lines |
|
163 |
||
|
0.9.9
by Aaron Bentley
Much progress on non-naive text reconstruction |
164 |
def test_reconstructor(self): |
165 |
vf = self.make_vf() |
|
166 |
self.assertEqual(['a\n', 'b\n'], self.reconstruct(vf, 'rev-a', 0, 2)) |
|
167 |
self.assertEqual(['c\n', 'd\n'], self.reconstruct(vf, 'rev-a', 2, 4)) |
|
168 |
self.assertEqual(['e\n', 'f\n'], self.reconstruct(vf, 'rev-c', 2, 4)) |
|
|
0.9.10
by Aaron Bentley
Text reconstruction seems to work |
169 |
self.assertEqual(['a\n', 'b\n', 'e\n', 'f\n'], |
170 |
self.reconstruct(vf, 'rev-c', 0, 4)) |
|
|
0.9.11
by Aaron Bentley
Implement reconstruct_version, handle all hunks through that |
171 |
self.assertEqual(['a\n', 'b\n', 'e\n', 'f\n'], |
172 |
self.reconstruct_version(vf, 'rev-c')) |
|
|
0.9.22
by Aaron Bentley
Fix restoration bug |
173 |
|
174 |
def test_reordered(self): |
|
175 |
"""Check for a corner case that requires re-starting the cursor""" |
|
|
0.9.30
by Aaron Bentley
Split into MultiVersionedFile and MultiMemoryVersionedFile |
176 |
vf = multiparent.MultiMemoryVersionedFile() |
|
0.9.22
by Aaron Bentley
Fix restoration bug |
177 |
# rev-b must have at least two hunks, so split a and b with c.
|
178 |
self.add_version(vf, 'c', 'rev-a', []) |
|
179 |
self.add_version(vf, 'acb', 'rev-b', ['rev-a']) |
|
180 |
# rev-c and rev-d must each have a line from a different rev-b hunk
|
|
181 |
self.add_version(vf, 'b', 'rev-c', ['rev-b']) |
|
182 |
self.add_version(vf, 'a', 'rev-d', ['rev-b']) |
|
183 |
# The lines from rev-c and rev-d must appear in the opposite order
|
|
184 |
self.add_version(vf, 'ba', 'rev-e', ['rev-c', 'rev-d']) |
|
185 |
vf.clear_cache() |
|
186 |
lines = vf.get_line_list(['rev-e'])[0] |
|
187 |
self.assertEqual(['b\n', 'a\n'], lines) |