~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

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
        if os.name == "posix" and sys.platform != "cygwin":
 
863
            # posix filesystems fail on renaming if the readonly bit is set
 
864
            osutils.make_readonly(self.wt.abspath('first-dir'))
 
865
        elif os.name == "nt":
 
866
            # windows filesystems fail on renaming open files
 
867
            self.addCleanup(file(self.wt.abspath('myfile')).close)
 
868
        else:
 
869
            self.skip("Don't know how to force a permissions error on rename")
 
870
        # now transform to rename
 
871
        rename_transform, root_id = self.get_transform()
 
872
        file_trans_id = rename_transform.trans_id_file_id('myfile-id')
 
873
        dir_id = rename_transform.trans_id_file_id('first-id')
 
874
        rename_transform.adjust_path('newname', dir_id, file_trans_id)
 
875
        e = self.assertRaises(errors.TransformRenameFailed,
 
876
            rename_transform.apply)
 
877
        # On nix looks like: 
 
878
        # "Failed to rename .../work/.bzr/checkout/limbo/new-1
 
879
        # to .../first-dir/newname: [Errno 13] Permission denied"
 
880
        # On windows looks like:
 
881
        # "Failed to rename .../work/myfile to 
 
882
        # .../work/.bzr/checkout/limbo/new-1: [Errno 13] Permission denied"
 
883
        # The strerror will vary per OS and language so it's not checked here
 
884
        self.assertContainsRe(str(e),
 
885
            "Failed to rename .*(first-dir.newname:|myfile)")
 
886
 
833
887
    def test_set_executability_order(self):
834
888
        """Ensure that executability behaves the same, no matter what order.
835
889
 
1923
1977
        self.assertTrue(source.is_executable('file1-id'))
1924
1978
 
1925
1979
    def install_rot13_content_filter(self, pattern):
 
1980
        # We could use
 
1981
        # self.addCleanup(filters._reset_registry, filters._reset_registry())
 
1982
        # below, but that looks a bit... hard to read even if it's exactly
 
1983
        # the same thing.
1926
1984
        original_registry = filters._reset_registry()
1927
1985
        def restore_registry():
1928
1986
            filters._reset_registry(original_registry)
2087
2145
        self.assertRaises(errors.MalformedTransform, tt.commit, branch,
2088
2146
                          'message')
2089
2147
 
 
2148
    def test_commit_rich_revision_data(self):
 
2149
        branch, tt = self.get_branch_and_transform()
 
2150
        rev_id = tt.commit(branch, 'message', timestamp=1, timezone=43201,
 
2151
                           committer='me <me@example.com>',
 
2152
                           revprops={'foo': 'bar'}, revision_id='revid-1',
 
2153
                           authors=['Author1 <author1@example.com>',
 
2154
                              'Author2 <author2@example.com>',
 
2155
                               ])
 
2156
        self.assertEqual('revid-1', rev_id)
 
2157
        revision = branch.repository.get_revision(rev_id)
 
2158
        self.assertEqual(1, revision.timestamp)
 
2159
        self.assertEqual(43201, revision.timezone)
 
2160
        self.assertEqual('me <me@example.com>', revision.committer)
 
2161
        self.assertEqual(['Author1 <author1@example.com>',
 
2162
                          'Author2 <author2@example.com>'],
 
2163
                         revision.get_apparent_authors())
 
2164
        del revision.properties['authors']
 
2165
        self.assertEqual({'foo': 'bar',
 
2166
                          'branch-nick': 'tree'},
 
2167
                         revision.properties)
 
2168
 
 
2169
    def test_no_explicit_revprops(self):
 
2170
        branch, tt = self.get_branch_and_transform()
 
2171
        rev_id = tt.commit(branch, 'message', authors=[
 
2172
            'Author1 <author1@example.com>',
 
2173
            'Author2 <author2@example.com>', ])
 
2174
        revision = branch.repository.get_revision(rev_id)
 
2175
        self.assertEqual(['Author1 <author1@example.com>',
 
2176
                          'Author2 <author2@example.com>'],
 
2177
                         revision.get_apparent_authors())
 
2178
        self.assertEqual('tree', revision.properties['branch-nick'])
 
2179
 
2090
2180
 
2091
2181
class MockTransform(object):
2092
2182
 
2367
2457
    def test_ignore_pb(self):
2368
2458
        # pb could be supported, but TT.iter_changes doesn't support it.
2369
2459
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2370
 
        preview_tree.iter_changes(revision_tree, pb=progress.DummyProgress())
 
2460
        preview_tree.iter_changes(revision_tree)
2371
2461
 
2372
2462
    def test_kind(self):
2373
2463
        revision_tree = self.create_tree()
2775
2865
        file_trans_id = preview.trans_id_file_id('file-id')
2776
2866
        preview.delete_contents(file_trans_id)
2777
2867
        preview.create_file('a\nb\n', file_trans_id)
2778
 
        pb = progress.DummyProgress()
2779
2868
        preview_tree = preview.get_preview_tree()
2780
 
        merger = Merger.from_revision_ids(pb, preview_tree,
 
2869
        merger = Merger.from_revision_ids(None, preview_tree,
2781
2870
                                          child_tree.branch.last_revision(),
2782
2871
                                          other_branch=child_tree.branch,
2783
2872
                                          tree_branch=work_tree.branch)
2795
2884
        tt.new_file('name', tt.root, 'content', 'file-id')
2796
2885
        tree2 = self.make_branch_and_tree('tree2')
2797
2886
        tree2.set_root_id('TREE_ROOT')
2798
 
        pb = progress.DummyProgress()
2799
2887
        merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
2800
 
                                         pb, tree.basis_tree())
 
2888
                                         None, tree.basis_tree())
2801
2889
        merger.merge_type = Merge3Merger
2802
2890
        merger.do_merge()
2803
2891
 
2813
2901
        tt.create_file('baz', trans_id)
2814
2902
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
2815
2903
        self.build_tree_contents([('tree2/foo', 'qux')])
2816
 
        pb = progress.DummyProgress()
 
2904
        pb = None
2817
2905
        merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
2818
2906
                                         pb, tree.basis_tree())
2819
2907
        merger.merge_type = Merge3Merger