~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    tests,
27
27
    workingtree,
28
28
    )
29
 
from bzrlib.tests import (
30
 
    script,
31
 
    scenarios,
32
 
    )
33
 
 
34
 
 
35
 
load_tests = scenarios.load_tests_apply_scenarios
 
29
from bzrlib.tests import script
 
30
 
 
31
 
 
32
def load_tests(standard_tests, module, loader):
 
33
    result = loader.suiteClass()
 
34
 
 
35
    sp_tests, remaining_tests = tests.split_suite_by_condition(
 
36
        standard_tests, tests.condition_isinstance((
 
37
                TestParametrizedResolveConflicts,
 
38
                )))
 
39
    # Each test class defines its own scenarios. This is needed for
 
40
    # TestResolvePathConflictBefore531967 that verifies that the same tests as
 
41
    # TestResolvePathConflict still pass.
 
42
    for test in tests.iter_suite_tests(sp_tests):
 
43
        tests.apply_scenarios(test, test.scenarios(), result)
 
44
 
 
45
    # No parametrization for the remaining tests
 
46
    result.addTests(remaining_tests)
 
47
 
 
48
    return result
36
49
 
37
50
 
38
51
# TODO: Test commit with some added, and added-but-missing files
280
293
    _this = None
281
294
    _other = None
282
295
 
283
 
    scenarios = []
284
 
    """The scenario list for the conflict type defined by the class.
285
 
 
286
 
    Each scenario is of the form:
287
 
    (common, (left_name, left_dict), (right_name, right_dict))
288
 
 
289
 
    * common is a dict
290
 
 
291
 
    * left_name and right_name are the scenario names that will be combined
292
 
 
293
 
    * left_dict and right_dict are the attributes specific to each half of
294
 
      the scenario. They should include at least 'actions' and 'check' and
295
 
      will be available as '_this' and '_other' test instance attributes.
296
 
 
297
 
    Daughters classes are free to add their specific attributes as they see
298
 
    fit in any of the three dicts.
299
 
 
300
 
    This is a class method so that load_tests can find it.
301
 
 
302
 
    '_base_actions' in the common dict, 'actions' and 'check' in the left
303
 
    and right dicts use names that map to methods in the test classes. Some
304
 
    prefixes are added to these names to get the correspong methods (see
305
 
    _get_actions() and _get_check()). The motivation here is to avoid
306
 
    collisions in the class namespace.
307
 
    """
 
296
    @staticmethod
 
297
    def scenarios():
 
298
        """Return the scenario list for the conflict type defined by the class.
 
299
 
 
300
        Each scenario is of the form:
 
301
        (common, (left_name, left_dict), (right_name, right_dict))
 
302
 
 
303
        * common is a dict
 
304
 
 
305
        * left_name and right_name are the scenario names that will be combined
 
306
 
 
307
        * left_dict and right_dict are the attributes specific to each half of
 
308
          the scenario. They should include at least 'actions' and 'check' and
 
309
          will be available as '_this' and '_other' test instance attributes.
 
310
 
 
311
        Daughters classes are free to add their specific attributes as they see
 
312
        fit in any of the three dicts.
 
313
 
 
314
        This is a class method so that load_tests can find it.
 
315
 
 
316
        '_base_actions' in the common dict, 'actions' and 'check' in the left
 
317
        and right dicts use names that map to methods in the test classes. Some
 
318
        prefixes are added to these names to get the correspong methods (see
 
319
        _get_actions() and _get_check()). The motivation here is to avoid
 
320
        collisions in the class namespace.
 
321
        """
 
322
        # Only concrete classes return actual scenarios
 
323
        return []
308
324
 
309
325
    def setUp(self):
310
326
        super(TestParametrizedResolveConflicts, self).setUp()
374
390
 
375
391
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
376
392
 
377
 
    _conflict_type = conflicts.ContentsConflict
 
393
    _conflict_type = conflicts.ContentsConflict,
378
394
 
379
 
    # Set by the scenarios
 
395
    # Set by load_tests from scenarios()
