~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

  • Committer: Jelmer Vernooij
  • Date: 2010-12-20 11:57:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5577.
  • Revision ID: jelmer@samba.org-20101220115714-2ru3hfappjweeg7q
Don't use no-plugins.

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
210
197
        self.run_script(self.preamble)
211
198
 
212
199
 
213
 
class TestResolveTextConflicts(TestResolveConflicts):
214
 
    # TBC
215
 
    pass
216
 
 
217
 
 
218
200
def mirror_scenarios(base_scenarios):
219
201
    """Return a list of mirrored scenarios.
220
202
 
293
275
    _this = None
294
276
    _other = None
295
277
 
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 []
 
278
    scenarios = []
 
279
    """The scenario list for the conflict type defined by the class.
 
280
 
 
281
    Each scenario is of the form:
 
282
    (common, (left_name, left_dict), (right_name, right_dict))
 
283
 
 
284
    * common is a dict
 
285
 
 
286
    * left_name and right_name are the scenario names that will be combined
 
287
 
 
288
    * left_dict and right_dict are the attributes specific to each half of
 
289
      the scenario. They should include at least 'actions' and 'check' and
 
290
      will be available as '_this' and '_other' test instance attributes.
 
291
 
 
292
    Daughters classes are free to add their specific attributes as they see
 
293
    fit in any of the three dicts.
 
294
 
 
295
    This is a class method so that load_tests can find it.
 
296
 
 
297
    '_base_actions' in the common dict, 'actions' and 'check' in the left
 
298
    and right dicts use names that map to methods in the test classes. Some
 
299
    prefixes are added to these names to get the correspong methods (see
 
300
    _get_actions() and _get_check()). The motivation here is to avoid
 
301
    collisions in the class namespace.
 
302
    """
324
303
 
325
304
    def setUp(self):
326
305
        super(TestParametrizedResolveConflicts, self).setUp()
388
367
        check_other()
389
368
 
390
369
 
 
370
class TestResolveTextConflicts(TestParametrizedResolveConflicts):
 
371
 
 
372
    _conflict_type = conflicts.TextConflict
 
373
 
 
374
    # Set by the scenarios
 
375
    # path and file-id for the file involved in the conflict
 
376
    _path = None
 
377
    _file_id = None
 
378
 
 
379
    scenarios = mirror_scenarios(
 
380
        [
 
381
            # File modified/deleted
 
382
            (dict(_base_actions='create_file',
 
383
                  _path='file', _file_id='file-id'),
 
384
             ('filed_modified_A',
 
385
              dict(actions='modify_file_A', check='file_has_content_A')),
 
386
             ('file_modified_B',
 
387
              dict(actions='modify_file_B', check='file_has_content_B')),),
 
388
            ])
 
389
 
 
390
    def do_create_file(self):
 
391
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
 
392
 
 
393
    def do_modify_file_A(self):
 
394
        return [('modify', ('file-id', 'trunk content\nfeature A\n'))]
 
395
 
 
396
    def do_modify_file_B(self):
 
397
        return [('modify', ('file-id', 'trunk content\nfeature B\n'))]
 
398
 
 
399
    def check_file_has_content_A(self):
 
400
        self.assertFileEqual('trunk content\nfeature A\n', 'branch/file')
 
401
 
 
402
    def check_file_has_content_B(self):
 
403
        self.assertFileEqual('trunk content\nfeature B\n', 'branch/file')
 
404
 
 
405
    def _get_resolve_path_arg(self, wt, action):
 
406
        return self._path
 
407
 
 
408
    def assertTextConflict(self, wt, c):
 
409
        self.assertEqual(self._file_id, c.file_id)
 
410
        self.assertEqual(self._path, c.path)
 
411
    _assert_conflict = assertTextConflict
 
412
 
 
413
 
391
414
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
392
415
 
393
 
    _conflict_type = conflicts.ContentsConflict,
 
416
    _conflict_type = conflicts.ContentsConflict
394
417
 
395
 
    # Set by load_tests from scenarios()
 
418
    # Set by the scenarios
396
419
    # path and file-id for the file involved in the conflict
397
420
    _path = None
398
421
    _file_id = None
399
422
 
400
 
    @staticmethod
401
 
    def scenarios():
402
 
        base_scenarios = [
 
423
    scenarios = mirror_scenarios(
 
424
        [
403
425
            # File modified/deleted
404
426
            (dict(_base_actions='create_file',
405
427
                  _path='file', _file_id='file-id'),
407
429
              dict(actions='modify_file', check='file_has_more_content')),
408
430
             ('file_deleted',
409
431
              dict(actions='delete_file', check='file_doesnt_exist')),),
410
 
            ]
411
 
        return mirror_scenarios(base_scenarios)
 
432
            ])
412
433
 
413
434
    def do_create_file(self):
414
435
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
436
457
 
437
458
class TestResolvePathConflict(TestParametrizedResolveConflicts):
438
459
 
439
 
    _conflict_type = conflicts.PathConflict,
 
460
    _conflict_type = conflicts.PathConflict
440
461
 
441
462
    def do_nothing(self):
442
463
        return []
443
464
 
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 = [
 
465
    # Each side dict additionally defines:
 
466
    # - path path involved (can be '<deleted>')
 
467
    # - file-id involved
 
468
    scenarios = mirror_scenarios(
 
469
        [
450
470
            # File renamed/deleted
451
471
            (dict(_base_actions='create_file'),
452
472
             ('file_renamed',
483
503
             ('dir_renamed2',
484
504
              dict(actions='rename_dir2', check='dir_renamed2',
485
505
                   path='new-dir2', file_id='dir-id')),),
486
 
        ]
487
 
        return mirror_scenarios(base_scenarios)
 
506
            ])
488
507
 
489
508
    def do_create_file(self):
490
509
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
568
587
 
569
588
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
570
589
 
571
 
    _conflict_type = conflicts.DuplicateEntry,
 
590
    _conflict_type = conflicts.DuplicateEntry
572
591
 
573
 
    @staticmethod
574
 
    def scenarios():
575
 
        # Each side dict additionally defines:
576
 
        # - path involved
577
 
        # - file-id involved
578
 
        base_scenarios = [
 
592
    scenarios = mirror_scenarios(
 
593
        [
579
594
            # File created with different file-ids
580
595
            (dict(_base_actions='nothing'),
581
596
             ('filea_created',
584
599
             ('fileb_created',
585
600
              dict(actions='create_file_b', check='file_content_b',
586
601
                   path='file', file_id='file-b-id')),),
587
 
            ]
588
 
        return mirror_scenarios(base_scenarios)
 
602
            ])
589
603
 
590
604
    def do_nothing(self):
591
605
        return []
625
639
    # tests MissingParent resolution :-/
626
640
    preamble = """
