~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

(gz) Fix test failure on alpha by correcting format string for
 gc_chk_sha1_record (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
])
63
63
 
64
64
 
65
 
def vary_by_conflicts():
66
 
    for conflict in example_conflicts:
67
 
        yield (conflict.__class__.__name__, {"conflict": conflict})
68
 
 
69
 
 
70
65
class TestConflicts(tests.TestCaseWithTransport):
71
66
 
 
67
    def test_conflicts(self):
 
68
        """Conflicts are detected properly"""
 
69
        # Use BzrDirFormat6 so we can fake conflicts
 
70
        tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
 
71
        self.build_tree_contents([('hello', 'hello world4'),
 
72
                                  ('hello.THIS', 'hello world2'),
 
73
                                  ('hello.BASE', 'hello world1'),
 
74
                                  ('hello.OTHER', 'hello world3'),
 
75
                                  ('hello.sploo.BASE', 'yellowworld'),
 
76
                                  ('hello.sploo.OTHER', 'yellowworld2'),
 
77
                                  ])
 
78
        tree.lock_read()
 
79
        self.assertLength(6, list(tree.list_files()))
 
80
        tree.unlock()
 
81
        tree_conflicts = tree.conflicts()
 
82
        self.assertLength(2, tree_conflicts)
 
83
        self.assertTrue('hello' in tree_conflicts[0].path)
 
84
        self.assertTrue('hello.sploo' in tree_conflicts[1].path)
 
85
        conflicts.restore('hello')
 
86
        conflicts.restore('hello.sploo')
 
87
        self.assertLength(0, tree.conflicts())
 
88
        self.assertFileEqual('hello world2', 'hello')
 
89
        self.assertFalse(os.path.lexists('hello.sploo'))
 
90
        self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
 
91
        self.assertRaises(errors.NotConflicted,
 
92
                          conflicts.restore, 'hello.sploo')
 
93
 
72
94
    def test_resolve_conflict_dir(self):
73
95
        tree = self.make_branch_and_tree('.')
74
96
        self.build_tree_contents([('hello', 'hello world4'),
125
147
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
126
148
 
127
149
 
128
 
class TestPerConflict(tests.TestCase):
129
 
 
130
 
    scenarios = scenarios.multiply_scenarios(vary_by_conflicts())
131
 
 
132
 
    def test_stringification(self):
133
 
        text = unicode(self.conflict)
134
 
        self.assertContainsString(text, self.conflict.path)
135
 
        self.assertContainsString(text.lower(), "conflict")
136
 
        self.assertContainsString(repr(self.conflict),
137
 
            self.conflict.__class__.__name__)
 
150
class TestConflictStanzas(tests.TestCase):
138
151
 
139
152
    def test_stanza_roundtrip(self):
140
 
        p = self.conflict
141
 
        o = conflicts.Conflict.factory(**p.as_stanza().as_dict())
142
 
        self.assertEqual(o, p)
143
 
 
144
 
        self.assertIsInstance(o.path, unicode)
145
 
 
146
 
        if o.file_id is not None:
147
 
            self.assertIsInstance(o.file_id, str)
148
 
 
149
 
        conflict_path = getattr(o, 'conflict_path', None)
150
 
        if conflict_path is not None:
151
 
            self.assertIsInstance(conflict_path, unicode)
152
 
 
153
 
        conflict_file_id = getattr(o, 'conflict_file_id', None)
154
 
        if conflict_file_id is not None:
155
 
            self.assertIsInstance(conflict_file_id, str)
 
153
        # write and read our example stanza.
 
154
        stanza_iter = example_conflicts.to_stanzas()
 
155
        processed = conflicts.ConflictList.from_stanzas(stanza_iter)
 
156
        for o, p in zip(processed, example_conflicts):
 
157
            self.assertEqual(o, p)
 
158
 
 
159
            self.assertIsInstance(o.path, unicode)
 
160
 
 
161
            if o.file_id is not None:
 
162
                self.assertIsInstance(o.file_id, str)
 
163
 
 
164
            conflict_path = getattr(o, 'conflict_path', None)
 
165
            if conflict_path is not None:
 
166
                self.assertIsInstance(conflict_path, unicode)
 
167
 
 
168
            conflict_file_id = getattr(o, 'conflict_file_id', None)
 
169
            if conflict_file_id is not None:
 
170
                self.assertIsInstance(conflict_file_id, str)
156
171
 
157
172
    def test_stanzification(self):
158
 
        stanza = self.conflict.as_stanza()
159
 
        if 'file_id' in stanza:
160
 
            # In Stanza form, the file_id has to be unicode.
161
 
            self.assertStartsWith(stanza['file_id'], u'\xeed')
162
 
        self.assertStartsWith(stanza['path'], u'p\xe5th')
163
 
        if 'conflict_path' in stanza:
164
 
            self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
165
 
        if 'conflict_file_id' in stanza:
166
 
            self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
167
 
 
168
 
 
169
 
class TestConflictList(tests.TestCase):
170
 
 
171
 
    def test_stanzas_roundtrip(self):
172
 
        stanzas_iter = example_conflicts.to_stanzas()
173
 
        processed = conflicts.ConflictList.from_stanzas(stanzas_iter)
174
 
        self.assertEqual(example_conflicts, processed)
175
 
 
176
 
    def test_stringification(self):
177
 
        for text, o in zip(example_conflicts.to_strings(), example_conflicts):
178
 
            self.assertEqual(text, unicode(o))
 
173
        for stanza in example_conflicts.to_stanzas():
 
174
            if 'file_id' in stanza:
 
175
                # In Stanza form, the file_id has to be unicode.
 
176
                self.assertStartsWith(stanza['file_id'], u'\xeed')
 
177
            self.assertStartsWith(stanza['path'], u'p\xe5th')
 
178
            if 'conflict_path' in stanza:
 
179
                self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
 
180
            if 'conflict_file_id' in stanza:
 
181
                self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
179
182
 
180
183
 
181
184
# FIXME: The shell-like tests should be converted to real whitebox tests... or
446
449
              dict(actions='modify_file', check='file_has_more_content')),
447
450
             ('file_deleted',
448
451
              dict(actions='delete_file', check='file_doesnt_exist')),),
