~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-05-18 13:02:52 UTC
  • mfrom: (5830.3.6 i18n-msgfmt)
  • Revision ID: pqm@pqm.ubuntu.com-20110518130252-ky96qcvzt6o0zg3f
(mbp) add build_mo command to setup.py (INADA Naoki)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
 
20
20
from bzrlib import (
 
21
    bzrdir,
21
22
    conflicts,
22
23
    errors,
23
24
    option,
61
62
])
62
63
 
63
64
 
64
 
def vary_by_conflicts():
65
 
    for conflict in example_conflicts:
66
 
        yield (conflict.__class__.__name__, {"conflict": conflict})
67
 
 
68
 
 
69
65
class TestConflicts(tests.TestCaseWithTransport):
70
66
 
71
67
    def test_resolve_conflict_dir(self):
124
120
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
125
121
 
126
122
 
127
 
class TestPerConflict(tests.TestCase):
128
 
 
129
 
    scenarios = scenarios.multiply_scenarios(vary_by_conflicts())
130
 
 
131
 
    def test_stringification(self):
132
 
        text = unicode(self.conflict)
133
 
        self.assertContainsString(text, self.conflict.path)
134
 
        self.assertContainsString(text.lower(), "conflict")
135
 
        self.assertContainsString(repr(self.conflict),
136
 
            self.conflict.__class__.__name__)
 
123
class TestConflictStanzas(tests.TestCase):
137
124
 
138
125
    def test_stanza_roundtrip(self):
139
 
        p = self.conflict
140
 
        o = conflicts.Conflict.factory(**p.as_stanza().as_dict())
141
 
        self.assertEqual(o, p)
142
 
 
143
 
        self.assertIsInstance(o.path, unicode)
144
 
 
145
 
        if o.file_id is not None:
146
 
            self.assertIsInstance(o.file_id, str)
147
 
 
148
 
        conflict_path = getattr(o, 'conflict_path', None)
149
 
        if conflict_path is not None:
150
 
            self.assertIsInstance(conflict_path, unicode)
151
 
 
152
 
        conflict_file_id = getattr(o, 'conflict_file_id', None)
153
 
        if conflict_file_id is not None:
154
 
            self.assertIsInstance(conflict_file_id, str)
 
126
        # write and read our example stanza.
 
127
        stanza_iter = example_conflicts.to_stanzas()
 
128
        processed = conflicts.ConflictList.from_stanzas(stanza_iter)
 
129
        for o, p in zip(processed, example_conflicts):
 
130
            self.assertEqual(o, p)
 
131
 
 
132
            self.assertIsInstance(o.path, unicode)
 
133
 
 
134
            if o.file_id is not None:
 
135
                self.assertIsInstance(o.file_id, str)
 
136
 
 
137
            conflict_path = getattr(o, 'conflict_path', None)
 
138
            if conflict_path is not None:
 
139
                self.assertIsInstance(conflict_path, unicode)
 
140
 
 
141
            conflict_file_id = getattr(o, 'conflict_file_id', None)
 
142
            if conflict_file_id is not None:
 
143
                self.assertIsInstance(conflict_file_id, str)
155
144
 
156
145
    def test_stanzification(self):
157
 
        stanza = self.conflict.as_stanza()
158
 
        if 'file_id' in stanza:
159
 
            # In Stanza form, the file_id has to be unicode.
160
 
            self.assertStartsWith(stanza['file_id'], u'\xeed')
161
 
        self.assertStartsWith(stanza['path'], u'p\xe5th')
162
 
        if 'conflict_path' in stanza:
163
 
            self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
164
 
        if 'conflict_file_id' in stanza:
165
 
            self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
166
 
 
167
 
 
168
 
class TestConflictList(tests.TestCase):
169
 
 
170
 
    def test_stanzas_roundtrip(self):
171
 
        stanzas_iter = example_conflicts.to_stanzas()
172
 
        processed = conflicts.ConflictList.from_stanzas(stanzas_iter)
173
 
        self.assertEqual(example_conflicts, processed)
174
 
 
175
 
    def test_stringification(self):
176
 
        for text, o in zip(example_conflicts.to_strings(), example_conflicts):
177
 
            self.assertEqual(text, unicode(o))
 
146
        for stanza in example_conflicts.to_stanzas():
 
147
            if 'file_id' in stanza:
 
148
                # In Stanza form, the file_id has to be unicode.
 
