/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_weave.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-16 19:47:19 UTC
  • mfrom: (7178 work)
  • mto: This revision was merged to the branch mainline in revision 7179.
  • Revision ID: jelmer@jelmer.uk-20181116194719-m5ut2wfuze5x9s1p
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
    """Weave __contains__ operator"""
70
70
 
71
71
    def runTest(self):
72
 
        k = Weave(get_scope=lambda:None)
 
72
        k = Weave(get_scope=lambda: None)
73
73
        self.assertFalse(b'foo' in k)
74
74
        k.add_lines(b'foo', [], TEXT_1)
75
75
        self.assertTrue(b'foo' in k)
78
78
class Easy(TestBase):
79
79
 
80
80
    def runTest(self):
81
 
        k = Weave()
 
81
        Weave()
82
82
 
83
83
 
84
84
class AnnotateOne(TestBase):
118
118
    def runTest(self):
119
119
        k = Weave()
120
120
        k.add_lines(b'basis', [], TEXT_0)
121
 
        idx = k.add_lines(b'text0', [], TEXT_0)
 
121
        k.add_lines(b'text0', [], TEXT_0)
122
122
        self.assertRaises(errors.RevisionAlreadyPresent,
123
123
                          k.add_lines,
124
124
                          b'text0',
136
136
 
137
137
    Look at the annotations to make sure that the first line is matched
138
138
    and not stored repeatedly."""
 
139
 
139
140
    def runTest(self):
140
141
        k = Weave()
141
142
 
161
162
 
162
163
        text3 = [b'line 1', b'middle line', b'line 2']
163
164
        k.add_lines(b'text3',
164
 
              [b'text0', b'text1'],
165
 
              text3)
 
165
                    [b'text0', b'text1'],
 
166
                    text3)
166
167
 
167
 
        # self.log("changes to text3: " + pformat(list(k._delta(set([0, 1]), text3))))
 
168
        # self.log("changes to text3: " + pformat(list(k._delta(set([0, 1]),
 
169
        # text3))))
168
170
 
169
171
        self.log("k._weave=" + pformat(k._weave))
170
172
 
174
176
                          (b'text1', b'line 2')])
175
177
 
176
178
        # now multiple insertions at different places
177
 
        k.add_lines(b'text4',
178
 
              [b'text0', b'text1', b'text3'],
179
 
              [b'line 1', b'aaa', b'middle line', b'bbb', b'line 2', b'ccc'])
 
179
        k.add_lines(
 
180
            b'text4', [b'text0', b'text1', b'text3'],
 
181
            [b'line 1', b'aaa', b'middle line', b'bbb', b'line 2', b'ccc'])
180
182
 
181
183
        self.assertEqual(k.annotate(b'text4'),
182
184
                         [(b'text0', b'line 1'),
191
193
    """Deletion of lines from existing text.
192
194
 
193
195
    Try various texts all based on a common ancestor."""
 
196
 
194
197
    def runTest(self):
195
198
        k = Weave()
196
199
 
206
209
 
207
210
        i = 1
208
211
        for t in texts:
209
 
            ver = k.add_lines(b'text%d' % i,
210
 
                        [b'text0'], t)
 
212
            k.add_lines(b'text%d' % i, [b'text0'], t)
211
213
            i += 1
212
214
 
213
215
        self.log('final weave:')
214
216
        self.log('k._weave=' + pformat(k._weave))
215
217
 
216
218
        for i in range(len(texts)):
217
 
            self.assertEqual(k.get_lines(i+1),
 
219
            self.assertEqual(k.get_lines(i + 1),
218
220
                             texts[i])
219
221
 
220
222
 
221
223
class SuicideDelete(TestBase):
222
224
    """Invalid weave which tries to add and delete simultaneously."""
 
225
 
223
226
    def runTest(self):
224
227
        k = Weave()
225
228
 
226
229
        k._parents = [(),
227
 
                ]
 
230
                      ]
228
231
        k._weave = [(b'{', 0),
229
 
                b'first line',
230
 
                (b'[', 0),
231
 
                b'deleted in 0',
232
 
                (b']', 0),
233
 
                (b'}', 0),
234
 
                ]
235
 
        ################################### SKIPPED
 
232
                    b'first line',
 
233
                    (b'[', 0),
 
234
                    b'deleted in 0',
 
235
                    (b']', 0),
 
236
                    (b'}', 0),
 
237
                    ]
 
238
        # SKIPPED
236
239
        # Weave.get doesn't trap this anymore
237
240
        return
238
241
 
243
246
 
244
247
class CannedDelete(TestBase):
245
248
    """Unpack canned weave with deleted lines."""
 
249
 
246
250
    def runTest(self):
247
251
        k = Weave()
248
252
 
249
253
        k._parents = [(),
250
 
                frozenset([0]),
251
 
                ]
 
254
                      frozenset([0]),
 
255
                      ]
252
256
        k._weave = [(b'{', 0),
253
 
                b'first line',
254
 
                (b'[', 1),
255
 
                b'line to be deleted',
256
 
                (b']', 1),
257
 
                b'last line',
258
 
                (b'}', 0),
259
 
                ]
260
 
        k._sha1s = [sha_string(b'first lineline to be deletedlast line')
261
 
                  , sha_string(b'first linelast line')]
 
257
                    b'first line',
 
258
                    (b'[', 1),
 
259
                    b'line to be deleted',
 
260
                    (b']', 1),
 
261
                    b'last line',
 
262
                    (b'}', 0),
 
263
                    ]
 
264
        k._sha1s = [
 
265
            sha_string(b'first lineline to be deletedlast line'),
 
266
            sha_string(b'first linelast line')]
262
267
 
263
268
        self.assertEqual(k.get_lines(0),
264
269
                         [b'first line',
274
279
 
275
280
class CannedReplacement(TestBase):
276
281
    """Unpack canned weave with deleted lines."""
 
282
 
277
283
    def runTest(self):
278
284
        k = Weave()
279
285
 
280
286
        k._parents = [frozenset(),
281
 
                frozenset([0]),
282
 
                ]
 
287
                      frozenset([0]),
 
288
                      ]
283
289
        k._weave = [(b'{', 0),
284
 
                b'first line',
285
 
                (b'[', 1),
286
 
                b'line to be deleted',
287
 
                (b']', 1),
288
 
                (b'{', 1),
289
 
                b'replacement line',
290
 
                (b'}', 1),
291
 
                b'last line',
292
 
                (b'}', 0),
293
 
                ]
294
 
        k._sha1s = [sha_string(b'first lineline to be deletedlast line')
295
 
                  , sha_string(b'first linereplacement linelast line')]
 
290
                    b'first line',
 
291
                    (b'[', 1),
 
292
                    b'line to be deleted',
 
293
                    (b']', 1),
 
294
                    (b'{', 1),
 
295
                    b'replacement line',
 
296
                    (b'}', 1),
 
297
                    b'last line',
 
298
                    (b'}', 0),
 
299
                    ]
 
300
        k._sha1s = [
 
301
            sha_string(b'first lineline to be deletedlast line'),
 
302
            sha_string(b'first linereplacement linelast line')]
296
303
 
297
304
        self.assertEqual(k.get_lines(0),
298
305
                         [b'first line',
309
316
 
310
317
class BadWeave(TestBase):
311
318
    """Test that we trap an insert which should not occur."""
 
319
 
312
320
    def runTest(self):
313
321
        k = Weave()
314
322
 
315
323
        k._parents = [frozenset(),
316
 
                ]
 
324
                      ]
317
325
        k._weave = [b'bad line',
318
 
                (b'{', 0),
319
 
                b'foo {',
320
 
                (b'{', 1),
321
 
                b'  added in version 1',
322
 
                (b'{', 2),
323
 
                b'  added in v2',
324
 
                (b'}', 2),
325
 
                b'  also from v1',
326
 
                (b'}', 1),
327
 
                b'}',
328
 
                (b'}', 0)]
 
326
                    (b'{', 0),
 
327
                    b'foo {',
 
328
                    (b'{', 1),
 
329
                    b'  added in version 1',
 
330
                    (b'{', 2),
 
331
                    b'  added in v2',
 
332
                    (b'}', 2),
 
333
                    b'  also from v1',
 
334
                    (b'}', 1),
 
335
                    b'}',
 
336
                    (b'}', 0)]
329
337
 
330
 
        ################################### SKIPPED
 
338
        # SKIPPED
331
339
        # Weave.get doesn't trap this anymore
332
340
        return
333
341
 
334
 
 
335
342
        self.assertRaises(WeaveFormatError,
336
343
                          k.get,
337
344
                          0)
339
346
 
340
347
class BadInsert(TestBase):
341
348
    """Test that we trap an insert which should not occur."""
 
349
 
342
350
    def runTest(self):
343
351
        k = Weave()
344
352
 
345
353
        k._parents = [frozenset(),
346
 
                frozenset([0]),
347
 
                frozenset([0]),
348
 
                frozenset([0, 1, 2]),
349
 
                ]
 
354
                      frozenset([0]),
 
355
                      frozenset([0]),
 
356
                      frozenset([0, 1, 2]),
 
357
                      ]
350
358
        k._weave = [(b'{', 0),
351
 
                b'foo {',
352
 
                (b'{', 1),
353
 
                b'  added in version 1',
354
 
                (b'{', 1),
355
 
                b'  more in 1',
356
 
                (b'}', 1),
357
 
                (b'}', 1),
358
 
                (b'}', 0)]
359
 
 
 
359
                    b'foo {',
 
360
                    (b'{', 1),
 
361
                    b'  added in version 1',
 
362
                    (b'{', 1),
 
363
                    b'  more in 1',
 
364
                    (b'}', 1),
 
365
                    (b'}', 1),
 
366
                    (b'}', 0)]
360
367
 
361
368
        # this is not currently enforced by get
362
 
        return  ##########################################
 
369
        return
363
370
 
364
371
        self.assertRaises(WeaveFormatError,
365
372
                          k.get,
372
379
 
373
380
class InsertNested(TestBase):
374
381
    """Insertion with nested instructions."""
 
382
 
375
383
    def runTest(self):
376
384
        k = Weave()
377
385
 
378
386
        k._parents = [frozenset(),
379
 
                frozenset([0]),
380
 
                frozenset([0]),
381
 
                frozenset([0, 1, 2]),
382
 
                ]
 
387
                      frozenset([0]),
 
388
                      frozenset([0]),
 
389
                      frozenset([0, 1, 2]),
 
390
                      ]
383
391
        k._weave = [(b'{', 0),
384
 
                b'foo {',
385
 
                (b'{', 1),
386
 
                b'  added in version 1',
387
 
                (b'{', 2),
388
 
                b'  added in v2',
389
 
                (b'}', 2),
390
 
                b'  also from v1',
391
 
                (b'}', 1),
392
 
                b'}',
393
 
                (b'}', 0)]
 
392
                    b'foo {',
 
393
                    (b'{', 1),
 
394
                    b'  added in version 1',
 
395
                    (b'{', 2),
 
396
                    b'  added in v2',
 
397
                    (b'}', 2),
 
398
                    b'  also from v1',
 
399
                    (b'}', 1),
 
400
                    b'}',
 
401
                    (b'}', 0)]
394
402
 
395
 
        k._sha1s = [sha_string(b'foo {}')
396
 
                  , sha_string(b'foo {  added in version 1  also from v1}')
397
 
                  , sha_string(b'foo {  added in v2}')
398
 
                  , sha_string(b'foo {  added in version 1  added in v2  also from v1}')
399
 
                  ]
 
403
        k._sha1s = [
 
404
            sha_string(b'foo {}'),
 
405
            sha_string(b'foo {  added in version 1  also from v1}'),
 
406
            sha_string(b'foo {  added in v2}'),
 
407
            sha_string(
 
408
                b'foo {  added in version 1  added in v2  also from v1}')
 
409
            ]
400
410
 
401
411
        self.assertEqual(k.get_lines(0),
402
412
                         [b'foo {',
426
436
 
427
437
    This relies on the weave having a way to represent lines knocked
428
438
    out by a later revision."""
 
439
 
429
440
    def runTest(self):
430
441
        k = Weave()
431
442
 
432
443
        k.add_lines(b'text0', [], [b"line the first",
433
 
                   b"line 2",
434
 
                   b"line 3",
435
 
                   b"fine"])
 
444
                                   b"line 2",
 
445
                                   b"line 3",
 
446
                                   b"fine"])
