/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 bzrlib/tests/test_conflicts.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-03-25 10:54:06 UTC
  • mfrom: (5113.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100325105406-d1nspg0ryp7ebxm7
(vila) Add XFAIL tests for bug #537956

Show diffs side-by-side

added added

removed removed

Lines of Context:
247
247
    _item_id = None
248
248
 
249
249
    # Set by _this_actions and other_actions
 
250
    # FIXME: rename them this_args and other_args so the tests can use them
 
251
    # more freely
250
252
    _this_path = None
251
253
    _this_id = None
252
254
    _other_path = None
318
320
    def _get_check(self, name):
319
321
        return getattr(self, 'check_%s' % name)
320
322
 
321
 
    def assertConflict(self, wt):
322
 
        confs = wt.conflicts()
323
 
        self.assertLength(1, confs)
324
 
        c = confs[0]
325
 
        self.assertIsInstance(c, self._conflict_type)
326
 
        self._assert_conflict(wt, c)
327
 
 
328
 
    def check_resolved(self, wt, path, action):
329
 
        conflicts.resolve(wt, [path], action=action)
330
 
        # Check that we don't have any conflicts nor unknown left
331
 
        self.assertLength(0, wt.conflicts())
332
 
        self.assertLength(0, list(wt.unknowns()))
 
323
    def do_nothing(self):
 
324
        return (None, None, [])
333
325
 
334
326
    def do_create_file(self):
335
327
        return ('file', 'file-id',
336
328
                [('add', ('file', 'file-id', 'file', 'trunk content\n'))])
337
329
 
 
330
    def do_create_file_a(self):
 
331
        return ('file', 'file-a-id',
 
332
                [('add', ('file', 'file-a-id', 'file', 'file a content\n'))])
 
333
 
 
334
    def check_file_content_a(self):
 
335
        self.assertFileEqual('file a content\n', 'branch/file')
 
336
 
 
337
    def do_create_file_b(self):
 
338
        return ('file', 'file-b-id',
 
339
                [('add', ('file', 'file-b-id', 'file', 'file b content\n'))])
 
340
 
 
341
    def check_file_content_b(self):
 
342
        self.assertFileEqual('file b content\n', 'branch/file')
 
343
 
338
344
    def do_create_dir(self):
339
345
        return ('dir', 'dir-id', [('add', ('dir', 'dir-id', 'directory', ''))])
340
346
 
358
364
        self.failIfExists('branch/file')
359
365
        self.failUnlessExists('branch/new-file')
360
366
 
 
367
    def do_rename_file2(self):
 
368
        return ('new-file2', 'file-id', [('rename', ('file', 'new-file2'))])
 
369
 
 
370
    def check_file_renamed2(self):
 
371
        self.failIfExists('branch/file')
 
372
        self.failUnlessExists('branch/new-file2')
 
373
 
361
374
    def do_rename_dir(self):
362
375
        return ('new-dir', 'dir-id', [('rename', ('dir', 'new-dir'))])
363
376
 
384
397
        wt.merge_from_branch(b, 'other')
385
398
        return wt
386
399
 
 
400
    def assertConflict(self, wt):
 
401
        confs = wt.conflicts()
 
402
        self.assertLength(1, confs)
 
403
        c = confs[0]
 
404
        self.assertIsInstance(c, self._conflict_type)
 
405
        self._assert_conflict(wt, c)
 
406
 
 
407
    def _get_resolve_path_arg(self, wt, action):
 
408
        return self._item_path
 
409
 
 
410
    def check_resolved(self, wt, action):
 
411
        path = self._get_resolve_path_arg(wt, action)
 
412
        conflicts.resolve(wt, [path], action=action)
 
413
        # Check that we don't have any conflicts nor unknown left
 
414
        self.assertLength(0, wt.conflicts())
 
415
        self.assertLength(0, list(wt.unknowns()))
 
416
 
387
417
    def test_resolve_taking_this(self):
388
418
        wt = self._merge_other_into_this()
389
419
        self.assertConflict(wt)
390
 
        self.check_resolved(wt, self._item_path, 'take_this')
 
420
        self.check_resolved(wt, 'take_this')
391
421
        check_this = self._get_check(self._check_this)
392
422
        check_this()
393
423
 
394
424
    def test_resolve_taking_other(self):
395
425
        wt = self._merge_other_into_this()
396
426
        self.assertConflict(wt)
397
 
        self.check_resolved(wt, self._item_path, 'take_other')
 
427
        self.check_resolved(wt, 'take_other')
398
428
        check_other = self._get_check(self._check_other)
399
429
        check_other()
400
430
 
404
434
    _conflict_type = conflicts.ContentsConflict,
405
435
    @classmethod
406
436
    def scenarios(klass):
407
 
        common = dict(_actions_base='create_file',
408
 
                      _item_path='file', item_id='file-id',
409
 
                      )
410
437
        base_scenarios = [
411
438
            (('file_modified', dict(actions='modify_file',
412
439
                                   check='file_has_more_content')),
413
440
             ('file_deleted', dict(actions='delete_file',
414
441
                                   check='file_doesnt_exist')),
415
 
             dict(_actions_base='create_file',
416
 
                  _item_path='file', item_id='file-id',)),
 
442
             dict(_actions_base='create_file', _item_path='file')),
417
443
            ]