149
                self.assertStartsWith(stanza['file_id'], u'\xeed')
 
150
            self.assertStartsWith(stanza['path'], u'p\xe5th')
 
151
            if 'conflict_path' in stanza:
 
152
                self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
 
153
            if 'conflict_file_id' in stanza:
 
154
                self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
178
155
 
179
156
 
180
157
# FIXME: The shell-like tests should be converted to real whitebox tests... or
445
422
              dict(actions='modify_file', check='file_has_more_content')),
446
423
             ('file_deleted',
447
424
              dict(actions='delete_file', check='file_doesnt_exist')),),
448
 
            # File renamed-modified/deleted
449
 
            (dict(_base_actions='create_file',
450
 
                  _path='new-file', _file_id='file-id'),
451
 
             ('file_renamed_and_modified',
452
 
              dict(actions='modify_and_rename_file',
453
 
                   check='file_renamed_and_more_content')),
454
 
             ('file_deleted',
455
 
              dict(actions='delete_file', check='file_doesnt_exist')),),
456
425
            # File modified/deleted in dir
457
426
            (dict(_base_actions='create_file_in_dir',
458
427
                  _path='dir/file', _file_id='file-id'),
470
439
    def do_modify_file(self):
471
440
        return [('modify', ('file-id', 'trunk content\nmore content\n'))]
472
441
 
473
 
    def do_modify_and_rename_file(self):
474
 
        return [('modify', ('file-id', 'trunk content\nmore content\n')),
475
 
                ('rename', ('file', 'new-file'))]
476
 
 
477
442
    def check_file_has_more_content(self):
478
443
        self.assertFileEqual('trunk content\nmore content\n', 'branch/file')
479
444
 
480
 
    def check_file_renamed_and_more_content(self):
481
 
        self.assertFileEqual('trunk content\nmore content\n', 'branch/new-file')
482
 
 
483
445
    def do_delete_file(self):
484
446
        return [('unversion', 'file-id')]
485
447
 
676
638
             ('fileb_created',
677
639
              dict(actions='create_file_b', check='file_content_b',
678
640
                   path='file', file_id='file-b-id')),),
679
 
            # File created with different file-ids but deleted on one side
680
 
            (dict(_base_actions='create_file_a'),
681
 
             ('filea_replaced',
682
 
              dict(actions='replace_file_a_by_b', check='file_content_b',
683
 
                   path='file', file_id='file-b-id')),
684
 
             ('filea_modified',
685
 
              dict(actions='modify_file_a', check='file_new_content',
686
 
                   path='file', file_id='file-a-id')),),
687
641
            ])
688
642
 
689
643
    def do_nothing(self):
701
655
    def check_file_content_b(self):
702
656
        self.assertFileEqual('file b content\n', 'branch/file')
703
657
 
704
 
    def do_replace_file_a_by_b(self):
705
 
        return [('unversion', 'file-a-id'),
706
 
                ('add', ('file', 'file-b-id', 'file', 'file b content\n'))]
707
 
 
708
 
    def do_modify_file_a(self):
709
 
        return [('modify', ('file-a-id', 'new content\n'))]
710
 
 
711
 
    def check_file_new_content(self):
712
 
        self.assertFileEqual('new content\n', 'branch/file')
713
 
 
714
658
    def _get_resolve_path_arg(self, wt, action):
715
659
        return self._this['path']
716
660
 
756
700
 
757
701
    def test_take_this(self):
758
702
        self.run_script("""
759
 
$ bzr rm -q dir --no-backup
 
703
$ bzr rm -q dir  --force
760
704
$ bzr resolve dir
761
 
2>2 conflicts resolved, 0 remaining
 
705
2>2 conflict(s) resolved, 0 remaining
762
706
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
763
707
""")
764
708
 
765
709
    def test_take_other(self):
766
710
        self.run_script("""
767
711
$ bzr resolve dir
768
 
2>2 conflicts resolved, 0 remaining
 
712
2>2 conflict(s) resolved, 0 remaining
769
713
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
770
714
""")
771
715
 
785
729
$ bzr commit -q -m 'Add dir/file2 in branch'
786
730
$ bzr branch -q . -r 1 ../branch
787
731
$ cd ../branch
788
 
$ bzr rm -q dir/file --no-backup
 
732
$ bzr rm -q dir/file --force
789
733
$ bzr rm -q dir
790
734
$ bzr commit -q -m 'Remove dir/file'
791
735
$ bzr merge ../trunk
799
743
    def test_keep_them_all(self):