436
447
 
437
448
        self.assertEqual(len(k.get_lines(0)), 4)
438
449
 
439
450
        k.add_lines(b'text1', [b'text0'], [b"line the first",
440
 
                   b"fine"])
 
451
                                           b"fine"])
441
452
 
442
453
        self.assertEqual(k.get_lines(1),
443
454
                         [b"line the first",
463
474
 
464
475
        k._parents = [frozenset(), frozenset([0])]
465
476
        k._weave = [(b'{', 0),
466
 
                b"first line",
467
 
                (b'}', 0),
468
 
                (b'{', 1),
469
 
                b"second line",
470
 
                (b'}', 1)]
 
477
                    b"first line",
 
478
                    (b'}', 0),
 
479
                    (b'{', 1),
 
480
                    b"second line",
 
481
                    (b'}', 1)]
471
482
 
472
 
        k._sha1s = [sha_string(b'first line')
473
 
                  , sha_string(b'first linesecond line')]
 
483
        k._sha1s = [sha_string(b'first line'), sha_string(
 
484
            b'first linesecond line')]
474
485
 
475
486
        self.assertEqual(k.get_lines(1),
476
487
                         [b"first line",
483
494
class DivergedIncludes(TestBase):
484
495
    """Weave with two diverged texts based on version 0.
485
496
    """
 
497
 
486
498
    def runTest(self):
487
499
        # FIXME make the weave, dont poke at it.
488
500
        k = Weave()
489
501
 
490
502
        k._names = [b'0', b'1', b'2']
491
 
        k._name_map = {b'0':0, b'1':1, b'2':2}
 
503
        k._name_map = {b'0': 0, b'1': 1, b'2': 2}
492
504
        k._parents = [frozenset(),
493
 
                frozenset([0]),
494
 
                frozenset([0]),
495
 
                ]
 
505
                      frozenset([0]),
 
506
                      frozenset([0]),
 
507
                      ]
496
508
        k._weave = [(b'{', 0),
497
 
                b"first line",
498
 
                (b'}', 0),
499
 
                (b'{', 1),
500
 
                b"second line",
501
 
                (b'}', 1),
502
 
                (b'{', 2),
503
 
                b"alternative second line",
504
 
                (b'}', 2),
505
 
                ]
 
509
                    b"first line",
 
510
                    (b'}', 0),
 
511
                    (b'{', 1),
 
512
                    b"second line",
 
513
                    (b'}', 1),
 
514
                    (b'{', 2),
 
515
                    b"alternative second line",
 
516
                    (b'}', 2),
 
517
                    ]
506
518
 
507
 
        k._sha1s = [sha_string(b'first line')
508
 
                  , sha_string(b'first linesecond line')
509
 
                  , sha_string(b'first linealternative second line')]
 
519
        k._sha1s = [
 
520
            sha_string(b'first line'),
 
521
            sha_string(b'first linesecond line'),
 
522
            sha_string(b'first linealternative second line')]
510
523
 
511
524
        self.assertEqual(k.get_lines(0),
512
525
                         [b"first line"])
545
558
    def runTest(self):
546
559
        k = Weave()
547
560
 
548
 
        texts = [[b'header'],
549
 
                 [b'header', b'', b'line from 1'],
550
 
                 [b'header', b'', b'line from 2', b'more from 2'],
551
 
                 [b'header', b'', b'line from 1', b'fixup line', b'line from 2'],
552
 
                 ]
 
561
        texts = [
 
562
            [b'header'],
 
563
            [b'header', b'', b'line from 1'],
 
564
            [b'header', b'', b'line from 2', b'more from 2'],
 
565
            [b'header', b'', b'line from 1', b'fixup line', b'line from 2'],
 
566
            ]
553
567
 
554
568
        k.add_lines(b'text0', [], texts[0])
555
569
        k.add_lines(b'text1', [b'text0'], texts[1])
581
595
    A base version is inserted, then two descendents try to
582
596
    insert different lines in the same place.  These should be
583
597
    reported as a possible conflict and forwarded to the user."""
 
598
 
584
599
    def runTest(self):
585
600
        return  # NOT RUN
586
601
        k = Weave()
589
604
        k.add_lines([0], [b'aaa', b'111', b'bbb'])
590
605
        k.add_lines([1], [b'aaa', b'222', b'bbb'])
591
606
 
592
 
        merged = k.merge([1, 2])
 
607
        k.merge([1, 2])
593
608
 
594
609
        self.assertEqual([[[b'aaa']],
595
 
                           [[b'111'], [b'222']],
596
 
                           [[b'bbb']]])
 
610
                          [[b'111'], [b'222']],
 
611
                          [[b'bbb']]])
597
612
 
598
613
 
599
614
class NonConflict(TestBase):
600
615
    """Two descendants insert compatible changes.
601
616
 
602
617
    No conflict should be reported."""
 
618
 
603
619
    def runTest(self):
604
620
        return  # NOT RUN
605
621
        k = Weave()
644
660
        parents = set()
645
661
        i = 0
646
662
        for t in texts:
647
 
            ver = k.add_lines(b'text%d' % i,
648
 
                        list(parents), t)
 
663
            k.add_lines(b'text%d' % i, list(parents), t)
649
664
            parents.add(b'text%d' % i)
650
665
            i += 1
651
666
 
682
697
        tmpf = BytesIO()
683
698
        write_weave(w, tmpf)
684
699
 
685
 
        # Because we are corrupting, we need to make sure we have the exact text
686
 
        self.assertEqual(b'# bzr weave file v5\n'
687
 
                         b'i\n1 f572d396fae9206628714fb2ce00f72e94f2258f\nn v1\n\n'
688
 
                         b'i 0\n1 90f265c6e75f1c8f9ab76dcf85528352c5f215ef\nn v2\n\n'
689
 
                         b'w\n{ 0\n. hello\n}\n{ 1\n. there\n}\nW\n',
690
 
                         tmpf.getvalue())
 
700
        # Because we are corrupting, we need to make sure we have the exact
 
701
        # text
 
702
        self.assertEqual(
 
703
            b'# bzr weave file v5\n'
 
704
            b'i\n1 f572d396fae9206628714fb2ce00f72e94f2258f\nn v1\n\n'
 
705
            b'i 0\n1 90f265c6e75f1c8f9ab76dcf85528352c5f215ef\nn v2\n\n'
 
706
            b'w\n{ 0\n. hello\n}\n{ 1\n. there\n}\nW\n',
 
707
            tmpf.getvalue())
691
708
 
692
709
        # Change a single letter
693
 
        tmpf = BytesIO(b'# bzr weave file v5\n'
694
 
                       b'i\n1 f572d396fae9206628714fb2ce00f72e94f2258f\nn v1\n\n'
695
 
                       b'i 0\n1 90f265c6e75f1c8f9ab76dcf85528352c5f215ef\nn v2\n\n'
696
 
                       b'w\n{ 0\n. hello\n}\n{ 1\n. There\n}\nW\n')
 
710
        tmpf = BytesIO(
 
711
            b'# bzr weave file v5\n'
 
712
            b'i\n1 f572d396fae9206628714fb2ce00f72e94f2258f\nn v1\n\n'
 
713
            b'i 0\n1 90f265c6e75f1c8f9ab76dcf85528352c5f215ef\nn v2\n\n'
 
714
            b'w\n{ 0\n. hello\n}\n{ 1\n. There\n}\nW\n')
697
715
 
698
716
        w = read_weave(tmpf)
699
717
 
703
721
        self.assertRaises(WeaveInvalidChecksum, w.check)
704
722
 
705
723
        # Change the sha checksum
706
 
        tmpf = BytesIO(b'# bzr weave file v5\n'
707
 
                       b'i\n1 f572d396fae9206628714fb2ce00f72e94f2258f\nn v1\n\n'
708
 
                       b'i 0\n1 f0f265c6e75f1c8f9ab76dcf85528352c5f215ef\nn v2\n\n'
709
 
                       b'w\n{ 0\n. hello\n}\n{ 1\n. there\n}\nW\n')
 
724
        tmpf = BytesIO(
 
725
            b'# bzr weave file v5\n'
 
726
            b'i\n1 f572d396fae9206628714fb2ce00f72e94f2258f\nn v1\n\n'
 
727
            b'i 0\n1 f0f265c6e75f1c8f9ab76dcf85528352c5f215ef\nn v2\n\n'
 
728
            b'w\n{ 0\n. hello\n}\n{ 1\n. there\n}\nW\n')
710
729
 
711
730
        w = read_weave(tmpf)
712
731