627
641
$ bzr init trunk
 
642
...
628
643
$ cd trunk
629
644
$ mkdir dir
630
 
$ bzr add dir
631
 
$ bzr commit -m 'Create trunk'
632
 
 
 
645
$ bzr add -q dir
 
646
$ bzr commit -m 'Create trunk' -q
633
647
$ 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
 
648
$ bzr add -q dir/file
 
649
$ bzr commit -q -m 'Add dir/file in trunk'
 
650
$ bzr branch -q . -r 1 ../branch
638
651
$ cd ../branch
639
 
$ bzr rm dir
640
 
$ bzr commit -m 'Remove dir in branch'
641
 
 
 
652
$ bzr rm dir -q
 
653
$ bzr commit -q -m 'Remove dir in branch'
642
654
$ bzr merge ../trunk
643
655
2>+N  dir/
644
656
2>+N  dir/file
649
661
 
650
662
    def test_take_this(self):
651
663
        self.run_script("""
652
 
$ bzr rm dir  --force
 
664
$ bzr rm -q dir  --force
653
665
$ bzr resolve dir
654
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
666
2>2 conflict(s) resolved, 0 remaining
 
667
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
655
668
""")
656
669
 
657
670
    def test_take_other(self):
658
671
        self.run_script("""
659
672
$ bzr resolve dir
660
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
673
2>2 conflict(s) resolved, 0 remaining
 
674
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
661
675
""")
662
676
 
663
677
 
665
679
 
666
680
    preamble = """
667
681
$ bzr init trunk
 
682
...
668
683
$ cd trunk
669
684
$ mkdir dir
670
685
$ echo 'trunk content' >dir/file
671
 
$ bzr add
672
 
$ bzr commit -m 'Create trunk'
673
 
 
 
686
$ bzr add -q
 
687
$ bzr commit -m 'Create trunk' -q
674
688
$ 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
 
689
$ bzr add -q dir/file2
 
690
$ bzr commit -q -m 'Add dir/file2 in branch'
 
691
$ bzr branch -q . -r 1 ../branch
679
692
$ cd ../branch
680
 
$ bzr rm dir/file --force
681
 
$ bzr rm dir
682
 
$ bzr commit -m 'Remove dir/file'
683
 
 
 
693
$ bzr rm -q dir/file --force
 
694
$ bzr rm -q dir
 
695
$ bzr commit -q -m 'Remove dir/file'
684
696
$ bzr merge ../trunk
685
697
2>+N  dir/
686
698
2>+N  dir/file2
692
704
    def test_keep_them_all(self):
693
705
        self.run_script("""