800
744
        self.run_script("""
801
745
$ bzr resolve dir
802
 
2>2 conflicts resolved, 0 remaining
 
746
2>2 conflict(s) resolved, 0 remaining
803
747
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
804
748
""")
805
749
 
806
750
    def test_adopt_child(self):
807
751
        self.run_script("""
808
752
$ bzr mv -q dir/file2 file2
809
 
$ bzr rm -q dir --no-backup
 
753
$ bzr rm -q dir --force
810
754
$ bzr resolve dir
811
 
2>2 conflicts resolved, 0 remaining
 
755
2>2 conflict(s) resolved, 0 remaining
812
756
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
813
757
""")
814
758
 
815
759
    def test_kill_them_all(self):
816
760
        self.run_script("""
817
 
$ bzr rm -q dir --no-backup
 
761
$ bzr rm -q dir --force
818
762
$ bzr resolve dir
819
 
2>2 conflicts resolved, 0 remaining
 
763
2>2 conflict(s) resolved, 0 remaining
820
764
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
821
765
""")
822
766
 
845
789
$ echo 'trunk content' >dir/file
846
790
$ bzr add -q
847
791
$ bzr commit -m 'Create trunk' -q
848
 
$ bzr rm -q dir/file --no-backup
849
 
$ bzr rm -q dir --no-backup
 
792
$ bzr rm -q dir/file --force
 
793
$ bzr rm -q dir --force
850
794
$ bzr commit -q -m 'Remove dir/file'
851
795
$ bzr branch -q . -r 1 ../branch
852
796
$ cd ../branch
863
807
    def test_keep_them_all(self):
864
808
        self.run_script("""
865
809
$ bzr resolve dir
866
 
2>2 conflicts resolved, 0 remaining
 
810
2>2 conflict(s) resolved, 0 remaining
867
811
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
868
812
""")
869
813
 
870
814
    def test_adopt_child(self):
871
815
        self.run_script("""
872
816
$ bzr mv -q dir/file2 file2
873
 
$ bzr rm -q dir --no-backup
 
817
$ bzr rm -q dir --force
874
818
$ bzr resolve dir
875
 
2>2 conflicts resolved, 0 remaining
 
819
2>2 conflict(s) resolved, 0 remaining
876
820
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
877
821
""")
878
822
 
879
823
    def test_kill_them_all(self):
880
824
        self.run_script("""
881
 
$ bzr rm -q dir --no-backup
 
825
$ bzr rm -q dir --force
882
826
$ bzr resolve dir
883
 
2>2 conflicts resolved, 0 remaining
 
827
2>2 conflict(s) resolved, 0 remaining
884
828
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
885
829
""")
886
830
 
887
831
    def test_resolve_taking_this(self):
888
832
        self.run_script("""
889
833
$ bzr resolve --take-this dir
890
 
2>2 conflicts resolved, 0 remaining
 
834
2>2 conflict(s) resolved, 0 remaining
891
835
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
892
836
""")
893
837
 
896
840
$ bzr resolve --take-other dir
897
841
2>deleted dir/file2
898
842
2>deleted dir
899
 
2>2 conflicts resolved, 0 remaining
 
843
2>2 conflict(s) resolved, 0 remaining
900
844
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
901
845
""")
902
846
 
988
932
        if self._other['xfail']:
989
933
            # It's a bit hackish to raise from here relying on being called for
990
934
            # both tests but this avoid overriding test_resolve_taking_other
991
 
            self.knownFailure(
 
935
            raise tests.KnownFailure(
992
936
                "ParentLoop doesn't carry enough info to resolve --take-other")
993
937
    _assert_conflict = assertParentLoop
994
938
 
1021
965
 
1022
966
    def test_take_this(self):
1023
967
        self.run_script("""
1024
 
$ bzr rm -q foo.new --no-backup
 
968
$ bzr rm -q foo.new --force
1025
969
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
1026
970
# aside ? -- vila 090916
1027
971
$ bzr add -q foo
1028
972
$ bzr resolve foo.new
1029
 
2>1 conflict resolved, 0 remaining
 
973
2>1 conflict(s) resolved, 0 remaining
1030
974
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
1031
975
""")
1032
976
 
1033
977
    def test_take_other(self):
1034
978
        self.run_script("""
1035
 
$ bzr rm -q foo --no-backup
 