418
444
        return klass.mirror_scenarios(base_scenarios)
419
445
 
430
456
 
431
457
    @classmethod
432
458
    def scenarios(klass):
433
 
        for_dirs = dict(_actions_base='create_dir',
 
459
        for_file = dict(_actions_base='create_file',
 
460
                  _item_path='new-file', _item_id='file-id',)
 
461
        for_dir = dict(_actions_base='create_dir',
434
462
                        _item_path='new-dir', _item_id='dir-id',)
435
463
        base_scenarios = [
436
464
            (('file_renamed',
437
465
              dict(actions='rename_file', check='file_renamed')),
438
466
             ('file_deleted',
439
467
              dict(actions='delete_file', check='file_doesnt_exist')),
440
 
             dict(_actions_base='create_file',
441
 
                  _item_path='new-file', _item_id='file-id',)),
 
468
             for_file),
 
469
            (('file_renamed',
 
470
              dict(actions='rename_file', check='file_renamed')),
 
471
             ('file_renamed2',
 
472
              dict(actions='rename_file2', check='file_renamed2')),
 
473
             for_file),
442
474
            (('dir_renamed',
443
475
              dict(actions='rename_dir', check='dir_renamed')),
444
476
             ('dir_deleted',
445
477
              dict(actions='delete_dir', check='dir_doesnt_exist')),
446
 
             for_dirs),
 
478
             for_dir),
447
479
            (('dir_renamed',
448
480
              dict(actions='rename_dir', check='dir_renamed')),
449
481
             ('dir_renamed2',
450
482
              dict(actions='rename_dir2', check='dir_renamed2')),
451
 
             for_dirs),
 
483
             for_dir),
452
484
        ]
453
485
        return klass.mirror_scenarios(base_scenarios)
454
486
 
478
510
        wt.set_conflicts(conflicts.ConflictList([old_c]))
479
511
 
480
512
 
481
 
class TestResolveDuplicateEntry(TestResolveConflicts):
482
 
 
483
 
    preamble = """
484
 
$ bzr init trunk
485
 
$ cd trunk
486
 
$ echo 'trunk content' >file
487
 
$ bzr add file
488
 
$ bzr commit -m 'Create trunk'
489
 
 
490
 
$ echo 'trunk content too' >file2
491
 
$ bzr add file2
492
 
$ bzr commit -m 'Add file2 in trunk'
493
 
 
494
 
$ bzr branch . -r 1 ../branch
495
 
$ cd ../branch
496
 
$ echo 'branch content' >file2
497
 
$ bzr add file2
498
 
$ bzr commit -m 'Add file2 in branch'
499
 
 
500
 
$ bzr merge ../trunk
501
 
2>+N  file2
502
 
2>R   file2 => file2.moved
503
 
2>Conflict adding file file2.  Moved existing file to file2.moved.
504
 
2>1 conflicts encountered.
505
 
"""
506
 
 
507
 
    def test_keep_this(self):
508
 
        self.run_script("""
509
 
$ bzr rm file2  --force
510
 
$ bzr mv file2.moved file2
511
 
$ bzr resolve file2
512
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
513
 
""")
514
 
 
515
 
    def test_keep_other(self):
516
 
        self.failIfExists('branch/file2.moved')
517
 
        self.run_script("""
518
 
$ bzr rm file2.moved --force
519
 
$ bzr resolve file2
520
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
521
 
""")
522
 
        self.failIfExists('branch/file2.moved')
523
 
 
524
 
    def test_resolve_taking_this(self):
