bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.1.55
by Martin Pool
doc |
1 |
#! /usr/bin/python2.4
|
2 |
||
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
3 |
# Copyright (C) 2005 by Canonical Ltd
|
4 |
||
5 |
# This program is free software; you can redistribute it and/or modify
|
|
6 |
# it under the terms of the GNU General Public License as published by
|
|
7 |
# the Free Software Foundation; either version 2 of the License, or
|
|
8 |
# (at your option) any later version.
|
|
9 |
||
10 |
# This program is distributed in the hope that it will be useful,
|
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
# GNU General Public License for more details.
|
|
14 |
||
15 |
# You should have received a copy of the GNU General Public License
|
|
16 |
# along with this program; if not, write to the Free Software
|
|
17 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18 |
||
19 |
||
20 |
||
21 |
||
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
22 |
"""test suite for weave algorithm"""
|
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
23 |
|
24 |
||
25 |
from testsweet import TestBase |
|
|
0.1.47
by Martin Pool
New WeaveError and WeaveFormatError rather than assertions. |
26 |
from weave import Weave, VerInfo, WeaveFormatError |
|
0.1.57
by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously |
27 |
from pprint import pformat |
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
28 |
|
29 |
||
30 |
# texts for use in testing
|
|
|
0.1.3
by Martin Pool
Change storage of texts for testing |
31 |
TEXT_0 = ["Hello world"] |
32 |
TEXT_1 = ["Hello world", |
|
33 |
"A second line"] |
|
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
34 |
|
35 |
||
36 |
class Easy(TestBase): |
|
37 |
def runTest(self): |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
38 |
k = Weave() |
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
39 |
|
40 |
||
41 |
class StoreText(TestBase): |
|
42 |
"""Store and retrieve a simple text.""" |
|
43 |
def runTest(self): |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
44 |
k = Weave() |
|
0.1.26
by Martin Pool
Refactor parameters to add command |
45 |
idx = k.add([], TEXT_0) |
|
0.1.4
by Martin Pool
Start indexing knits by both integer and version string. |
46 |
self.assertEqual(k.get(idx), TEXT_0) |
47 |
self.assertEqual(idx, 0) |
|
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
48 |
|
49 |
||
|
0.1.7
by Martin Pool
Add trivial annotate text |
50 |
|
51 |
class AnnotateOne(TestBase): |
|
52 |
def runTest(self): |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
53 |
k = Weave() |
|
0.1.26
by Martin Pool
Refactor parameters to add command |
54 |
k.add([], TEXT_0) |
|
0.1.7
by Martin Pool
Add trivial annotate text |
55 |
self.assertEqual(k.annotate(0), |
56 |
[(0, TEXT_0[0])]) |
|
57 |
||
58 |
||
|
0.1.5
by Martin Pool
Add test for storing two text versions. |
59 |
class StoreTwo(TestBase): |
60 |
def runTest(self): |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
61 |
k = Weave() |
|
0.1.5
by Martin Pool
Add test for storing two text versions. |
62 |
|
|
0.1.26
by Martin Pool
Refactor parameters to add command |
63 |
idx = k.add([], TEXT_0) |
|
0.1.5
by Martin Pool
Add test for storing two text versions. |
64 |
self.assertEqual(idx, 0) |
65 |
||
|
0.1.26
by Martin Pool
Refactor parameters to add command |
66 |
idx = k.add([], TEXT_1) |
|
0.1.5
by Martin Pool
Add test for storing two text versions. |
67 |
self.assertEqual(idx, 1) |
68 |
||
69 |
self.assertEqual(k.get(0), TEXT_0) |
|
70 |
self.assertEqual(k.get(1), TEXT_1) |
|
71 |
||
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
72 |
k.dump(self.TEST_LOG) |
73 |
||
74 |
||
|
0.1.21
by Martin Pool
Start computing a delta to insert a new revision |
75 |
|
|
0.1.55
by Martin Pool
doc |
76 |
class DeltaAdd(TestBase): |
|
0.1.21
by Martin Pool
Start computing a delta to insert a new revision |
77 |
"""Detection of changes prior to inserting new revision.""" |
78 |
def runTest(self): |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
79 |
k = Weave() |
|
0.1.26
by Martin Pool
Refactor parameters to add command |
80 |
k.add([], ['line 1']) |
|
0.1.21
by Martin Pool
Start computing a delta to insert a new revision |
81 |
|
|
0.1.52
by Martin Pool
Update tests for new weave representation |
82 |
self.assertEqual(k._l, |
83 |
[('{', 0), |
|
84 |
'line 1', |
|
85 |
('}', 0), |
|
86 |
])
|
|
87 |
||
|
0.1.22
by Martin Pool
Calculate delta for new versions relative to a set of parent versions. |
88 |
changes = list(k._delta(set([0]), |
89 |
['line 1', |
|
90 |
'new line'])) |
|
|
0.1.21
by Martin Pool
Start computing a delta to insert a new revision |
91 |
|
92 |
self.log('raw changes: ' + pformat(changes)) |
|
93 |
||
|
0.1.52
by Martin Pool
Update tests for new weave representation |
94 |
# currently there are 3 lines in the weave, and we insert after them
|
|
0.1.22
by Martin Pool
Calculate delta for new versions relative to a set of parent versions. |
95 |
self.assertEquals(changes, |
|
0.1.52
by Martin Pool
Update tests for new weave representation |
96 |
[(3, 3, ['new line'])]) |
|
0.1.22
by Martin Pool
Calculate delta for new versions relative to a set of parent versions. |
97 |
|
|
0.1.24
by Martin Pool
Add another change for delta of new version. |
98 |
changes = k._delta(set([0]), |
99 |
['top line', |
|
100 |
'line 1']) |
|
101 |
||
102 |
self.assertEquals(list(changes), |
|
|
0.1.54
by Martin Pool
Fix weave line calculation when making deltas |
103 |
[(1, 1, ['top line'])]) |
|
0.1.24
by Martin Pool
Add another change for delta of new version. |
104 |
|
105 |
||
|
0.1.21
by Martin Pool
Start computing a delta to insert a new revision |
106 |
|
|
0.1.27
by Martin Pool
Check that version numbers passed in are reasonable |
107 |
class InvalidAdd(TestBase): |
108 |
"""Try to use invalid version number during add.""" |
|
109 |
def runTest(self): |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
110 |
k = Weave() |
|
0.1.27
by Martin Pool
Check that version numbers passed in are reasonable |
111 |
|
112 |
self.assertRaises(IndexError, |
|
113 |
k.add, |
|
114 |
[69], |
|
115 |
['new text!']) |
|
116 |
||
117 |
||
|
0.1.26
by Martin Pool
Refactor parameters to add command |
118 |
class InsertLines(TestBase): |
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
119 |
"""Store a revision that adds one line to the original. |
120 |
||
121 |
Look at the annotations to make sure that the first line is matched
|
|
122 |
and not stored repeatedly."""
|
|
123 |
def runTest(self): |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
124 |
k = Weave() |
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
125 |
|
|
0.1.26
by Martin Pool
Refactor parameters to add command |
126 |
k.add([], ['line 1']) |
127 |
k.add([0], ['line 1', 'line 2']) |
|
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
128 |
|
129 |
self.assertEqual(k.annotate(0), |
|
130 |
[(0, 'line 1')]) |
|
131 |
||
|
0.1.25
by Martin Pool
Handle insertion of new weave layers that insert text on top of the basis |
132 |
self.assertEqual(k.get(1), |
133 |
['line 1', |
|
134 |
'line 2']) |
|
135 |
||
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
136 |
self.assertEqual(k.annotate(1), |
137 |
[(0, 'line 1'), |
|
138 |
(1, 'line 2')]) |
|
139 |
||
|
0.1.28
by Martin Pool
More tests for insertion of lines in new versions. |
140 |
k.add([0], ['line 1', 'diverged line']) |
141 |
||
142 |
self.assertEqual(k.annotate(2), |
|
143 |
[(0, 'line 1'), |
|
144 |
(2, 'diverged line')]) |
|
145 |
||
|
0.1.54
by Martin Pool
Fix weave line calculation when making deltas |
146 |
text3 = ['line 1', 'middle line', 'line 2'] |
|
0.1.28
by Martin Pool
More tests for insertion of lines in new versions. |
147 |
k.add([0, 1], |
|
0.1.54
by Martin Pool
Fix weave line calculation when making deltas |
148 |
text3) |
149 |
||
150 |
self.log("changes to text3: " + pformat(list(k._delta(set([0, 1]), text3)))) |
|
151 |
||
152 |
self.log("k._l=" + pformat(k._l)) |
|
|
0.1.28
by Martin Pool
More tests for insertion of lines in new versions. |
153 |
|
154 |
self.assertEqual(k.annotate(3), |
|
155 |
[(0, 'line 1'), |
|
156 |
(3, 'middle line'), |
|
157 |
(1, 'line 2')]) |
|
158 |
||
|
0.1.31
by Martin Pool
Fix insertion of multiple regions, calculating the right line offset as we go. |
159 |
# now multiple insertions at different places
|
160 |
k.add([0, 1, 3], |
|
161 |
['line 1', 'aaa', 'middle line', 'bbb', 'line 2', 'ccc']) |
|
162 |
||
163 |
self.assertEqual(k.annotate(4), |
|
164 |
[(0, 'line 1'), |
|
165 |
(4, 'aaa'), |
|
166 |
(3, 'middle line'), |
|
167 |
(4, 'bbb'), |
|
168 |
(1, 'line 2'), |
|
169 |
(4, 'ccc')]) |
|
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
170 |
|
|
0.1.40
by Martin Pool
Add test for extracting from weave with nested insertions |
171 |
|
|
0.1.48
by Martin Pool
Basic parsing of delete instructions. |
172 |
|
|
0.1.56
by Martin Pool
Handle deletion of lines by marking the region with a deletion |
173 |
class DeleteLines(TestBase): |
174 |
"""Deletion of lines from existing text. |
|
175 |
||
176 |
Try various texts all based on a common ancestor."""
|
|
177 |
def runTest(self): |
|
178 |
k = Weave() |
|
179 |
||
180 |
base_text = ['one', 'two', 'three', 'four'] |
|
181 |
||
182 |
k.add([], base_text) |
|
183 |
||
184 |
texts = [['one', 'two', 'three'], |
|
185 |
['two', 'three', 'four'], |
|
186 |
['one', 'four'], |
|
187 |
['one', 'two', 'three', 'four'], |
|
188 |
]
|
|
189 |
||
190 |
for t in texts: |
|
191 |
ver = k.add([0], t) |
|
192 |
||
193 |
self.log('final weave:') |
|
194 |
self.log('k._l=' + pformat(k._l)) |
|
195 |
||
196 |
for i in range(len(texts)): |
|
197 |
self.assertEqual(k.get(i+1), |
|
198 |
texts[i]) |
|
199 |
||
200 |
||
201 |
||
202 |
||
|
0.1.49
by Martin Pool
Add another constraint: revisions should not delete text that they |
203 |
class SuicideDelete(TestBase): |
|
0.1.55
by Martin Pool
doc |
204 |
"""Invalid weave which tries to add and delete simultaneously.""" |
|
0.1.49
by Martin Pool
Add another constraint: revisions should not delete text that they |
205 |
def runTest(self): |
206 |
k = Weave() |
|
207 |
||
208 |
k._v = [VerInfo([]), |
|
209 |
]
|
|
210 |
k._l = [('{', 0), |
|
211 |
'first line', |
|
212 |
('[', 0), |
|
213 |
'deleted in 0', |
|
214 |
(']', 0), |
|
215 |
('}', 0), |
|
216 |
]
|
|
217 |
||
218 |
self.assertRaises(WeaveFormatError, |
|
219 |
k.get, |
|
220 |
0) |
|
221 |
||
222 |
||
223 |
||
|
0.1.48
by Martin Pool
Basic parsing of delete instructions. |
224 |
class CannedDelete(TestBase): |
225 |
"""Unpack canned weave with deleted lines.""" |
|
226 |
def runTest(self): |
|
227 |
k = Weave() |
|
228 |
||
229 |
k._v = [VerInfo([]), |
|
230 |
VerInfo([0]), |
|
231 |
]
|
|
232 |
k._l = [('{', 0), |
|
233 |
'first line', |
|
234 |
('[', 1), |
|
235 |
'line to be deleted', |
|
236 |
(']', 1), |
|
237 |
'last line', |
|
238 |
('}', 0), |
|
239 |
]
|
|
240 |
||
241 |
self.assertEqual(k.get(0), |
|
242 |
['first line', |
|
243 |
'line to be deleted', |
|
244 |
'last line', |
|
245 |
])
|
|
246 |
||
|
0.1.50
by Martin Pool
Basic implementation of deletion markers |
247 |
self.assertEqual(k.get(1), |
248 |
['first line', |
|
249 |
'last line', |
|
250 |
])
|
|
251 |
||
|
0.1.48
by Martin Pool
Basic parsing of delete instructions. |
252 |
|
253 |
||
|
0.1.51
by Martin Pool
Add test for replacement lines |
254 |
class CannedReplacement(TestBase): |
255 |
"""Unpack canned weave with deleted lines.""" |
|
256 |
def runTest(self): |
|
257 |
k = Weave() |
|
258 |
||
259 |
k._v = [VerInfo([]), |
|
260 |
VerInfo([0]), |
|
261 |
]
|
|
262 |
k._l = [('{', 0), |
|
263 |
'first line', |
|
264 |
('[', 1), |
|
265 |
'line to be deleted', |
|
266 |
(']', 1), |
|
267 |
('{', 1), |
|
268 |
'replacement line', |
|
269 |
('}', 1), |
|
270 |
'last line', |
|
271 |
('}', 0), |
|
272 |
]
|
|
273 |
||
274 |
self.assertEqual(k.get(0), |
|
275 |
['first line', |
|
276 |
'line to be deleted', |
|
277 |
'last line', |
|
278 |
])
|
|
279 |
||
280 |
self.assertEqual(k.get(1), |
|
281 |
['first line', |
|
282 |
'replacement line', |
|
283 |
'last line', |
|
284 |
])
|
|
285 |
||
286 |
||
287 |
||
|
0.1.46
by Martin Pool
More constraints on structure of weave, and checks that they work |
288 |
class BadWeave(TestBase): |
289 |
"""Test that we trap an insert which should not occur.""" |
|
290 |
def runTest(self): |
|
291 |
k = Weave() |
|
292 |
||
293 |
k._v = [VerInfo([]), |
|
294 |
]
|
|
295 |
k._l = ['bad line', |
|
296 |
('{', 0), |
|
297 |
'foo {', |
|
298 |
('{', 1), |
|
299 |
' added in version 1', |
|
300 |
('{', 2), |
|
301 |
' added in v2', |
|
302 |
('}', 2), |
|
303 |
' also from v1', |
|
304 |
('}', 1), |
|
305 |
'}', |
|
306 |
('}', 0)] |
|
307 |
||
|
0.1.47
by Martin Pool
New WeaveError and WeaveFormatError rather than assertions. |
308 |
self.assertRaises(WeaveFormatError, |
|
0.1.46
by Martin Pool
More constraints on structure of weave, and checks that they work |
309 |
k.get, |
310 |
0) |
|
311 |
||
312 |
||
313 |
class BadInsert(TestBase): |
|
314 |
"""Test that we trap an insert which should not occur.""" |
|
315 |
def runTest(self): |
|
316 |
k = Weave() |
|
317 |
||
318 |
k._v = [VerInfo([]), |
|
319 |
VerInfo([0]), |
|
320 |
VerInfo([0]), |
|
321 |
VerInfo([0,1,2]), |
|
322 |
]
|
|
323 |
k._l = [('{', 0), |
|
324 |
'foo {', |
|
325 |
('{', 1), |
|
326 |
' added in version 1', |
|
327 |
('{', 1), |
|
328 |
' more in 1', |
|
329 |
('}', 1), |
|
330 |
('}', 1), |
|
331 |
('}', 0)] |
|
332 |
||
|
0.1.47
by Martin Pool
New WeaveError and WeaveFormatError rather than assertions. |
333 |
self.assertRaises(WeaveFormatError, |
|
0.1.46
by Martin Pool
More constraints on structure of weave, and checks that they work |
334 |
k.get, |
335 |
0) |
|
336 |
||
|
0.1.47
by Martin Pool
New WeaveError and WeaveFormatError rather than assertions. |
337 |
self.assertRaises(WeaveFormatError, |
|
0.1.46
by Martin Pool
More constraints on structure of weave, and checks that they work |
338 |
k.get, |
339 |
1) |
|
340 |
||
|
0.1.40
by Martin Pool
Add test for extracting from weave with nested insertions |
341 |
|
342 |
class InsertNested(TestBase): |
|
343 |
"""Insertion with nested instructions.""" |
|
344 |
def runTest(self): |
|
345 |
k = Weave() |
|
346 |
||
347 |
k._v = [VerInfo([]), |
|
348 |
VerInfo([0]), |
|
349 |
VerInfo([0]), |
|
|
0.1.44
by Martin Pool
More tests for nested insert instructions |
350 |
VerInfo([0,1,2]), |
|
0.1.40
by Martin Pool
Add test for extracting from weave with nested insertions |
351 |
]
|
352 |
k._l = [('{', 0), |
|
353 |
'foo {', |
|
354 |
('{', 1), |
|
355 |
' added in version 1', |
|
|
0.1.42
by Martin Pool
More tests for nested insert instructions |
356 |
('{', 2), |
357 |
' added in v2', |
|
358 |
('}', 2), |
|
359 |
' also from v1', |
|
|
0.1.40
by Martin Pool
Add test for extracting from weave with nested insertions |
360 |
('}', 1), |
361 |
'}', |
|
362 |
('}', 0)] |
|
363 |
||
364 |
self.assertEqual(k.get(0), |
|
365 |
['foo {', |
|
366 |
'}']) |
|
367 |
||
368 |
self.assertEqual(k.get(1), |
|
369 |
['foo {', |
|
370 |
' added in version 1', |
|
|
0.1.42
by Martin Pool
More tests for nested insert instructions |
371 |
' also from v1', |
|
0.1.40
by Martin Pool
Add test for extracting from weave with nested insertions |
372 |
'}']) |
373 |
||
|
0.1.44
by Martin Pool
More tests for nested insert instructions |
374 |
self.assertEqual(k.get(2), |
375 |
['foo {', |
|
376 |
' added in v2', |
|
377 |
'}']) |
|
378 |
||
379 |
self.assertEqual(k.get(3), |
|
380 |
['foo {', |
|
381 |
' added in version 1', |
|
382 |
' added in v2', |
|
383 |
' also from v1', |
|
384 |
'}']) |
|
385 |
||
|
0.1.45
by Martin Pool
doc |
386 |
|
|
0.1.40
by Martin Pool
Add test for extracting from weave with nested insertions |
387 |
|
|
0.1.56
by Martin Pool
Handle deletion of lines by marking the region with a deletion |
388 |
class DeleteLines2(TestBase): |
|
0.1.30
by Martin Pool
Start adding tests for line deletion |
389 |
"""Test recording revisions that delete lines. |
390 |
||
391 |
This relies on the weave having a way to represent lines knocked
|
|
392 |
out by a later revision."""
|
|
393 |
def runTest(self): |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
394 |
k = Weave() |
|
0.1.30
by Martin Pool
Start adding tests for line deletion |
395 |
|
396 |
k.add([], ["line the first", |
|
397 |
"line 2", |
|
398 |
"line 3", |
|
399 |
"fine"]) |
|
400 |
||
401 |
self.assertEqual(len(k.get(0)), 4) |
|
402 |
||
403 |
k.add([0], ["line the first", |
|
404 |
"fine"]) |
|
405 |
||
406 |
self.assertEqual(k.get(1), |
|
407 |
["line the first", |
|
408 |
"fine"]) |
|
409 |
||
|
0.1.56
by Martin Pool
Handle deletion of lines by marking the region with a deletion |
410 |
self.assertEqual(k.annotate(1), |
411 |
[(0, "line the first"), |
|
412 |
(0, "fine")]) |
|
413 |
||
|
0.1.30
by Martin Pool
Start adding tests for line deletion |
414 |
|
|
0.1.26
by Martin Pool
Refactor parameters to add command |
415 |
|
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
416 |
class IncludeVersions(TestBase): |
417 |
"""Check texts that are stored across multiple revisions. |
|
418 |
||
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
419 |
Here we manually create a weave with particular encoding and make
|
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
420 |
sure it unpacks properly.
|
421 |
||
422 |
Text 0 includes nothing; text 1 includes text 0 and adds some
|
|
423 |
lines.
|
|
424 |
"""
|
|
425 |
||
426 |
def runTest(self): |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
427 |
k = Weave() |
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
428 |
|
|
0.1.17
by Martin Pool
Use objects rather than tuples for tracking VerInfo for |
429 |
k._v = [VerInfo(), VerInfo(included=[0])] |
|
0.1.39
by Martin Pool
Change to a more realistic weave structure which can represent insertions and |
430 |
k._l = [('{', 0), |
431 |
"first line", |
|
432 |
('}', 0), |
|
433 |
('{', 1), |
|
434 |
"second line", |
|
435 |
('}', 1)] |
|
|
0.1.13
by Martin Pool
Knit structure now allows for versions to include the lines present in other |
436 |
|
437 |
self.assertEqual(k.get(1), |
|
438 |
["first line", |
|
439 |
"second line"]) |
|
440 |
||
441 |
self.assertEqual(k.get(0), |
|
442 |
["first line"]) |
|
443 |
||
444 |
k.dump(self.TEST_LOG) |
|
445 |
||
|
0.1.5
by Martin Pool
Add test for storing two text versions. |
446 |
|
|
0.1.14
by Martin Pool
Another test for version inclusion |
447 |
class DivergedIncludes(TestBase): |
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
448 |
"""Weave with two diverged texts based on version 0. |
|
0.1.14
by Martin Pool
Another test for version inclusion |
449 |
"""
|
450 |
def runTest(self): |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
451 |
k = Weave() |
|
0.1.14
by Martin Pool
Another test for version inclusion |
452 |
|
|
0.1.17
by Martin Pool
Use objects rather than tuples for tracking VerInfo for |
453 |
k._v = [VerInfo(), |
454 |
VerInfo(included=[0]), |
|
455 |
VerInfo(included=[0]), |
|
456 |
]
|
|
|
0.1.39
by Martin Pool
Change to a more realistic weave structure which can represent insertions and |
457 |
k._l = [('{', 0), |
458 |
"first line", |
|
459 |
('}', 0), |
|
460 |
('{', 1), |
|
461 |
"second line", |
|
462 |
('}', 1), |
|
463 |
('{', 2), |
|
464 |
"alternative second line", |
|
465 |
('}', 2), |
|
466 |
]
|
|
|
0.1.14
by Martin Pool
Another test for version inclusion |
467 |
|
468 |
self.assertEqual(k.get(0), |
|
469 |
["first line"]) |
|
470 |
||
471 |
self.assertEqual(k.get(1), |
|
472 |
["first line", |
|
473 |
"second line"]) |
|
474 |
||
475 |
self.assertEqual(k.get(2), |
|
476 |
["first line", |
|
477 |
"alternative second line"]) |
|
478 |
||
|
0.1.57
by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously |
479 |
|
480 |
||
481 |
class ReplaceLine(TestBase): |
|
482 |
def runTest(self): |
|
483 |
k = Weave() |
|
484 |
||
485 |
text0 = ['cheddar', 'stilton', 'gruyere'] |
|
486 |
text1 = ['cheddar', 'blue vein', 'neufchatel', 'chevre'] |
|
487 |
||
488 |
k.add([], text0) |
|
489 |
k.add([0], text1) |
|
490 |
||
491 |
self.log('k._l=' + pformat(k._l)) |
|
492 |
||
|
0.1.59
by Martin Pool
More modification tests |
493 |
self.assertEqual(k.get(0), text0) |
|
0.1.57
by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously |
494 |
self.assertEqual(k.get(1), text1) |
495 |
||
|
0.1.64
by Martin Pool
Add test for merging versions |
496 |
|
497 |
||
498 |
class Merge(TestBase): |
|
|
0.1.65
by Martin Pool
Add Weave.merge_iter to get automerged lines |
499 |
"""Versions that merge diverged parents""" |
|
0.1.64
by Martin Pool
Add test for merging versions |
500 |
def runTest(self): |
501 |
k = Weave() |
|
502 |
||
503 |
texts = [['header'], |
|
504 |
['header', '', 'line from 1'], |
|
505 |
['header', '', 'line from 2', 'more from 2'], |
|
506 |
['header', '', 'line from 1', 'fixup line', 'line from 2'], |
|
507 |
]
|
|
508 |
||
509 |
k.add([], texts[0]) |
|
510 |
k.add([0], texts[1]) |
|
511 |
k.add([0], texts[2]) |
|
512 |
k.add([0, 1, 2], texts[3]) |
|
513 |
||
514 |
for i, t in enumerate(texts): |
|
515 |
self.assertEqual(k.get(i), t) |
|
516 |
||
517 |
self.assertEqual(k.annotate(3), |
|
518 |
[(0, 'header'), |
|
519 |
(1, ''), |
|
520 |
(1, 'line from 1'), |
|
521 |
(3, 'fixup line'), |
|
522 |
(2, 'line from 2'), |
|
523 |
])
|
|
524 |
||
525 |
self.log('k._l=' + pformat(k._l)) |
|
526 |
||
|
0.1.65
by Martin Pool
Add Weave.merge_iter to get automerged lines |
527 |
|
528 |
||
529 |
class AutoMerge(TestBase): |
|
530 |
def runTest(self): |
|
531 |
k = Weave() |
|
532 |
||
533 |
texts = [['header', 'aaa', 'bbb'], |
|
534 |
['header', 'aaa', 'line from 1', 'bbb'], |
|
535 |
['header', 'aaa', 'bbb', 'line from 2', 'more from 2'], |
|
536 |
]
|
|
537 |
||
538 |
k.add([], texts[0]) |
|
539 |
k.add([0], texts[1]) |
|
540 |
k.add([0], texts[2]) |
|
541 |
||
542 |
self.log('k._l=' + pformat(k._l)) |
|
543 |
||
544 |
m = list(k.merge_iter([0, 1, 2])) |
|
545 |
||
546 |
self.assertEqual(m, |
|
547 |
['header', 'aaa', |
|
548 |
'line from 1', |
|
549 |
'bbb', |
|
550 |
'line from 2', 'more from 2']) |
|
|
0.1.57
by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously |
551 |
|
552 |
||
553 |
||
554 |
class Khayyam(TestBase): |
|
555 |
def runTest(self): |
|
556 |
rawtexts = [ |
|
557 |
"""A Book of Verses underneath the Bough, |
|
558 |
A Jug of Wine, a Loaf of Bread, -- and Thou
|
|
559 |
Beside me singing in the Wilderness --
|
|
560 |
Oh, Wilderness were Paradise enow!""", |
|
561 |
|
|
562 |
"""A Book of Verses underneath the Bough, |
|
563 |
A Jug of Wine, a Loaf of Bread, -- and Thou
|
|
564 |
Beside me singing in the Wilderness --
|
|
565 |
Oh, Wilderness were Paradise now!""", |
|
|
0.1.59
by Martin Pool
More modification tests |
566 |
|
567 |
"""A Book of poems underneath the tree, |
|
568 |
A Jug of Wine, a Loaf of Bread,
|
|
569 |
and Thou
|
|
570 |
Beside me singing in the Wilderness --
|
|
571 |
Oh, Wilderness were Paradise now!
|
|
572 |
||
573 |
-- O. Khayyam""", |
|
574 |
||
575 |
"""A Book of Verses underneath the Bough, |
|
576 |
A Jug of Wine, a Loaf of Bread,
|
|
577 |
and Thou
|
|
578 |
Beside me singing in the Wilderness --
|
|
579 |
Oh, Wilderness were Paradise now!
|
|
580 |
""", |
|
|
0.1.57
by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously |
581 |
]
|
582 |
texts = [[l.strip() for l in t.split('\n')] for t in rawtexts] |
|
583 |
||
584 |
k = Weave() |
|
585 |
parents = set() |
|
586 |
for t in texts: |
|
587 |
ver = k.add(parents, t) |
|
588 |
parents.add(ver) |
|
589 |
||
|
0.1.59
by Martin Pool
More modification tests |
590 |
self.log("k._l=" + pformat(k._l)) |
591 |
||
|
0.1.57
by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously |
592 |
for i, t in enumerate(texts): |
593 |
self.assertEqual(k.get(i), |
|
594 |
t) |
|
595 |
||
596 |
||
597 |
||
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
598 |
def testweave(): |
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
599 |
import testsweet |
600 |
from unittest import TestSuite, TestLoader |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
601 |
import testweave |
|
0.1.57
by Martin Pool
Fix bug in an update edit that both deletes and inserts -- previously |
602 |
|
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
603 |
tl = TestLoader() |
604 |
suite = TestSuite() |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
605 |
suite.addTest(tl.loadTestsFromModule(testweave)) |
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
606 |
|
|
0.1.15
by Martin Pool
Fix inverted shell return code for testknit |
607 |
return int(not testsweet.run_suite(suite)) # for shell 0=true |
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
608 |
|
609 |
||
610 |
if __name__ == '__main__': |
|
611 |
import sys |
|
|
0.1.38
by Martin Pool
Rename knit to weave. (I don't think there's an existing module called weave.) |
612 |
sys.exit(testweave()) |
|
0.1.2
by Martin Pool
Import testsweet module adapted from bzr. |
613 |