694
706
$ bzr resolve dir
695
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
707
2>2 conflict(s) resolved, 0 remaining
 
708
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
696
709
""")
697
710
 
698
711
    def test_adopt_child(self):
699
712
        self.run_script("""
700
 
$ bzr mv dir/file2 file2
701
 
$ bzr rm dir --force
 
713
$ bzr mv -q dir/file2 file2
 
714
$ bzr rm -q dir --force
702
715
$ bzr resolve dir
703
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
716
2>2 conflict(s) resolved, 0 remaining
 
717
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
704
718
""")
705
719
 
706
720
    def test_kill_them_all(self):
707
721
        self.run_script("""
708
 
$ bzr rm dir --force
 
722
$ bzr rm -q dir --force
709
723
$ bzr resolve dir
710
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
724
2>2 conflict(s) resolved, 0 remaining
 
725
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
711
726
""")
712
727
 
713
728
    def test_resolve_taking_this(self):
714
729
        self.run_script("""
715
730
$ bzr resolve --take-this dir
716
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
731
2>...
 
732
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
717
733
""")
718
734
 
719
735
    def test_resolve_taking_other(self):
720
736
        self.run_script("""
721
737
$ bzr resolve --take-other dir
722
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
738
2>...
 
739
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
723
740
""")
724
741
 
725
742
 
727
744
 
728
745
    preamble = """
729
746
$ bzr init trunk
 
747
...
730
748
$ cd trunk
731
749
$ mkdir dir
732
750
$ 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
 
751
$ bzr add -q
 
752
$ bzr commit -m 'Create trunk' -q
 
753
$ bzr rm -q dir/file --force
 
754
$ bzr rm -q dir --force
 
755
$ bzr commit -q -m 'Remove dir/file'
 
756
$ bzr branch -q . -r 1 ../branch
741
757
$ cd ../branch
742
758
$ echo 'branch content' >dir/file2
743
 
$ bzr add dir/file2
744
 
$ bzr commit -m 'Add dir/file2 in branch'
745
 
 
 
759
$ bzr add -q dir/file2
 
760
$ bzr commit -q -m 'Add dir/file2 in branch'
746
761
$ bzr merge ../trunk
747
762
2>-D  dir/file
748
763
2>Conflict: can't delete dir because it is not empty.  Not deleting.
753
768
    def test_keep_them_all(self):
754
769
        self.run_script("""
755
770
$ bzr resolve dir
756
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
771
2>2 conflict(s) resolved, 0 remaining
 
772
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
757
773
""")
758
774
 
759
775
    def test_adopt_child(self):
760
776
        self.run_script("""
761
 
$ bzr mv dir/file2 file2
762
 
$ bzr rm dir --force
 
777
$ bzr mv -q dir/file2 file2
 
778
$ bzr rm -q dir --force
763
779
$ bzr resolve dir
764
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
780
2>2 conflict(s) resolved, 0 remaining
 
781
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
765
782
""")
766
783
 
767
784
    def test_kill_them_all(self):
768
785
        self.run_script("""
769
 
$ bzr rm dir --force
 
786
$ bzr rm -q dir --force
770
787
$ bzr resolve dir
771
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
788
2>2 conflict(s) resolved, 0 remaining
 
789
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
772
790
""")
773
791
 
774
792
    def test_resolve_taking_this(self):
775
793
        self.run_script("""
776
794
$ bzr resolve --take-this dir
777
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
795
2>2 conflict(s) resolved, 0 remaining
 
796
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
778
797
""")
779
798
 
780
799
    def test_resolve_taking_other(self):
781
800
        self.run_script("""
782
801
$ bzr resolve --take-other dir
783
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
802
2>deleted dir/file2
 
803
2>deleted dir
 
804
2>2 conflict(s) resolved, 0 remaining
 
805
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
784
806
""")
785
807
 
786
808
 
787
809
class TestResolveParentLoop(TestParametrizedResolveConflicts):
788
810
 
789
 
    _conflict_type = conflicts.ParentLoop,
 