979
$ bzr rm -q foo --force
1036
980
$ bzr mv -q foo.new foo
1037
981
$ bzr resolve foo
1038
 
2>1 conflict resolved, 0 remaining
 
982
2>1 conflict(s) resolved, 0 remaining
1039
983
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
1040
984
""")
1041
985
 
1060
1004
        # This is nearly like TestResolveNonDirectoryParent but with branch and
1061
1005
        # trunk switched. As such it should certainly produce the same
1062
1006
        # conflict.
1063
 
        self.assertRaises(errors.MalformedTransform,
1064
 
                          self.run_script,"""
 
1007
        self.run_script("""
1065
1008
$ bzr init trunk
1066
1009
...
1067
1010
$ cd trunk
1081
1024
""")
1082
1025
 
1083
1026
 
1084
 
class TestNoFinalPath(script.TestCaseWithTransportAndScript):
1085
 
 
1086
 
    def test_bug_805809(self):
1087
 
        self.run_script("""
1088
 
$ bzr init trunk
1089
 
Created a standalone tree (format: 2a)
1090
 
$ cd trunk
1091
 
$ echo trunk >file
1092
 
$ bzr add
1093
 
adding file
1094
 
$ bzr commit -m 'create file on trunk'
1095
 
2>Committing to: .../trunk/
1096
 
2>added file
1097
 
2>Committed revision 1.
1098
 
# Create a debian branch based on trunk
1099
 
$ cd ..
1100
 
$ bzr branch trunk -r 1 debian
1101
 
2>Branched 1 revision.
1102
 
$ cd debian
1103
 
$ mkdir dir
1104
 
$ bzr add
1105
 
adding dir
1106
 
$ bzr mv file dir
1107
 
file => dir/file
1108
 
$ bzr commit -m 'rename file to dir/file for debian'
1109
 
2>Committing to: .../debian/
1110
 
2>added dir
1111
 
2>renamed file => dir/file
1112
 
2>Committed revision 2.
1113
 
# Create an experimental branch with a new root-id
1114
 
$ cd ..
1115
 
$ bzr init experimental
1116
 
Created a standalone tree (format: 2a)
1117
 
$ cd experimental
1118
 
# Work around merging into empty branch not being supported
1119
 
# (http://pad.lv/308562)
1120
 
$ echo something >not-empty
1121
 
$ bzr add
1122
 
adding not-empty
1123
 
$ bzr commit -m 'Add some content in experimental'
1124
 
2>Committing to: .../experimental/
1125
 
2>added not-empty
1126
 
2>Committed revision 1.
1127
 
# merge debian even without a common ancestor
1128
 
$ bzr merge ../debian -r0..2
1129
 
2>+N  dir/
1130
 
2>+N  dir/file
1131
 
2>All changes applied successfully.
1132
 
$ bzr commit -m 'merging debian into experimental'
1133
 
2>Committing to: .../experimental/
1134
 
2>added dir
1135
 
2>added dir/file
1136
 
2>Committed revision 2.
1137
 
# Create an ubuntu branch with yet another root-id
1138
 
$ cd ..
1139
 
$ bzr init ubuntu
1140
 
Created a standalone tree (format: 2a)
1141
 
$ cd ubuntu
1142
 
# Work around merging into empty branch not being supported
1143
 
# (http://pad.lv/308562)
1144
 
$ echo something >not-empty-ubuntu
1145
 
$ bzr add
1146
 
adding not-empty-ubuntu
1147
 
$ bzr commit -m 'Add some content in experimental'
1148
 
2>Committing to: .../ubuntu/
1149
 
2>added not-empty-ubuntu
1150
 
2>Committed revision 1.
1151
 
# Also merge debian
1152
 
$ bzr merge ../debian -r0..2
1153
 
2>+N  dir/
1154
 
2>+N  dir/file
1155
 
2>All changes applied successfully.
1156
 
$ bzr commit -m 'merging debian'
1157
 
2>Committing to: .../ubuntu/
1158
 
2>added dir
1159
 
2>added dir/file
1160
 
2>Committed revision 2.
1161
 
# Now try to merge experimental
1162
 
$ bzr merge ../experimental
1163
 
2>+N  not-empty
1164
 
2>Path conflict: dir / dir
1165
 
2>1 conflicts encountered.
1166
 
""")
1167
 
 
1168
 
 
1169
1027
class TestResolveActionOption(tests.TestCase):
1170
1028
 
1171
1029
    def setUp(self):