449
 
            # File renamed-modified/deleted
450
 
            (dict(_base_actions='create_file',
451
 
                  _path='new-file', _file_id='file-id'),
452
 
             ('file_renamed_and_modified',
453
 
              dict(actions='modify_and_rename_file',
454
 
                   check='file_renamed_and_more_content')),
455
 
             ('file_deleted',
456
 
              dict(actions='delete_file', check='file_doesnt_exist')),),
457
452
            # File modified/deleted in dir
458
453
            (dict(_base_actions='create_file_in_dir',
459
454
                  _path='dir/file', _file_id='file-id'),
471
466
    def do_modify_file(self):
472
467
        return [('modify', ('file-id', 'trunk content\nmore content\n'))]
473
468
 
474
 
    def do_modify_and_rename_file(self):
475
 
        return [('modify', ('file-id', 'trunk content\nmore content\n')),
476
 
                ('rename', ('file', 'new-file'))]
477
 
 
478
469
    def check_file_has_more_content(self):
479
470
        self.assertFileEqual('trunk content\nmore content\n', 'branch/file')
480
471
 
481
 
    def check_file_renamed_and_more_content(self):
482
 
        self.assertFileEqual('trunk content\nmore content\n', 'branch/new-file')
483
 
 
484
472
    def do_delete_file(self):
485
473
        return [('unversion', 'file-id')]
486
474
 
487
475
    def check_file_doesnt_exist(self):
488
 
        self.assertPathDoesNotExist('branch/file')
 
476
        self.failIfExists('branch/file')
489
477
 
490
478
    def do_create_file_in_dir(self):
491
479
        return [('add', ('dir', 'dir-id', 'directory', '')),
498
486
        self.assertFileEqual('trunk content\nmore content\n', 'branch/dir/file')
499
487
 
500
488
    def check_file_in_dir_doesnt_exist(self):
501
 
        self.assertPathDoesNotExist('branch/dir/file')
 
489
        self.failIfExists('branch/dir/file')
502
490
 
503
491
    def _get_resolve_path_arg(self, wt, action):
504
492
        return self._path
579
567
        return [('rename', ('file', 'new-file'))]
580
568
 
581
569
    def check_file_renamed(self):
582
 
        self.assertPathDoesNotExist('branch/file')
583
 
        self.assertPathExists('branch/new-file')
 
570
        self.failIfExists('branch/file')
 
571
        self.failUnlessExists('branch/new-file')
584
572
 
585
573
    def do_rename_file2(self):
586
574
        return [('rename', ('file', 'new-file2'))]
587
575
 
588
576
    def check_file_renamed2(self):
589
 
        self.assertPathDoesNotExist('branch/file')
590
 
        self.assertPathExists('branch/new-file2')
 
577
        self.failIfExists('branch/file')
 
578
        self.failUnlessExists('branch/new-file2')
591
579
 
592
580
    def do_rename_dir(self):
593
581
        return [('rename', ('dir', 'new-dir'))]
594
582
 
595
583
    def check_dir_renamed(self):
596
 
        self.assertPathDoesNotExist('branch/dir')
597
 
        self.assertPathExists('branch/new-dir')
 
584
        self.failIfExists('branch/dir')
 
585
        self.failUnlessExists('branch/new-dir')
598
586
 
599
587
    def do_rename_dir2(self):
600
588
        return [('rename', ('dir', 'new-dir2'))]
601
589
 
602
590
    def check_dir_renamed2(self):
603
 
        self.assertPathDoesNotExist('branch/dir')
604
 
        self.assertPathExists('branch/new-dir2')
 
591
        self.failIfExists('branch/dir')
 
592
        self.failUnlessExists('branch/new-dir2')
605
593
 
606
594
    def do_delete_file(self):
607
595
        return [('unversion', 'file-id')]
608
596
 
609
597
    def check_file_doesnt_exist(self):
610
 
        self.assertPathDoesNotExist('branch/file')
 
598
        self.failIfExists('branch/file')
611
599
 
612
600
    def do_delete_dir(self):
613
601
        return [('unversion', 'dir-id')]
614
602
 
615
603
    def check_dir_doesnt_exist(self):
616
 
        self.assertPathDoesNotExist('branch/dir')
 
604
        self.failIfExists('branch/dir')
617
605
 
618
606
    def do_create_file_in_dir(self):
619
607
        return [('add', ('dir', 'dir-id', 'directory', '')),
623
611
        return [('rename', ('dir/file', 'dir/new-file'))]
624
612
 
625
613
    def check_file_in_dir_renamed(self):
626
 
        self.assertPathDoesNotExist('branch/dir/file')
627
 
        self.assertPathExists('branch/dir/new-file')
 
614
        self.failIfExists('branch/dir/file')
 
615
        self.failUnlessExists('branch/dir/new-file')
628
616
 
629
617
    def check_file_in_dir_doesnt_exist(self):
630
 
        self.assertPathDoesNotExist('branch/dir/file')
 
618
        self.failIfExists('branch/dir/file')
631
619
 
632
620
    def _get_resolve_path_arg(self, wt, action):
633
621
        tpath = self._this['path']
741
729
        self.run_script("""
742
730
$ bzr rm -q dir  --force
743
731
$ bzr resolve dir
744
 
2>2 conflicts resolved, 0 remaining
 
732
2>2 conflict(s) resolved, 0 remaining
745
733
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
746
734
""")
747
735
 
748
736
    def test_take_other(self):
749
737
        self.run_script("""
750
738
$ bzr resolve dir
751
 
2>2 conflicts resolved, 0 remaining
 
739
2>2 conflict(s) resolved, 0 remaining
752
740
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
753
741
""")
754
742
 
782
770
    def test_keep_them_all(self):
783
771
        self.run_script("""
784
772
$ bzr resolve dir
785
 
2>2 conflicts resolved, 0 remaining
 
773
2>2 conflict(s) resolved, 0 remaining
786
774
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
787
775
""")
788
776
 
791
779
$ bzr mv -q dir/file2 file2
792
780
$ bzr rm -q dir --force
793
781
$ bzr resolve dir
794
 
2>2 conflicts resolved, 0 remaining
 
782
2>2 conflict(s) resolved, 0 remaining
795
783
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
796
784
""")
797
785
 
799
787
        self.run_script("""
800
788
$ bzr rm -q dir --force
801
789
$ bzr resolve dir
802
 
2>2 conflicts resolved, 0 remaining
 
790
2>2 conflict(s) resolved, 0 remaining
803
791
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
804
792
""")
805
793
 
846
834
    def test_keep_them_all(self):
847
835
        self.run_script("""
848
836
$ bzr resolve dir
849
 
2>2 conflicts resolved, 0 remaining
 
837
2>2 conflict(s) resolved, 0 remaining
850
838
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
851
839
""")
852
840
 
855
843
$ bzr mv -q dir/file2 file2
856
844
$ bzr rm -q dir --force
857
845
$ bzr resolve dir
858
 
2>2 conflicts resolved, 0 remaining
 
846
2>2 conflict(s) resolved, 0 remaining
859
847
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
860
848
""")
861
849
 
863
851
        self.run_script("""
864
852
$ bzr rm -q dir --force
865
853
$ bzr resolve dir
866
 
2>2 conflicts resolved, 0 remaining
 
854
2>2 conflict(s) resolved, 0 remaining
867
855
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
868
856
""")
869
857
 
870
858
    def test_resolve_taking_this(self):
871
859
        self.run_script("""
872
860
$ bzr resolve --take-this dir
873
 
2>2 conflicts resolved, 0 remaining
 
861
2>2 conflict(s) resolved, 0 remaining
874
862
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
875
863
""")
876
864
 
879
867
$ bzr resolve --take-other dir
880
868
2>deleted dir/file2
881
869
2>deleted dir
882
 
2>2 conflicts resolved, 0 remaining
 
870
2>2 conflict(s) resolved, 0 remaining
883
871
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
884
872
""")
885
873
 
924
912
        return [('rename', ('dir1', 'dir2/dir1'))]
925
913
 
926
914
    def check_dir1_moved(self):
927
 
        self.assertPathDoesNotExist('branch/dir1')
928
 
        self.assertPathExists('branch/dir2/dir1')
 
915
        self.failIfExists('branch/dir1')
 
916
        self.failUnlessExists('branch/dir2/dir1')
929
917
 
930
918
    def do_move_dir2_into_dir1(self):
931
919
        return [('rename', ('dir2', 'dir1/dir2'))]
932
920
 
933
921
    def check_dir2_moved(self):
934
 
        self.assertPathDoesNotExist('branch/dir2')
935
 
        self.assertPathExists('branch/dir1/dir2')
 
922
        self.failIfExists('branch/dir2')
 
923
        self.failUnlessExists('branch/dir1/dir2')
936
924
 
937
925
    def do_create_dir1_4(self):
938
926
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
944
932
        return [('rename', ('dir1', 'dir3/dir4/dir1'))]
945
933
 
946
934
    def check_dir1_2_moved(self):
947
 
        self.assertPathDoesNotExist('branch/dir1')
948
 
        self.assertPathExists('branch/dir3/dir4/dir1')
949
 
        self.assertPathExists('branch/dir3/dir4/dir1/dir2')
 
935
        self.failIfExists('branch/dir1')
 
936
        self.failUnlessExists('branch/dir3/dir4/dir1')
 
937
        self.failUnlessExists('branch/dir3/dir4/dir1/dir2')
950
938
 
951
939
    def do_move_dir3_into_dir2(self):
952
940
        return [('rename', ('dir3', 'dir1/dir2/dir3'))]
953
941
 
954
942
    def check_dir3_4_moved(self):
955
 
        self.assertPathDoesNotExist('branch/dir3')
956
 
        self.assertPathExists('branch/dir1/dir2/dir3')
957
 
        self.assertPathExists('branch/dir1/dir2/dir3/dir4')
 
943
        self.failIfExists('branch/dir3')
 
944
        self.failUnlessExists('branch/dir1/dir2/dir3')
 
945
        self.failUnlessExists('branch/dir1/dir2/dir3/dir4')
958
946
 
959
947
    def _get_resolve_path_arg(self, wt, action):
960
948
        # ParentLoop says: moving <conflict_path> into <path>. Cancelled move.
971
959
        if self._other['xfail']:
972
960
            # It's a bit hackish to raise from here relying on being called for
973
961
            # both tests but this avoid overriding test_resolve_taking_other
974
 
            self.knownFailure(
 
962
            raise tests.KnownFailure(
975
963
                "ParentLoop doesn't carry enough info to resolve --take-other")
976
964
    _assert_conflict = assertParentLoop
977
965
 
1009
997
# aside ? -- vila 090916
1010
998
$ bzr add -q foo
1011
999
$ bzr resolve foo.new
1012
 
2>1 conflict resolved, 0 remaining
 
1000
2>1 conflict(s) resolved, 0 remaining
1013
1001
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
1014
1002
""")
1015
1003
 
1018
1006
$ bzr rm -q foo --force
1019
1007
$ bzr mv -q foo.new foo
1020
1008
$ bzr resolve foo
1021
 
2>1 conflict resolved, 0 remaining
 
1009
2>1 conflict(s) resolved, 0 remaining
1022
1010
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
1023
1011
""")
1024
1012
 
1063
1051
""")
1064
1052
 
