~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-07 10:36:24 UTC
  • mfrom: (5764 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5766.
  • Revision ID: john@arbash-meinel.com-20110407103624-n76g6tjeqmznwdcd
Merge bzr.dev 5764 to resolve release-notes (aka NEWS) conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
import os
19
19
 
20
20
from bzrlib import (
21
 
    branchbuilder,
22
21
    bzrdir,
23
22
    conflicts,
24
23
    errors,
25
24
    option,
 
25
    osutils,
26
26
    tests,
27
 
    workingtree,
28
27
    )
29
28
from bzrlib.tests import (
30
29
    script,
65
64
 
66
65
class TestConflicts(tests.TestCaseWithTransport):
67
66
 
68
 
    def test_conflicts(self):
69
 
        """Conflicts are detected properly"""
70
 
        # Use BzrDirFormat6 so we can fake conflicts
71
 
        tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
72
 
        self.build_tree_contents([('hello', 'hello world4'),
73
 
                                  ('hello.THIS', 'hello world2'),
74
 
                                  ('hello.BASE', 'hello world1'),
75
 
                                  ('hello.OTHER', 'hello world3'),
76
 
                                  ('hello.sploo.BASE', 'yellowworld'),
77
 
                                  ('hello.sploo.OTHER', 'yellowworld2'),
78
 
                                  ])
79
 
        tree.lock_read()
80
 
        self.assertLength(6, list(tree.list_files()))
81
 
        tree.unlock()
82
 
        tree_conflicts = tree.conflicts()
83
 
        self.assertLength(2, tree_conflicts)
84
 
        self.assertTrue('hello' in tree_conflicts[0].path)
85
 
        self.assertTrue('hello.sploo' in tree_conflicts[1].path)
86
 
        conflicts.restore('hello')
87
 
        conflicts.restore('hello.sploo')
88
 
        self.assertLength(0, tree.conflicts())
89
 
        self.assertFileEqual('hello world2', 'hello')
90
 
        self.assertFalse(os.path.lexists('hello.sploo'))
91
 
        self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
92
 
        self.assertRaises(errors.NotConflicted,
93
 
                          conflicts.restore, 'hello.sploo')
94
 
 
95
67
    def test_resolve_conflict_dir(self):
96
68
        tree = self.make_branch_and_tree('.')
97
69
        self.build_tree_contents([('hello', 'hello world4'),
197
169
        self.run_script(self.preamble)
198
170
 
199
171
 
200
 
class TestResolveTextConflicts(TestResolveConflicts):
201
 
    # TBC
202
 
    pass
203
 
 
204
 
 
205
172
def mirror_scenarios(base_scenarios):
206
173
    """Return a list of mirrored scenarios.
207
174
 
372
339
        check_other()
373
340
 
374
341
 
 
342
class TestResolveTextConflicts(TestParametrizedResolveConflicts):
 
343
 
 
344
    _conflict_type = conflicts.TextConflict
 
345
 
 
346
    # Set by the scenarios
 
347
    # path and file-id for the file involved in the conflict
 
348
    _path = None
 
349
    _file_id = None
 
350
 
 
351
    scenarios = mirror_scenarios(
 
352
        [
 
353
            # File modified on both sides
 
354
            (dict(_base_actions='create_file',
 
355
                  _path='file', _file_id='file-id'),
 
356
             ('filed_modified_A',
 
357
              dict(actions='modify_file_A', check='file_has_content_A')),
 
358
             ('file_modified_B',
 
359
              dict(actions='modify_file_B', check='file_has_content_B')),),
 
360
            # File modified on both sides in dir
 
361
            (dict(_base_actions='create_file_in_dir',
 
362
                  _path='dir/file', _file_id='file-id'),
 
363
             ('filed_modified_A_in_dir',
 
364
              dict(actions='modify_file_A',
 
365
                   check='file_in_dir_has_content_A')),
 
366
             ('file_modified_B',
 
367
              dict(actions='modify_file_B',
 
368
                   check='file_in_dir_has_content_B')),),
 
369
            ])
 
370
 
 
371
    def do_create_file(self, path='file'):
 
372
        return [('add', (path, 'file-id', 'file', 'trunk content\n'))]
 
373
 
 
374
    def do_modify_file_A(self):
 
375
        return [('modify', ('file-id', 'trunk content\nfeature A\n'))]
 
376
 
 
377
    def do_modify_file_B(self):
 
378
        return [('modify', ('file-id', 'trunk content\nfeature B\n'))]
 
379
 
 
380
    def check_file_has_content_A(self, path='file'):
 
381
        self.assertFileEqual('trunk content\nfeature A\n',
 
382
                             osutils.pathjoin('branch', path))
 
383
 
 
384
    def check_file_has_content_B(self, path='file'):
 
385
        self.assertFileEqual('trunk content\nfeature B\n',
 
386
                             osutils.pathjoin('branch', path))
 
387
 
 
388
    def do_create_file_in_dir(self):
 
389
        return [('add', ('dir', 'dir-id', 'directory', '')),
 
390
            ] + self.do_create_file('dir/file')
 
391
 
 
392
    def check_file_in_dir_has_content_A(self):
 
393
        self.check_file_has_content_A('dir/file')
 
394
 
 
395
    def check_file_in_dir_has_content_B(self):
 
396
        self.check_file_has_content_B('dir/file')
 
397
 
 
398
    def _get_resolve_path_arg(self, wt, action):
 
399
        return self._path
 
400
 
 
401
    def assertTextConflict(self, wt, c):
 
402
        self.assertEqual(self._file_id, c.file_id)
 
403
        self.assertEqual(self._path, c.path)
 
404
    _assert_conflict = assertTextConflict
 
405
 
 
406
 
375
407
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
376
408
 
377
409
    _conflict_type = conflicts.ContentsConflict
390
422
              dict(actions='modify_file', check='file_has_more_content')),
391
423
             ('file_deleted',
392
424
              dict(actions='delete_file', check='file_doesnt_exist')),),
 
425
            # File modified/deleted in dir
 
426
            (dict(_base_actions='create_file_in_dir',
 
427
                  _path='dir/file', _file_id='file-id'),
 
428
             ('file_modified_in_dir',
 
429
              dict(actions='modify_file_in_dir',
 
430
                   check='file_in_dir_has_more_content')),
 
431
             ('file_deleted_in_dir',
 
432
              dict(actions='delete_file',
 
433
                   check='file_in_dir_doesnt_exist')),),
393
434
            ])
394
435
 
395
436
    def do_create_file(self):
407
448
    def check_file_doesnt_exist(self):
408
449
        self.failIfExists('branch/file')
409
450
 
 
451
    def do_create_file_in_dir(self):
 
452
        return [('add', ('dir', 'dir-id', 'directory', '')),
 
453
                ('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
 
454
 
 
455
    def do_modify_file_in_dir(self):
 
456
        return [('modify', ('file-id', 'trunk content\nmore content\n'))]
 
457
 
 
458
    def check_file_in_dir_has_more_content(self):
 
459
        self.assertFileEqual('trunk content\nmore content\n', 'branch/dir/file')
 
460
 
 
461
    def check_file_in_dir_doesnt_exist(self):
 
462
        self.failIfExists('branch/dir/file')
 
463
 
410
464
    def _get_resolve_path_arg(self, wt, action):
411
465
        return self._path
412
466
 
438
492
                   # PathConflicts deletion handling requires a special
439
493
                   # hard-coded value
440
494
                   path='<deleted>', file_id='file-id')),),
 
495
            # File renamed/deleted in dir
 
496
            (dict(_base_actions='create_file_in_dir'),
 
497
             ('file_renamed_in_dir',
 
498
              dict(actions='rename_file_in_dir', check='file_in_dir_renamed',
 
499
                   path='dir/new-file', file_id='file-id')),
 
500
             ('file_deleted',
 
501
              dict(actions='delete_file', check='file_in_dir_doesnt_exist',
 
502
                   # PathConflicts deletion handling requires a special
 
503
                   # hard-coded value
 
504
                   path='<deleted>', file_id='file-id')),),
441
505
            # File renamed/renamed differently
442
506
            (dict(_base_actions='create_file'),
443
507
             ('file_renamed',
512
576
    def check_dir_doesnt_exist(self):
513
577
        self.failIfExists('branch/dir')
514
578
 
 
579
    def do_create_file_in_dir(self):
 
580
        return [('add', ('dir', 'dir-id', 'directory', '')),
 
581
                ('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
 
582
 
 
583
    def do_rename_file_in_dir(self):
 
584
        return [('rename', ('dir/file', 'dir/new-file'))]
 
585
 
 
586
    def check_file_in_dir_renamed(self):
 
587
        self.failIfExists('branch/dir/file')
 
588
        self.failUnlessExists('branch/dir/new-file')
 
589
 
 
590
    def check_file_in_dir_doesnt_exist(self):
 
591
        self.failIfExists('branch/dir/file')
 
592
 
515
593
    def _get_resolve_path_arg(self, wt, action):
516
594
        tpath = self._this['path']
517
595
        opath = self._other['path']