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