~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: abentley
  • Date: 2006-04-20 23:47:53 UTC
  • mfrom: (1681 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1683.
  • Revision ID: abentley@lappy-20060420234753-6a6874b76f09f86d
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import os
18
18
 
19
19
from bzrlib.bzrdir import BzrDir
 
20
from bzrlib.conflicts import (DuplicateEntry, DuplicateID, MissingParent,
 
21
                              UnversionedParent, ParentLoop)
20
22
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
21
23
                           ReusingTransform, CantMoveRoot, NotVersionedError,
22
24
                           ExistingLimbo, ImmortalLimbo, LockError)
23
25
from bzrlib.osutils import file_kind, has_symlinks, pathjoin
24
26
from bzrlib.merge import Merge3Merger
25
 
from bzrlib.tests import TestCaseInTempDir, TestSkipped
 
27
from bzrlib.tests import TestCaseInTempDir, TestSkipped, TestCase
26
28
from bzrlib.transform import (TreeTransform, ROOT_PARENT, FinalPaths, 
27
29
                              resolve_conflicts, cook_conflicts, 
28
 
                              conflicts_strings, find_interesting, build_tree)
 
30
                              find_interesting, build_tree, get_backup_name)
29
31
 
30
32
class TestTreeTransform(TestCaseInTempDir):
31
33
    def setUp(self):
188
190
        transform3.adjust_path('tip', root_id, tip_id)
189
191
        transform3.apply()
190
192
 
 
193
    def test_add_del(self):
 
194
        start, root = self.get_transform()
 
195
        start.new_directory('a', root, 'a')
 
196
        start.apply()
 
197
        transform, root = self.get_transform()
 
198
        transform.delete_versioned(transform.trans_id_tree_file_id('a'))
 
199
        transform.new_directory('a', root, 'a')
 
200
        transform.apply()
 
201
 
191
202
    def test_unversioning(self):
192
203
        create_tree, root = self.get_transform()
193
204
        parent_id = create_tree.new_directory('parent', root, 'parent-id')
392
403
        tt, emerald, oz, old_dorothy, new_dorothy = self.get_conflicted()
393
404
        raw_conflicts = resolve_conflicts(tt)
394
405
        cooked_conflicts = cook_conflicts(raw_conflicts, tt)
395
 
        duplicate = ('duplicate', 'Moved existing file to', 'dorothy.moved', 
396
 
                     None, 'dorothy', 'dorothy-id')
 
406
        duplicate = DuplicateEntry('Moved existing file to', 'dorothy.moved', 
 
407
                                   'dorothy', None, 'dorothy-id')
397
408
        self.assertEqual(cooked_conflicts[0], duplicate)
398
 
        duplicate_id = ('duplicate id', 'Unversioned existing file', 
399
 
                        'dorothy.moved', None, 'dorothy', 'dorothy-id')
 
409
        duplicate_id = DuplicateID('Unversioned existing file', 
 
410
                                   'dorothy.moved', 'dorothy', None,
 
411
                                   'dorothy-id')
400
412
        self.assertEqual(cooked_conflicts[1], duplicate_id)
401
 
        missing_parent = ('missing parent', 'Not deleting', 'oz', 'oz-id')
 
413
        missing_parent = MissingParent('Not deleting', 'oz', 'oz-id')
402
414
        self.assertEqual(cooked_conflicts[2], missing_parent)
403
 
        unversioned_parent = ('unversioned parent', 
404
 
                              'Versioned directory', 'oz', 'oz-id')
 
415
        unversioned_parent = UnversionedParent('Versioned directory', 'oz',
 
416
                                               'oz-id')
405
417
        self.assertEqual(cooked_conflicts[3], unversioned_parent)
406
 
        parent_loop = ('parent loop', 'Cancelled move', 'oz/emeraldcity', 
407
 
                       'emerald-id', 'oz/emeraldcity', 'emerald-id')
 
418
        parent_loop = ParentLoop('Cancelled move', 'oz/emeraldcity', 
 
419
                                 'oz/emeraldcity', 'emerald-id', 'emerald-id')
408
420
        self.assertEqual(cooked_conflicts[4], parent_loop)
409
421
        self.assertEqual(len(cooked_conflicts), 5)
410
422
        tt.finalize()
414
426
        raw_conflicts = resolve_conflicts(tt)
415
427
        cooked_conflicts = cook_conflicts(raw_conflicts, tt)
416
428
        tt.finalize()
417
 
        conflicts_s = list(conflicts_strings(cooked_conflicts))
 
429
        conflicts_s = [str(c) for c in cooked_conflicts]
418
430
        self.assertEqual(len(cooked_conflicts), len(conflicts_s))
419
431
        self.assertEqual(conflicts_s[0], 'Conflict adding file dorothy.  '
420
432
                                         'Moved existing file to '
567
579
        merge_modified = this.wt.merge_modified()
568
580
        self.assertSubset(merge_modified, modified)
569
581
        self.assertEqual(len(merge_modified), len(modified))
 
582
        this.wt.remove('b')
 
583
        this.wt.revert([])
570
584
 
571
585
    def test_file_merge(self):
572
586
        if not has_symlinks():
688
702
        self.assertIs(os.path.isdir('b/foo'), True)
689
703
        self.assertEqual(file('b/foo/bar', 'rb').read(), "contents")
690
704
        self.assertEqual(os.readlink('b/foo/baz'), 'a/foo/bar')
 
705
        
 
706
class MockTransform(object):
 
707
 
 
708
    def has_named_child(self, by_parent, parent_id, name):
 
709
        for child_id in by_parent[parent_id]:
 
710
            if child_id == '0':
 
711
                if name == "name~":
 
712
                    return True
 
713
            elif name == "name.~%s~" % child_id:
 
714
                return True
 
715
        return False
 
716
 
 
717
class MockEntry(object):
 
718
    def __init__(self):
 
719
        object.__init__(self)
 
720
        self.name = "name"
 
721
 
 
722
class TestGetBackupName(TestCase):
 
723
    def test_get_backup_name(self):
 
724
        tt = MockTransform()
 
725
        name = get_backup_name(MockEntry(), {'a':[]}, 'a', tt)
 
726
        self.assertEqual(name, 'name.~1~')
 
727
        name = get_backup_name(MockEntry(), {'a':['1']}, 'a', tt)
 
728
        self.assertEqual(name, 'name.~2~')
 
729
        name = get_backup_name(MockEntry(), {'a':['2']}, 'a', tt)
 
730
        self.assertEqual(name, 'name.~1~')
 
731
        name = get_backup_name(MockEntry(), {'a':['2'], 'b':[]}, 'b', tt)
 
732
        self.assertEqual(name, 'name.~1~')
 
733
        name = get_backup_name(MockEntry(), {'a':['1', '2', '3']}, 'a', tt)
 
734
        self.assertEqual(name, 'name.~4~')