25
23
from testsweet import TestBase
26
from weave import Weave, VerInfo, WeaveFormatError
27
from pprint import pformat
29
# XXX: If we do weaves this way, will a merge still behave the same
30
# way if it's done in a different order? That's a pretty desirable
24
from weave import Weave, VerInfo
34
27
# texts for use in testing
80
class DeltaAdd(TestBase):
73
class Delta1(TestBase):
81
74
"""Detection of changes prior to inserting new revision."""
76
return ########################## SKIPPED
77
from pprint import pformat
84
80
k.add([], ['line 1'])
86
self.assertEqual(k._l,
92
82
changes = list(k._delta(set([0]),
96
86
self.log('raw changes: ' + pformat(changes))
98
# currently there are 3 lines in the weave, and we insert after them
88
# should be one inserted line after line 0q
99
89
self.assertEquals(changes,
100
[(3, 3, ['new line'])])
90
[(1, 1, ['new line'])])
102
92
changes = k._delta(set([0]),
106
96
self.assertEquals(list(changes),
107
[(1, 1, ['top line'])])
97
[(0, 0, ['top line'])])
148
140
(2, 'diverged line')])
150
text3 = ['line 1', 'middle line', 'line 2']
154
self.log("changes to text3: " + pformat(list(k._delta(set([0, 1]), text3))))
156
self.log("k._l=" + pformat(k._l))
143
['line 1', 'middle line', 'line 2'])
158
145
self.assertEqual(k.annotate(3),
177
class DeleteLines(TestBase):
178
"""Deletion of lines from existing text.
180
Try various texts all based on a common ancestor."""
184
base_text = ['one', 'two', 'three', 'four']
188
texts = [['one', 'two', 'three'],
189
['two', 'three', 'four'],
191
['one', 'two', 'three', 'four'],
197
self.log('final weave:')
198
self.log('k._l=' + pformat(k._l))
200
for i in range(len(texts)):
201
self.assertEqual(k.get(i+1),
207
class SuicideDelete(TestBase):
208
"""Invalid weave which tries to add and delete simultaneously."""
222
self.assertRaises(WeaveFormatError,
228
class CannedDelete(TestBase):
229
"""Unpack canned weave with deleted lines."""
239
'line to be deleted',
245
self.assertEqual(k.get(0),
247
'line to be deleted',
251
self.assertEqual(k.get(1),
258
class CannedReplacement(TestBase):
259
"""Unpack canned weave with deleted lines."""
269
'line to be deleted',
278
self.assertEqual(k.get(0),
280
'line to be deleted',
284
self.assertEqual(k.get(1),
292
class BadWeave(TestBase):
293
"""Test that we trap an insert which should not occur."""
303
' added in version 1',
312
self.assertRaises(WeaveFormatError,
317
class BadInsert(TestBase):
318
"""Test that we trap an insert which should not occur."""
330
' added in version 1',
337
self.assertRaises(WeaveFormatError,
341
self.assertRaises(WeaveFormatError,
346
164
class InsertNested(TestBase):
347
165
"""Insertion with nested instructions."""
348
166
def runTest(self):
481
297
"alternative second line"])
485
class ReplaceLine(TestBase):
489
text0 = ['cheddar', 'stilton', 'gruyere']
490
text1 = ['cheddar', 'blue vein', 'neufchatel', 'chevre']
495
self.log('k._l=' + pformat(k._l))
497
self.assertEqual(k.get(0), text0)
498
self.assertEqual(k.get(1), text1)
503
class Khayyam(TestBase):
506
"""A Book of Verses underneath the Bough,
507
A Jug of Wine, a Loaf of Bread, -- and Thou
508
Beside me singing in the Wilderness --
509
Oh, Wilderness were Paradise enow!""",
511
"""A Book of Verses underneath the Bough,
512
A Jug of Wine, a Loaf of Bread, -- and Thou
513
Beside me singing in the Wilderness --
514
Oh, Wilderness were Paradise now!""",
516
"""A Book of poems underneath the tree,
517
A Jug of Wine, a Loaf of Bread,
519
Beside me singing in the Wilderness --
520
Oh, Wilderness were Paradise now!
524
"""A Book of Verses underneath the Bough,
525
A Jug of Wine, a Loaf of Bread,
527
Beside me singing in the Wilderness --
528
Oh, Wilderness were Paradise now!
531
texts = [[l.strip() for l in t.split('\n')] for t in rawtexts]
536
ver = k.add(parents, t)
539
self.log("k._l=" + pformat(k._l))
541
for i, t in enumerate(texts):
542
self.assertEqual(k.get(i),
549
301
from unittest import TestSuite, TestLoader
552
304
tl = TestLoader()
553
305
suite = TestSuite()
554
306
suite.addTest(tl.loadTestsFromModule(testweave))