~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

Some cleanup.

* bzrlib/tests/test_conflicts.py:
(TestResolveContentsConflict, TestResolvePathConflict): Cleanup
scenarios and sme method names.

* bzrlib/tests/test_conflicts.py:
(TestParametrizedResolveConflicts): Cleanup common parameter which
are really test class attributes.

* bzrlib/conflicts.py:
(PathConflict._infer_file_id): Cleaned up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
        standard_tests, tests.condition_isinstance((
37
37
                TestParametrizedResolveConflicts,
38
38
                )))
39
 
    # Each test class define its own scenarios. This is needed for
 
39
    # Each test class defines its own scenarios. This is needed for
40
40
    # TestResolvePathConflictBefore531967 that verifies that the same tests as
41
41
    # TestResolvePathConflict still pass.
42
42
    for test in tests.iter_suite_tests(sp_tests):
219
219
# TestResolveConflicts -- vila 20100308
220
220
class TestParametrizedResolveConflicts(tests.TestCaseWithTransport):
221
221
 
 
222
    # Set by daughter classes
 
223
    _conflict_type = None
 
224
    _assert_conflict = None
 
225
 
222
226
    # Set by load_tests
223
227
    _base_actions = None
224
228
    _this_actions = None
225
229
    _other_actions = None
226
 
    _conflict_type = None
227
230
    _item_path = None
228
231
    _item_id = None
229
232
 
234
237
    _other_id = None
235
238
 
236
239
    @classmethod
237
 
    def mirror_scenarios(klass, base_scenarios, common_params):
 
240
    def mirror_scenarios(klass, common_params, base_scenarios):
238
241
        scenarios = []
239
242
        def adapt(d, side):
240
243
            """Modify dict to apply to the given side.
303
306
        self.assertLength(1, confs)
304
307
        c = confs[0]
305
308
        self.assertIsInstance(c, self._conflict_type)
306
 
        _assert_conflict = getattr(self, self._assert_conflict)
307
 
        _assert_conflict(c)
 
309
        self._assert_conflict(c)
308
310
 
309
311
    def check_resolved(self, wt, path, action):
310
312
        conflicts.resolve(wt, [path], action=action)
327
329
        self.assertFileEqual('trunk content\nmore content\n', 'branch/file')
328
330
 
329
331
    def do_delete_file(self):
330
 
        # None or <deleted> ?
331
332
        return ('file', 'file-id', [('unversion', 'file-id')])
332
333
 
333
334
    def check_file_doesnt_exist(self):
348
349
        self.failUnlessExists('branch/new-dir2')
349
350
 
350
351
    def do_delete_dir(self):
351
 
        # None or <deleted> ?
352
 
        # bug #531967 also mess up the paths
353
352
        return ('<deleted>', 'dir-id', [('unversion', 'dir-id')])
354
353
 
355
354
    def check_dir_doesnt_exist(self):
378
377
 
379
378
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
380
379
 
 
380
    _conflict_type = conflicts.ContentsConflict,
381
381
    @classmethod
382
382
    def scenarios(klass):
 
383
        common = dict(_actions_base='create_file',
 
384
                      _item_path='file', item_id='file-id',
 
385
                      )
383
386
        base_scenarios = [
384
387
            (('file_modified', dict(actions='modify_file',
385
388
                                   check='file_has_more_content')),
386
389
             ('file_deleted', dict(actions='delete_file',
387
390
                                   check='file_doesnt_exist'))),
388
391
            ]
389
 
        common = dict(_conflict_type=conflicts.ContentsConflict,
390
 
                      _actions_base='create_file',
391
 
                      _assert_conflict='assertContentsConflict',
392
 
                      _item_path='file', item_id='file-id',
393
 
                      )
394
 
        return klass.mirror_scenarios(base_scenarios, common)
 
392
        return klass.mirror_scenarios(common, base_scenarios)
395
393
 
396
394
    def assertContentsConflict(self, c):
397
395
        self.assertEqual(self._other_id, c.file_id)
398
396
        self.assertEqual(self._other_path, c.path)
 
397
    _assert_conflict = assertContentsConflict
 
398
 
399
399
 
400
400
 
401
401
class TestResolvePathConflict(TestParametrizedResolveConflicts):
402
402
 
 
403
    _conflict_type = conflicts.PathConflict,
 
404
 
403
405
    @classmethod
404
406
    def scenarios(klass):
 
407
        common = dict(_actions_base='create_dir',
 
408
                      _item_path='new-dir', _item_id='dir-id',)
405
409
        base_scenarios = [
406
410
        (('dir_renamed', dict(actions='rename_dir', check='dir_renamed')),
407
411
         ('dir_deleted', dict(actions='delete_dir', check='dir_doesnt_exist'))),
408
412
        (('dir_renamed', dict(actions='rename_dir', check='dir_renamed')),
409
413
         ('dir_renamed2', dict(actions='rename_dir2', check='dir_renamed2'))),
410
414
            ]
411
 
        common = dict(_conflict_type=conflicts.PathConflict,
412
 
                      _assert_conflict='assert_PathConflict',
413
 
                      _actions_base='create_dir',
414
 
                      _item_path='new-dir', _item_id='dir-id',)
415
 
        return klass.mirror_scenarios(base_scenarios, common)
 
415
        return klass.mirror_scenarios(common, base_scenarios)
416
416
 
417
 
    def assert_PathConflict(self, c):
 
417
    def assertPathConflict(self, c):
418
418
        self.assertEqual(self._item_id, c.file_id)
419
419
        self.assertEqual(self._this_path, c.path)
420
420
        self.assertEqual(self._other_path, c.conflict_path)
 
421
    _assert_conflict = assertPathConflict
421
422
 
422
423
 
423
424
class TestResolvePathConflictBefore531967(TestParametrizedResolveConflicts):
427
428
    # FIXME: Now that bug #531697 is fixed, we need to inject a conflict object
428
429
    # as it existed before the fix.
429
430
 
430
 
    def assert_PathConflict(self, c):
 
431
    def assertPathConflict(self, c):
431
432
        # bug #531967 is about file_id not being set in some cases
432
433
        self.assertIs(None, c.file_id)
433
434
        # Whatever this and other are saying, the same paths are used