~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

  • Committer: Zearin
  • Date: 2010-11-12 22:08:18 UTC
  • mto: (5570.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5572.
  • Revision ID: zearin@users.sourceforge.net-20101112220818-mb62len4zyxr8qvd
Fixed capitalization of XML and HTTP.  Fixed by hand and only where appropriate (e.g., left http://some/url lowercase, but capitalized "When making an HTTP request…").

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