~bzr-pqm/bzr/bzr.dev

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