~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

Fix bug #529968 by renaming the kept file on content conflicts.

* bzrlib/conflicts.py:
(ContentsConflict._take_it): Helper to resolve the conflict,
factored out of the two symmetric cases. Use a tree transform to
transparently handle more cases.
(ContentsConflict.action_take_this,
ContentsConflict.action_take_other):

* bzrlib/tests/test_conflicts.py:
(load_tests): Start parametrizing tests.
(content_conflict_scenarios): First scenarios for ContenConflict.
(TestResolveContentConflicts.setUp): Actions are parameters.
(TestResolveContentConflicts.test_resolve_taking_this,
TestResolveContentConflicts.test_resolve_taking_other): Finer
checks are parameters.
(TestResolveContentConflicts._get_actions)
(TestResolveContentConflicts._get_check): Helpers.
(TestResolveContentConflicts.do_modify_file,
TestResolveContentConflicts.do_delete_file): Specific actions.
(TestResolveContentConflicts.check_file_has_more_content,
TestResolveContentConflicts.check_file_doesnt_exist): Specific
checks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from bzrlib.tests import script
30
30
 
31
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
                TestResolveContentConflicts,
 
38
                )))
 
39
    tests.multiply_tests(sp_tests, content_conflict_scenarios(), result)
 
40
 
 
41
    # No parametrization for the remaining tests
 
42
    result.addTests(remaining_tests)
 
43
 
 
44
    return result
 
45
 
 
46
 
32
47
# TODO: Test commit with some added, and added-but-missing files
33
48
# RBC 20060124 is that not tested in test_commit.py ?
34
49
 
194
209
    pass
195
210
 
196
211
 
 
212
def content_conflict_scenarios():
 
213
    return [('file,None', dict(_this_actions='modify_file',
 
214
                               _check_this='file_has_more_content',
 
215
                               _other_actions='delete_file',
 
216
                               _check_other='file_doesnt_exist',
 
217
                               )),
 
218
            ('None,file', dict(_this_actions='delete_file',
 
219
                               _check_this='file_doesnt_exist',
 
220
                               _other_actions='modify_file',
 
221
                               _check_other='file_has_more_content',
 
222
                               )),
 
223
            ]
 
224
 
 
225
 
197
226
class TestResolveContentConflicts(tests.TestCaseWithTransport):
198
227
 
199
 
    # FIXME: We need to add the reverse case (delete in trunk, modify in
200
 
    # branch) but that could wait until the resolution mechanism is implemented.
 
228
    # Set by load_tests
 
229
    this_actions = None
 
230
    other_actions = None
201
231
 
202
232
    def setUp(self):
203
233
        super(TestResolveContentConflicts, self).setUp()
210
240
        builder.build_snapshot('base', ['start'], [
211
241
                ('add', ('file', 'file-id', 'file', 'trunk content\n'))])
212
242
        # Modify the base content in branch
213
 
        builder.build_snapshot('other', ['base'], [
214
 
                ('unversion', 'file-id')])
 
243
        other_actions = self._get_actions(self._other_actions)
 
244
        builder.build_snapshot('other', ['base'], other_actions())
215
245
        # Modify the base content in trunk
216
 
        builder.build_snapshot('this', ['base'], [
217
 
                ('modify', ('file-id', 'trunk content\nmore content\n'))])
 
246
        this_actions = self._get_actions(self._this_actions)
 
247
        builder.build_snapshot('this', ['base'], this_actions())
218
248
        builder.finish_series()
219
249
        self.builder = builder
220
250
 
 
251
    def _get_actions(self, name):
 
252
        return getattr(self, 'do_%s' % name)
 
253
 
 
254
    def _get_check(self, name):
 
255
        return getattr(self, 'check_%s' % name)
 
256
 
 
257
    def do_modify_file(self):
 
258
        return [('modify', ('file-id', 'trunk content\nmore content\n'))]
 
259
 
 
260
    def check_file_has_more_content(self):
 
261
        self.assertFileEqual('trunk content\nmore content\n', 'branch/file')
 
262
 
 
263
    def do_delete_file(self):
 
264
        return [('unversion', 'file-id')]
 
265
 
 
266
    def check_file_doesnt_exist(self):
 
267
        self.failIfExists('branch/file')
 
268
 
221
269
    def _merge_other_into_this(self):
222
270
        b = self.builder.get_branch()
223
271
        wt = b.bzrdir.sprout('branch').open_workingtree()
244
292
        self.assertConflict(wt, conflicts.ContentsConflict,
245
293
                            path='file', file_id='file-id',)
246
294
        self.assertResolved(wt, 'file', 'take_this')
247
 
        self.assertFileEqual('trunk content\nmore content\n', 'branch/file')
 
295
        check_this = self._get_check(self._check_this)
 
296
        check_this()
248
297
 
249
298
    def test_resolve_taking_other(self):
250
299
        wt = self._merge_other_into_this()
251
300
        self.assertConflict(wt, conflicts.ContentsConflict,
252
301
                            path='file', file_id='file-id',)
253
302
        self.assertResolved(wt, 'file', 'take_other')
254
 
        self.failIfExists('branch/file')
 
303
        check_other = self._get_check(self._check_other)
 
304
        check_other()
255
305
 
256
306
 
257
307
class TestResolveDuplicateEntry(TestResolveConflicts):