~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Alexander Belchenko
  • Date: 2010-06-17 08:53:15 UTC
  • mfrom: (5300 +trunk)
  • mto: (5303.2.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5305.
  • Revision ID: bialix@ukr.net-20100617085315-hr8186zck57zn35s
merge bzr.dev; fix NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    filters,
26
26
    generate_ids,
27
27
    osutils,
28
 
    progress,
29
28
    revision as _mod_revision,
30
29
    rules,
31
30
    tests,
32
31
    urlutils,
33
32
    )
34
33
from bzrlib.bzrdir import BzrDir
35
 
from bzrlib.conflicts import (DuplicateEntry, DuplicateID, MissingParent,
36
 
                              UnversionedParent, ParentLoop, DeletingParent,
37
 
                              NonDirectoryParent)
 
34
from bzrlib.conflicts import (
 
35
    DeletingParent,
 
36
    DuplicateEntry,
 
37
    DuplicateID,
 
38
    MissingParent,
 
39
    NonDirectoryParent,
 
40
    ParentLoop,
 
41
    UnversionedParent,
 
42
)
38
43
from bzrlib.diff import show_diff_trees
39
 
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
40
 
                           ReusingTransform, CantMoveRoot,
41
 
                           PathsNotVersionedError, ExistingLimbo,
42
 
                           ExistingPendingDeletion, ImmortalLimbo,
43
 
                           ImmortalPendingDeletion, LockError)
44
 
from bzrlib.osutils import file_kind, pathjoin
 
44
from bzrlib.errors import (
 
45
    DuplicateKey,
 
46
    ExistingLimbo,
 
47
    ExistingPendingDeletion,
 
48
    ImmortalLimbo,
 
49
    ImmortalPendingDeletion,
 
50
    LockError,
 
51
    MalformedTransform,
 
52
    NoSuchFile,
 
53
    ReusingTransform,
 
54
)
 
55
from bzrlib.osutils import (
 
56
    file_kind,
 
57
    pathjoin,
 
58
)
45
59
from bzrlib.merge import Merge3Merger, Merger
46
60
from bzrlib.tests import (
47
61
    HardlinkFeature,
49
63
    TestCase,
50
64
    TestCaseInTempDir,
51
65
    TestSkipped,
52
 
    )
53
 
from bzrlib.transform import (TreeTransform, ROOT_PARENT, FinalPaths,
54
 
                              resolve_conflicts, cook_conflicts,
55
 
                              build_tree, get_backup_name,
56
 
                              _FileMover, resolve_checkout,
57
 
                              TransformPreview, create_from_tree)
 
66
)
 
67
from bzrlib.transform import (
 
68
    build_tree,
 
69
    create_from_tree,
 
70
    cook_conflicts,
 
71
    _FileMover,
 
72
    FinalPaths,
 
73
    get_backup_name,
 
74
    resolve_conflicts,
 
75
    resolve_checkout,
 
76
    ROOT_PARENT,
 
77
    TransformPreview,
 
78
    TreeTransform,
 
79
)
58
80
 
59
81
 
60
82
class TestTreeTransform(tests.TestCaseWithTransport):
735
757
                                         ' versioned, but has versioned'
736
758
                                         ' children.  Versioned directory.')
737
759
        self.assertEqual(conflicts_s[6], 'Conflict moving oz/emeraldcity into'
738
 
                                         ' oz/emeraldcity.  Cancelled move.')
 
760
                                         ' oz/emeraldcity. Cancelled move.')
739
761
 
740
762
    def prepare_wrong_parent_kind(self):
741
763
        tt, root = self.get_transform()
830
852
        rename.set_executability(True, myfile)
831
853
        rename.apply()
832
854
 
 
855
    def test_rename_fails(self):
 
856
        # see https://bugs.launchpad.net/bzr/+bug/491763
 
857
        create, root_id = self.get_transform()
 
858
        first_dir = create.new_directory('first-dir', root_id, 'first-id')
 
859
        myfile = create.new_file('myfile', root_id, 'myfile-text',
 
860
                                 'myfile-id')
 
861
        create.apply()
 
862
        # make the file and directory readonly in the hope this will prevent
 
863
        # renames
 
864
        osutils.make_readonly(self.wt.abspath('first-dir'))
 
865
        osutils.make_readonly(self.wt.abspath('myfile'))
 
866
        # now transform to rename
 
867
        rename_transform, root_id = self.get_transform()
 
868
        file_trans_id = rename_transform.trans_id_file_id('myfile-id')
 
869
        dir_id = rename_transform.trans_id_file_id('first-id')
 
870
        rename_transform.adjust_path('newname', dir_id, file_trans_id)
 
871
        e = self.assertRaises(errors.TransformRenameFailed,
 
872
            rename_transform.apply)
 
873
        # Looks like: 
 
874
        # "Failed to rename .../work/.bzr/checkout/limbo/new-1
 
875
        # to .../first-dir/newname: [Errno 13] Permission denied"
 
876
        # so the first filename is not visible in it; we expect a strerror but
 
877
        # it may vary per OS and language so it's not checked here
 
878
        self.assertContainsRe(str(e),
 
879
            "Failed to rename .*first-dir.newname:")
 
880
 
833
881
    def test_set_executability_order(self):
834
882
        """Ensure that executability behaves the same, no matter what order.
835
883
 
2091
2139
        self.assertRaises(errors.MalformedTransform, tt.commit, branch,
2092
2140
                          'message')
2093
2141
 
 
2142
    def test_commit_rich_revision_data(self):
 
2143
        branch, tt = self.get_branch_and_transform()
 
2144
        rev_id = tt.commit(branch, 'message', timestamp=1, timezone=43201,
 
2145
                           committer='me <me@example.com>',
 
2146
                           revprops={'foo': 'bar'}, revision_id='revid-1',
 
2147
                           authors=['Author1 <author1@example.com>',
 
2148
                              'Author2 <author2@example.com>',
 
2149
                               ])
 
2150
        self.assertEqual('revid-1', rev_id)
 
2151
        revision = branch.repository.get_revision(rev_id)
 
2152
        self.assertEqual(1, revision.timestamp)
 
2153
        self.assertEqual(43201, revision.timezone)
 
2154
        self.assertEqual('me <me@example.com>', revision.committer)
 
2155
        self.assertEqual(['Author1 <author1@example.com>',
 
2156
                          'Author2 <author2@example.com>'],
 
2157
                         revision.get_apparent_authors())
 
2158
        del revision.properties['authors']
 
2159
        self.assertEqual({'foo': 'bar',
 
2160
                          'branch-nick': 'tree'},
 
2161
                         revision.properties)
 
2162
 
 
2163
    def test_no_explicit_revprops(self):
 
2164
        branch, tt = self.get_branch_and_transform()
 
2165
        rev_id = tt.commit(branch, 'message', authors=[
 
2166
            'Author1 <author1@example.com>',
 
2167
            'Author2 <author2@example.com>', ])
 
2168
        revision = branch.repository.get_revision(rev_id)
 
2169
        self.assertEqual(['Author1 <author1@example.com>',
 
2170
                          'Author2 <author2@example.com>'],
 
2171
                         revision.get_apparent_authors())
 
2172
        self.assertEqual('tree', revision.properties['branch-nick'])
 
2173
 
2094
2174
 
2095
2175
class MockTransform(object):
2096
2176