525
 
        self.run_script("""
526
 
$ bzr resolve --take-this file2
527
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
528
 
""")
529
 
 
530
 
    def test_resolve_taking_other(self):
531
 
        self.run_script("""
532
 
$ bzr resolve --take-other file2
533
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
534
 
""")
 
513
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
 
514
 
 
515
    _conflict_type = conflicts.DuplicateEntry,
 
516
    @classmethod
 
517
    def scenarios(klass):
 
518
        base_scenarios = [
 
519
            (('filea_created', dict(actions='create_file_a',
 
520
                                    check='file_content_a')),
 
521
             ('fileb_created', dict(actions='create_file_b',
 
522
                                   check='file_content_b')),
 
523
             dict(_actions_base='nothing', _item_path='file')),
 
524
            ]
 
525
        return klass.mirror_scenarios(base_scenarios)
 
526
 
 
527
    def assertDuplicateEntry(self, wt, c):
 
528
        self.assertEqual(self._this_id, c.file_id)
 
529
        self.assertEqual(self._item_path + '.moved', c.path)
 
530
        self.assertEqual(self._item_path, c.conflict_path)
 
531
    _assert_conflict = assertDuplicateEntry
535
532
 
536
533
 
537
534
class TestResolveUnversionedParent(TestResolveConflicts):
701
698
""")
702
699
 
703
700
 
704
 
class OldTestResolvePathConflict(TestResolveConflicts):
705
 
 
706
 
    preamble = """
707
 
$ bzr init trunk
708
 
$ cd trunk
709
 
$ echo 'Boo!' >file
710
 
$ bzr add
711
 
$ bzr commit -m 'Create trunk'
712
 
 
713
 
$ bzr mv file file-in-trunk
714
 
$ bzr commit -m 'Renamed to file-in-trunk'
715
 
 
716
 
$ bzr branch . -r 1 ../branch
717
 
$ cd ../branch
718
 
$ bzr mv file file-in-branch
719
 
$ bzr commit -m 'Renamed to file-in-branch'
720
 
 
721
 
$ bzr merge ../trunk
722
 
2>R   file-in-branch => file-in-trunk
723
 
2>Path conflict: file-in-branch / file-in-trunk
724
 
2>1 conflicts encountered.
725
 
"""
726
 
 
727
 
    def test_keep_source(self):
728
 
        self.run_script("""
729
 
$ bzr resolve file-in-trunk
730
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
731
 
""")
732
 
 
733
 
    def test_keep_target(self):
734
 
        self.run_script("""
735
 
$ bzr mv file-in-trunk file-in-branch
736
 
$ bzr resolve file-in-branch
737
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
738
 
""")
739
 
 
740
 
    def test_resolve_taking_this(self):
741
 
        self.run_script("""
742
 
$ bzr resolve --take-this file-in-branch
743
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
744
 
""")
745
 
 
746
 
    def test_resolve_taking_other(self):
747
 
        self.run_script("""
748
 
$ bzr resolve --take-other file-in-branch
749
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
750
 