811
    _conflict_type = conflicts.ParentLoop
790
812
 
791
813
    _this_args = None
792
814
    _other_args = None
793
815
 
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 = [
 
816
    # Each side dict additionally defines:
 
817
    # - dir_id: the directory being moved
 
818
    # - target_id: The target directory
 
819
    # - xfail: whether the test is expected to fail if the action is
 
820
    #   involved as 'other'
 
821
    scenarios = mirror_scenarios(
 
822
        [
802
823
            # Dirs moved into each other
803
824
            (dict(_base_actions='create_dir1_dir2'),
804
825
             ('dir1_into_dir2',
815
836
             ('dir3_into_dir2',
816
837
              dict(actions='move_dir3_into_dir2', check='dir3_4_moved',
817
838
                   dir_id='dir3-id', target_id='dir2-id', xfail=True))),
818
 
            ]
819
 
        return mirror_scenarios(base_scenarios)
 
839
            ])
820
840
 
821
841
    def do_create_dir1_dir2(self):
822
842
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
882
902
 
883
903
    preamble = """
884
904
$ bzr init trunk
 
905
...
885
906
$ cd trunk
886
907
$ bzr mkdir foo
887
 
$ bzr commit -m 'Create trunk'
 
908
...
 
909
$ bzr commit -m 'Create trunk' -q
888
910
$ echo "Boing" >foo/bar
889
 
$ bzr add foo/bar
890
 
$ bzr commit -m 'Add foo/bar'
891
 
 
892
 
$ bzr branch . -r 1 ../branch
 
911
$ bzr add -q foo/bar
 
912
$ bzr commit -q -m 'Add foo/bar'
 
913
$ bzr branch -q . -r 1 ../branch
893
914
$ cd ../branch
894
915
$ rm -r foo
895
916
$ echo "Boo!" >foo
896
 
$ bzr commit -m 'foo is now a file'
897
 
 
 
917
$ bzr commit -q -m 'foo is now a file'
898
918
$ bzr merge ../trunk
899
919
2>+N  foo.new/bar
900
920
2>RK  foo => foo.new/
906
926
 
907
927
    def test_take_this(self):
908
928
        self.run_script("""
909
 
$ bzr rm foo.new --force
 
929
$ bzr rm -q foo.new --force
910
930
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
911
931
# aside ? -- vila 090916
912
 
$ bzr add foo
 
932
$ bzr add -q foo
913
933
$ bzr resolve foo.new
914
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
934
2>1 conflict(s) resolved, 0 remaining
 
935
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
915
936
""")
916
937
 
917
938
    def test_take_other(self):
918
939
        self.run_script("""
919
 
$ bzr rm foo --force
920
 
$ bzr mv foo.new foo
 
940
$ bzr rm -q foo --force
 
941
$ bzr mv -q foo.new foo
921
942
$ bzr resolve foo
922
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
943
2>1 conflict(s) resolved, 0 remaining
 
944
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
923
945
""")
924
946
 
925
947
    def test_resolve_taking_this(self):
926
948
        self.run_script("""
927
949
$ bzr resolve --take-this foo.new
928
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
950
2>...
 
951
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
929
952
""")
930
953
 
931
954
    def test_resolve_taking_other(self):
932
955
        self.run_script("""
933
956
$ bzr resolve --take-other foo.new
934
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
957
2>...
 
958
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
935
959
""")
936
960
 
937
961
 
943
967
        # conflict.
944
968
        self.run_script("""
945
969
$ bzr init trunk
 
970
...
946
971
$ cd trunk
947
972
$ bzr mkdir foo
948
 
$ bzr commit -m 'Create trunk'
 
973
...
 
974
$ bzr commit -m 'Create trunk' -q
949
975
$ rm -r foo
950
976
$ echo "Boo!" >foo
951
 
$ bzr commit -m 'foo is now a file'
952
 
 
953
 
$ bzr branch . -r 1 ../branch
 
977
$ bzr commit -m 'foo is now a file' -q
 
978
$ bzr branch -q . -r 1 ../branch -q
954
979
$ cd ../branch
955
980
$ echo "Boing" >foo/bar
956
 
$ bzr add foo/bar
957
 
$ bzr commit -m 'Add foo/bar'
958
 
 
 
981
$ bzr add -q foo/bar -q
 
982
$ bzr commit -m 'Add foo/bar' -q
959
983
$ bzr merge ../trunk
960
984
2>bzr: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]
961
985
""")