380
396
    # path and file-id for the file involved in the conflict
381
397
    _path = None
382
398
    _file_id = None
383
399
 
384
 
    scenarios = mirror_scenarios(
385
 
        [
 
400
    @staticmethod
 
401
    def scenarios():
 
402
        base_scenarios = [
386
403
            # File modified/deleted
387
404
            (dict(_base_actions='create_file',
388
405
                  _path='file', _file_id='file-id'),
390
407
              dict(actions='modify_file', check='file_has_more_content')),
391
408
             ('file_deleted',
392
409
              dict(actions='delete_file', check='file_doesnt_exist')),),
393
 
            ])
 
410
            ]
 
411
        return mirror_scenarios(base_scenarios)
394
412
 
395
413
    def do_create_file(self):
396
414
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
418
436
 
419
437
class TestResolvePathConflict(TestParametrizedResolveConflicts):
420
438
 
421
 
    _conflict_type = conflicts.PathConflict
 
439
    _conflict_type = conflicts.PathConflict,
422
440
 
423
441
    def do_nothing(self):
424
442
        return []
425
443
 
426
 
    # Each side dict additionally defines:
427
 
    # - path path involved (can be '<deleted>')
428
 
    # - file-id involved
429
 
    scenarios = mirror_scenarios(
430
 
        [
 
444
    @staticmethod
 
445
    def scenarios():
 
446
        # Each side dict additionally defines:
 
447
        # - path path involved (can be '<deleted>')
 
448
        # - file-id involved
 
449
        base_scenarios = [
431
450
            # File renamed/deleted
432
451
            (dict(_base_actions='create_file'),
433
452
             ('file_renamed',
464
483
             ('dir_renamed2',
465
484
              dict(actions='rename_dir2', check='dir_renamed2',
466
485
                   path='new-dir2', file_id='dir-id')),),
467
 
            ])
 
486
        ]
 
487
        return mirror_scenarios(base_scenarios)
468
488
 
469
489
    def do_create_file(self):
470
490
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
548
568
 
549
569
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
550
570
 
551
 
    _conflict_type = conflicts.DuplicateEntry
 
571
    _conflict_type = conflicts.DuplicateEntry,
552
572
 
553
 
    scenarios = mirror_scenarios(
554
 
        [
 
573
    @staticmethod
 
574
    def scenarios():
 
575
        # Each side dict additionally defines:
 
576
        # - path involved
 
577
        # - file-id involved
 
578
        base_scenarios = [
555
579
            # File created with different file-ids
556
580
            (dict(_base_actions='nothing'),
557
581
             ('filea_created',
560
584
             ('fileb_created',
561
585
              dict(actions='create_file_b', check='file_content_b',
562
586
                   path='file', file_id='file-b-id')),),
563
 
            ])
 
587
            ]
 
588
        return mirror_scenarios(base_scenarios)
564
589
 
565
590
    def do_nothing(self):
566
591
        return []
600
625
    # tests MissingParent resolution :-/
601
626
    preamble = """
602
627
$ bzr init trunk
603
 
...
604
628
$ cd trunk
605
629
$ mkdir dir
606
 
$ bzr add -q dir
607
 
$ bzr commit -m 'Create trunk' -q
 
630
$ bzr add dir
 
631
$ bzr commit -m 'Create trunk'
 
632
 
608
633
$ echo 'trunk content' >dir/file
609
 
$ bzr add -q dir/file
610
 
$ bzr commit -q -m 'Add dir/file in trunk'
611
 
$ bzr branch -q . -r 1 ../branch
 
634
$ bzr add dir/file
 
635
$ bzr commit -m 'Add dir/file in trunk'
 
636
 
 
637
$ bzr branch . -r 1 ../branch
612
638
$ cd ../branch
613
 
$ bzr rm dir -q
614
 
$ bzr commit -q -m 'Remove dir in branch'
 
639
$ bzr rm dir
 
640
$ bzr commit -m 'Remove dir in branch'
 
641
 
615
642
$ bzr merge ../trunk
616
643
2>+N  dir/
617
644
2>+N  dir/file
622
649
 
623
650
    def test_take_this(self):
624
651
        self.run_script("""
625
 
$ bzr rm -q dir  --force
 
652
$ bzr rm dir  --force
626
653
$ bzr resolve dir
627
 
2>2 conflict(s) resolved, 0 remaining
628
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
654
$ bzr commit --strict -m 'No more conflicts nor unknown files'
629
655
""")
630
656
 
631
657
    def test_take_other(self):
632
658
        self.run_script("""
633
659
$ bzr resolve dir
634
 
2>2 conflict(s) resolved, 0 remaining
635
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
660
$ bzr commit --strict -m 'No more conflicts nor unknown files'
636
661
""")
637
662
 
638
663
 
640
665
 
641
666
    preamble = """
642
667
$ bzr init trunk
643
 
...
644
668
$ cd trunk
645
669
$ mkdir dir
646
670
$ echo 'trunk content' >dir/file
647
 
$ bzr add -q
648
 
$ bzr commit -m 'Create trunk' -q
 
671
$ bzr add
 
672
$ bzr commit -m 'Create trunk'
 
673
 
649
674
$ echo 'trunk content' >dir/file2
650
 
$ bzr add -q dir/file2
651
 
$ bzr commit -q -m 'Add dir/file2 in branch'
652
 
$ bzr branch -q . -r 1 ../branch
 
675
$ bzr add dir/file2
 
676
$ bzr commit -m 'Add dir/file2 in branch'
 
677
 
 
678
$ bzr branch . -r 1 ../branch
653
679
$ cd ../branch
654
 
$ bzr rm -q dir/file --force
655
 
$ bzr rm -q dir
656
 
$ bzr commit -q -m 'Remove dir/file'
 
680
$ bzr rm dir/file --force
 
681
$ bzr rm dir
 
682
$ bzr commit -m 'Remove dir/file'
 
683
 
657
684
$ bzr merge ../trunk
658
685
2>+N  dir/
659
686
2>+N  dir/file2
665
692
    def test_keep_them_all(self):
666
693
        self.run_script("""
667
694
$ bzr resolve dir
668
 
2>2 conflict(s) resolved, 0 remaining
669
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
695
$ bzr commit --strict -m 'No more conflicts nor unknown files'
670
696
""")
671
697
 
672
698
    def test_adopt_child(self):
673
699
        self.run_script("""
674
 
$ bzr mv -q dir/file2 file2
675
 
$ bzr rm -q dir --force
 
700
$ bzr mv dir/file2 file2
 
701
$ bzr rm dir --force
676
702
$ bzr resolve dir
677
 
2>2 conflict(s) resolved, 0 remaining
678
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
703
$ bzr commit --strict -m 'No more conflicts nor unknown files'
679
704
""")
680
705
 
681
706
    def test_kill_them_all(self):
682
707
        self.run_script("""
683
 
$ bzr rm -q dir --force
 
708
$ bzr rm dir --force
684
709
$ bzr resolve dir
685
 
2>2 conflict(s) resolved, 0 remaining
686
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
710
$ bzr commit --strict -m 'No more conflicts nor unknown files'
687
711
""")
688
712
 
689
713
    def test_resolve_taking_this(self):
690
714
        self.run_script("""
691
715
$ bzr resolve --take-this dir
692
 
2>...
693
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
716
$ bzr commit --strict -m 'No more conflicts nor unknown files'
694
717
""")
695
718
 
696
719
    def test_resolve_taking_other(self):
697
720
        self.run_script("""
698
721
$ bzr resolve --take-other dir
699
 
2>...
700
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
722
$ bzr commit --strict -m 'No more conflicts nor unknown files'
701
723
""")
702
724
 
703
725
 
705
727
 
706
728
    preamble = """
707
729
$ bzr init trunk
708
 
...
709
730
$ cd trunk
710
731
$ mkdir dir
711
732
$ echo 'trunk content' >dir/file
712
 
$ bzr add -q
713
 
$ bzr commit -m 'Create trunk' -q
714
 
$ bzr rm -q dir/file --force
715
 
$ bzr rm -q dir --force
716
 
$ bzr commit -q -m 'Remove dir/file'
717
 
$ bzr branch -q . -r 1 ../branch
 
733
$ bzr add
 
734
$ bzr commit -m 'Create trunk'
 
735
 
 
736
$ bzr rm dir/file --force
 
737
$ bzr rm dir --force
 
738
$ bzr commit -m 'Remove dir/file'
 
739
 
 
740
$ bzr branch . -r 1 ../branch
718
741
$ cd ../branch
719
742
$ echo 'branch content' >dir/file2
720
 
$ bzr add -q dir/file2
721
 
$ bzr commit -q -m 'Add dir/file2 in branch'
 
743
$ bzr add dir/file2
 
744
$ bzr commit -m 'Add dir/file2 in branch'
 
745
 
722
746
$ bzr merge ../trunk
723
747
2>-D  dir/file
724
748
2>Conflict: can't delete dir because it is not empty.  Not deleting.
729
753
    def test_keep_them_all(self):
730
754
        self.run_script("""
731
755
$ bzr resolve dir
732
 
2>2 conflict(s) resolved, 0 remaining
733
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
756
$ bzr commit --strict -m 'No more conflicts nor unknown files'
734
757
""")
735
758
 
736
759
    def test_adopt_child(self):
737
760
        self.run_script("""
738
 
$ bzr mv -q dir/file2 file2
739
 
$ bzr rm -q dir --force
 
761
$ bzr mv dir/file2 file2
 
762
$ bzr rm dir --force
740
763
$ bzr resolve dir
741
 
2>2 conflict(s) resolved, 0 remaining
742
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
764
$ bzr commit --strict -m 'No more conflicts nor unknown files'
743
765
""")
744
766
 
745
767
    def test_kill_them_all(self):
746
768
        self.run_script("""
747
 
$ bzr rm -q dir --force
 
769
$ bzr rm dir --force
748
770
$ bzr resolve dir
749
 
2>2 conflict(s) resolved, 0 remaining
750
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
771
$ bzr commit --strict -m 'No more conflicts nor unknown files'
751
772
""")
752
773
 
753
774
    def test_resolve_taking_this(self):
754
775
        self.run_script("""
755
776
$ bzr resolve --take-this dir
756
 
2>2 conflict(s) resolved, 0 remaining
757
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
777
$ bzr commit --strict -m 'No more conflicts nor unknown files'
758
778
""")
759
779
 
760
780
    def test_resolve_taking_other(self):
761
781
        self.run_script("""
762
782
$ bzr resolve --take-other dir
763
 
2>deleted dir/file2
764
 
2>deleted dir
765
 
2>2 conflict(s) resolved, 0 remaining
766
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
783
$ bzr commit --strict -m 'No more conflicts nor unknown files'
767
784
""")
768
785
 
769
786
 
770
787
class TestResolveParentLoop(TestParametrizedResolveConflicts):
771
788
 
772
 
    _conflict_type = conflicts.ParentLoop
 
789
    _conflict_type = conflicts.ParentLoop,
773
790
 
774
791
    _this_args = None
775
792
    _other_args = None
776
793
 
777
 
    # Each side dict additionally defines:
778
 
    # - dir_id: the directory being moved
779
 
    # - target_id: The target directory
780
 
    # - xfail: whether the test is expected to fail if the action is
781
 
    #   involved as 'other'
782
 
    scenarios = mirror_scenarios(
783
 
        [
 
794
    @staticmethod
 
795
    def scenarios():
 
796
        # Each side dict additionally defines:
 
797
        # - dir_id: the directory being moved
 
798
        # - target_id: The target directory
 
799
        # - xfail: whether the test is expected to fail if the action is
 
800
        #     involved as 'other'
 
801
        base_scenarios = [
784
802
            # Dirs moved into each other
785
803
            (dict(_base_actions='create_dir1_dir2'),
786
804
             ('dir1_into_dir2',
797
815
             ('dir3_into_dir2',
798
816
              dict(actions='move_dir3_into_dir2', check='dir3_4_moved',
799
817
                   dir_id='dir3-id', target_id='dir2-id', xfail=True))),
800
 
            ])
 
818
            ]
 
819
        return mirror_scenarios(base_scenarios)
801
820
 
802
821
    def do_create_dir1_dir2(self):
803
822
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
863
882
 
864
883
    preamble = """
865
884
$ bzr init trunk
866
 
...
867
885
$ cd trunk
868
886
$ bzr mkdir foo
869
 
...
870
 
$ bzr commit -m 'Create trunk' -q
 
887
$ bzr commit -m 'Create trunk'
871
888
$ echo "Boing" >foo/bar
872
 
$ bzr add -q foo/bar
873
 
$ bzr commit -q -m 'Add foo/bar'
874
 
$ bzr branch -q . -r 1 ../branch
 
889
$ bzr add foo/bar
 
890
$ bzr commit -m 'Add foo/bar'
 
891
 
 
892
$ bzr branch . -r 1 ../branch
875
893
$ cd ../branch
876
894
$ rm -r foo
877
895
$ echo "Boo!" >foo
878
 
$ bzr commit -q -m 'foo is now a file'
 
896
$ bzr commit -m 'foo is now a file'
 
897
 
879
898
$ bzr merge ../trunk
880
899
2>+N  foo.new/bar
881
900
2>RK  foo => foo.new/
887
906
 
888
907
    def test_take_this(self):
889
908
        self.run_script("""
890
 
$ bzr rm -q foo.new --force
 
909
$ bzr rm foo.new --force
891
910
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
892
911
# aside ? -- vila 090916
893
 
$ bzr add -q foo
 
912
$ bzr add foo
894
913
$ bzr resolve foo.new
895
 
2>1 conflict(s) resolved, 0 remaining
896
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
914
$ bzr commit --strict -m 'No more conflicts nor unknown files'
897
915
""")
898
916
 
899
917
    def test_take_other(self):
900
918
        self.run_script("""
901
 
$ bzr rm -q foo --force
902
 
$ bzr mv -q foo.new foo
 
919
$ bzr rm foo --force
 
920
$ bzr mv foo.new foo
903
921
$ bzr resolve foo
904
 
2>1 conflict(s) resolved, 0 remaining
905
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
922
$ bzr commit --strict -m 'No more conflicts nor unknown files'
906
923
""")
907
924
 
908
925
    def test_resolve_taking_this(self):
909
926
        self.run_script("""
910
927
$ bzr resolve --take-this foo.new
911
 
2>...
912
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
928
$ bzr commit --strict -m 'No more conflicts nor unknown files'
913
929
""")
914
930
 
915
931
    def test_resolve_taking_other(self):
916
932
        self.run_script("""
917
933
$ bzr resolve --take-other foo.new
918
 
2>...
919
 
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
 
934
$ bzr commit --strict -m 'No more conflicts nor unknown files'
920
935
""")
921
936
 
922
937
 
928
943
        # conflict.
929
944
        self.run_script("""
930
945
$ bzr init trunk
931
 
...
932
946
$ cd trunk
933
947
$ bzr mkdir foo
934
 
...
935
 
$ bzr commit -m 'Create trunk' -q
 
948
$ bzr commit -m 'Create trunk'
936
949
$ rm -r foo
937
950
$ echo "Boo!" >foo
938
 
$ bzr commit -m 'foo is now a file' -q
939
 
$ bzr branch -q . -r 1 ../branch -q
 
951
$ bzr commit -m 'foo is now a file'
 
952
 
 
953
$ bzr branch . -r 1 ../branch
940
954
$ cd ../branch
941
955
$ echo "Boing" >foo/bar
942
 
$ bzr add -q foo/bar -q
943
 
$ bzr commit -m 'Add foo/bar' -q
 
956
$ bzr add foo/bar
 
957
$ bzr commit -m 'Add foo/bar'
 
958
 
944
959
$ bzr merge ../trunk
945
960
2>bzr: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]
946
961
""")