~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

Translate one more test.

* bzrlib/tests/test_conflicts.py:
(TestResolveContentConflicts): Rewrite test_resolve_taking_other as
a whitebox test, refactoring common code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
215
215
        builder.finish_series()
216
216
        self.builder = builder
217
217
 
218
 
    def test_resolve_taking_this(self):
 
218
    def _merge_other_into_this(self):
219
219
        b = self.builder.get_branch()
220
220
        wt = b.bzrdir.sprout('branch').open_workingtree()
221
221
        wt.merge_from_branch(b, 'other')
222
 
        # Check that we got the right conflict
 
222
        return wt
 
223
 
 
224
    def assertConflict(self, wt, ctype, **kwargs):
223
225
        confs = wt.conflicts()
224
226
        self.assertEqual(1, len(confs))
225
227
        c = confs[0]
226
 
        self.assertIsInstance(confs[0], conflicts.ContentsConflict)
227
 
        self.assertEqual('file-id', c.file_id)
228
 
        self.assertEqual('file', c.path)
229
 
        conflicts.resolve(wt, ['file'], action='take_this')
 
228
        self.assertIsInstance(c, ctype)
 
229
        sentinel = object() # An impossible value
 
230
        for k, v in kwargs.iteritems():
 
231
            self.assertEqual(v, getattr(c, k, sentinel))
 
232
 
 
233
    def assertResolved(self, wt, item, action):
 
234
        conflicts.resolve(wt, [item], action=action)
230
235
        # Check that we don't have any conflicts nor unknown left
231
236
        self.assertEqual(0, len(wt.conflicts()))
232
237
        self.assertEqual(0, len(list(wt.unknowns())))
233
238
 
 
239
    def test_resolve_taking_this(self):
 
240
        wt = self._merge_other_into_this()
 
241
        self.assertConflict(wt, conflicts.ContentsConflict,
 
242
                            path='file', file_id='file-id',)
 
243
        self.assertResolved(wt, 'file', 'take_this')
 
244
 
 
245
    def test_resolve_taking_other(self):
 
246
        wt = self._merge_other_into_this()
 
247
        self.assertConflict(wt, conflicts.ContentsConflict,
 
248
                            path='file', file_id='file-id',)
 
249
        self.assertResolved(wt, 'file', 'take_other')
 
250
 
234
251
 
235
252
class OldTestResolveContentConflicts(TestResolveConflicts):
236
253