/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: 2011-01-12 18:39:25 UTC
  • mfrom: (5598.1.1 bzr)
  • Revision ID: pqm@pqm.ubuntu.com-20110112183925-rnn12p6xp91441r0
(vila) Fix PEP-8 violation in PythonVersionInfoBuilder's output (Soren
 Hansen)

Show diffs side-by-side

added added

removed removed

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