1065
1053
 
1066
 
class TestNoFinalPath(script.TestCaseWithTransportAndScript):
1067
 
 
1068
 
    def test_bug_805809(self):
1069
 
        self.run_script("""
1070
 
$ bzr init trunk
1071
 
Created a standalone tree (format: 2a)
1072
 
$ cd trunk
1073
 
$ echo trunk >file
1074
 
$ bzr add
1075
 
adding file
1076
 
$ bzr commit -m 'create file on trunk'
1077
 
2>Committing to: .../trunk/
1078
 
2>added file
1079
 
2>Committed revision 1.
1080
 
# Create a debian branch based on trunk
1081
 
$ cd ..
1082
 
$ bzr branch trunk -r 1 debian
1083
 
2>Branched 1 revision.
1084
 
$ cd debian
1085
 
$ mkdir dir
1086
 
$ bzr add
1087
 
adding dir
1088
 
$ bzr mv file dir
1089
 
file => dir/file
1090
 
$ bzr commit -m 'rename file to dir/file for debian'
1091
 
2>Committing to: .../debian/
1092
 
2>added dir
1093
 
2>renamed file => dir/file
1094
 
2>Committed revision 2.
1095
 
# Create an experimental branch with a new root-id
1096
 
$ cd ..
1097
 
$ bzr init experimental
1098
 
Created a standalone tree (format: 2a)
1099
 
$ cd experimental
1100
 
# Work around merging into empty branch not being supported
1101
 
# (http://pad.lv/308562)
1102
 
$ echo something >not-empty
1103
 
$ bzr add
1104
 
adding not-empty
1105
 
$ bzr commit -m 'Add some content in experimental'
1106
 
2>Committing to: .../experimental/
1107
 
2>added not-empty
1108
 
2>Committed revision 1.
1109
 
# merge debian even without a common ancestor
1110
 
$ bzr merge ../debian -r0..2
1111
 
2>+N  dir/
1112
 
2>+N  dir/file
1113
 
2>All changes applied successfully.
1114
 
$ bzr commit -m 'merging debian into experimental'
1115
 
2>Committing to: .../experimental/
1116
 
2>added dir
1117
 
2>added dir/file
1118
 
2>Committed revision 2.
1119
 
# Create an ubuntu branch with yet another root-id
1120
 
$ cd ..
1121
 
$ bzr init ubuntu
1122
 
Created a standalone tree (format: 2a)
1123
 
$ cd ubuntu
1124
 
# Work around merging into empty branch not being supported
1125
 
# (http://pad.lv/308562)
1126
 
$ echo something >not-empty-ubuntu
1127
 
$ bzr add
1128
 
adding not-empty-ubuntu
1129
 
$ bzr commit -m 'Add some content in experimental'
1130
 
2>Committing to: .../ubuntu/
1131
 
2>added not-empty-ubuntu
1132
 
2>Committed revision 1.
1133
 
# Also merge debian
1134
 
$ bzr merge ../debian -r0..2
1135
 
2>+N  dir/
1136
 
2>+N  dir/file
1137
 
2>All changes applied successfully.
1138
 
$ bzr commit -m 'merging debian'
1139
 
2>Committing to: .../ubuntu/
1140
 
2>added dir
1141
 
2>added dir/file
1142
 
2>Committed revision 2.
1143
 
# Now try to merge experimental
1144
 
$ bzr merge ../experimental
1145
 
2>+N  not-empty
1146
 
2>Path conflict: dir / dir
1147
 
2>1 conflicts encountered.
1148
 
""")
1149
 
 
1150
 
 
1151
1054
class TestResolveActionOption(tests.TestCase):
1152
1055
 
1153
1056
    def setUp(self):