""")
751
 
 
752
 
 
753
 
class TestResolveParentLoop(TestResolveConflicts):
 
701
class TestResolveParentLoop(TestParametrizedResolveConflicts):
 
702
 
 
703
    _conflict_type = conflicts.ParentLoop,
 
704
    @classmethod
 
705
    def scenarios(klass):
 
706
        base_scenarios = [
 
707
            (('dir1_into_dir2', dict(actions='move_dir1_into_dir2',
 
708
                                      check='dir1_moved')),
 
709
             ('dir2_into_dir1', dict(actions='move_dir2_into_dir1',
 
710
                                      check='dir2_moved')),
 
711
             dict(_actions_base='create_dir1_dir2')),
 
712
            (('dir1_into_dir4', dict(actions='move_dir1_into_dir4',
 
713
                                      check='dir1_2_moved')),
 
714
             ('dir3_into_dir2', dict(actions='move_dir3_into_dir2',
 
715
                                      check='dir3_4_moved')),
 
716
             dict(_actions_base='create_dir1_4')),
 
717
            ]
 
718
        return klass.mirror_scenarios(base_scenarios)
 
719
 
 
720
    def do_create_dir1_dir2(self):
 
721
        return (None, None,
 
722
                [('add', ('dir1', 'dir1-id', 'directory', '')),
 
723
                 ('add', ('dir2', 'dir2-id', 'directory', '')),
 
724
                 ])
 
725
 
 
726
    def do_move_dir1_into_dir2(self):
 
727
        # The arguments are the file-id to move and the targeted file-id dir.
 
728
        return ('dir1-id', 'dir2-id', [('rename', ('dir1', 'dir2/dir1'))])
 
729
 
 
730
    def check_dir1_moved(self):
 
731
        self.failIfExists('branch/dir1')
 
732
        self.failUnlessExists('branch/dir2/dir1')
 
733
 
 
734
    def do_move_dir2_into_dir1(self):
 
735
        # The arguments are the file-id to move and the targeted file-id dir.
 
736
        return ('dir2-id', 'dir1-id', [('rename', ('dir2', 'dir1/dir2'))])
 
737
 
 
738
    def check_dir2_moved(self):
 
739
        self.failIfExists('branch/dir2')
 
740
        self.failUnlessExists('branch/dir1/dir2')
 
741
 
 
742
    def do_create_dir1_4(self):
 
743
        return (None, None,
 
744
                [('add', ('dir1', 'dir1-id', 'directory', '')),
 
745
                 ('add', ('dir1/dir2', 'dir2-id', 'directory', '')),
 
746
                 ('add', ('dir3', 'dir3-id', 'directory', '')),
 
747
                 ('add', ('dir3/dir4', 'dir4-id', 'directory', '')),
 
748
                 ])
 
749
 
 
750
    def do_move_dir1_into_dir4(self):
 
751
        # The arguments are the file-id to move and the targeted file-id dir.
 
752
        return ('dir1-id', 'dir4-id',
 
753
                [('rename', ('dir1', 'dir3/dir4/dir1'))])
 
754
 
 
755
    def check_dir1_2_moved(self):
 
756
        self.failIfExists('branch/dir1')
 
757
        self.failUnlessExists('branch/dir3/dir4/dir1')
 
758
        self.failUnlessExists('branch/dir3/dir4/dir1/dir2')
 
759
 
 
760
    def do_move_dir3_into_dir2(self):
 
761
        # The arguments are the file-id to move and the targeted file-id dir.
 
762
        return ('dir3-id', 'dir2-id',
 
763
                [('rename', ('dir3', 'dir1/dir2/dir3'))])
 
764
 
 
765
    def check_dir3_4_moved(self):
 
766
        self.failIfExists('branch/dir3')
 
767
        self.failUnlessExists('branch/dir1/dir2/dir3')
 
768
        self.failUnlessExists('branch/dir1/dir2/dir3/dir4')
 
769
 
 
770
    def _get_resolve_path_arg(self, wt, action):
 
771
        # ParentLoop is unsual as it says: 
 
772
        # moving <conflict_path> into <path>.  Cancelled move.
 
773
        # But since <path> doesn't exist in the working tree, we need to use
 
774
        # <conflict_path> instead
 
775
        path = wt.id2path(self._other_id)
 
776
        return path
 
777
 
 
778
    def assertParentLoop(self, wt, c):
 
779
        if 'taking_other(' in self.id() and 'dir4' in self.id():
 
780
            raise tests.KnownFailure(
 
781
                "ParentLoop doesn't carry enough info to resolve")
 
782
        # The relevant file-ids are other_args swapped (which is the main
 
783
        # reason why they should be renamed other_args instead of Other_path
 
784
        # and other_id). In the conflict object, they represent:
 
785
        # c.file_id: the directory being moved
 
786
        # c.conflict_id_id: The target directory
 
787
        self.assertEqual(self._other_path, c.file_id)
 
788
        self.assertEqual(self._other_id, c.conflict_file_id)
 
789
        # The conflict paths are irrelevant (they are deterministic but not
 
790
        # worth checking since they don't provide the needed information
 
791
        # anyway)
 
792
    _assert_conflict = assertParentLoop
 
793
 
 
794
 
 
795
class OldTestResolveParentLoop(TestResolveConflicts):
754
796
 
755
797
    preamble = """
756
798
$ bzr init trunk
768
810
$ bzr commit -m 'Moved dir1 into dir2'
769
811
 
770
812
$ bzr merge ../trunk
771
 
2>Conflict moving dir2/dir1 into dir2.  Cancelled move.
 
813
2>Conflict moving dir2 into dir2/dir1. Cancelled move.
772
814
2>1 conflicts encountered.
773
815
"""
774
816