~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_move.py

implement several new WorkingTree.move() tests
and fix the bugs in WorkingTree4.move() that it uncovers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Tests for interface conformance of 'workingtree.put_mkdir'"""
19
19
 
 
20
from bzrlib import (
 
21
    errors,
 
22
    )
 
23
 
20
24
from bzrlib.workingtree_4 import WorkingTreeFormat4
21
25
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
22
26
 
79
83
            if not isinstance(self.workingtree_format, WorkingTreeFormat4):
80
84
                raise
81
85
 
 
86
    def test_move_target_not_dir(self):
 
87
        tree = self.make_branch_and_tree('.')
 
88
        self.build_tree(['a'])
 
89
        tree.add(['a'])
 
90
 
 
91
        self.assertRaises(errors.BzrMoveFailedError,
 
92
                          tree.move, ['a'], 'not-a-dir')
 
93
 
 
94
    def test_move_non_existent(self):
 
95
        tree = self.make_branch_and_tree('.')
 
96
        self.build_tree(['a/'])
 
97
        tree.add(['a'])
 
98
        self.assertRaises(errors.BzrMoveFailedError,
 
99
                          tree.move, ['not-a-file'], 'a')
 
100
 
 
101
    def test_move_target_not_versioned(self):
 
102
        tree = self.make_branch_and_tree('.')
 
103
        self.build_tree(['a/', 'b'])
 
104
        tree.add(['b'])
 
105
        self.assertRaises(errors.BzrMoveFailedError,
 
106
                          tree.move, ['b'], 'a')
 
107
 
 
108
    # TODO: jam 20070225 What about a test when the target is now a directory,
 
109
    #       but in the past it was a file. Theoretically WorkingTree should
 
110
    #       notice the kind change.
 
111
 
 
112
    def test_move_unversioned(self):
 
113
        tree = self.make_branch_and_tree('.')
 
114
        self.build_tree(['a/', 'b'])
 
115
        tree.add(['a'])
 
116
        self.assertRaises(errors.BzrMoveFailedError,
 
117
                          tree.move, ['b'], 'a')
 
118
 
 
119
    def test_move_multi_unversioned(self):
 
120
        tree = self.make_branch_and_tree('.')
 
121
        self.build_tree(['a/', 'b', 'c', 'd'])
 
122
        tree.add(['a', 'c', 'd'])
 
123
        self.assertRaises(errors.BzrMoveFailedError,
 
124
                          tree.move, ['c', 'b', 'd'], 'a')
 
125
        self.assertRaises(errors.BzrMoveFailedError,
 
126
                          tree.move, ['b', 'c', 'd'], 'a')
 
127
        self.assertRaises(errors.BzrMoveFailedError,
 
128
                          tree.move, ['c', 'd', 'b'], 'a')
 
129
 
 
130
    def get_tree_layout(self, tree):
 
131
        """Get the (path, file_id) pairs for the current tree."""
 
132
        tree.lock_read()
 
133
        try:
 
134
            return [(path, ie.file_id) for path, ie
 
135
                    in tree.iter_entries_by_dir()]
 
136
        finally:
 
137
            tree.unlock()
 
138
 
 
139
    def assertTreeLayout(self, expected, tree):
 
140
        """Check that the tree has the correct layout."""
 
141
        actual = self.get_tree_layout(tree)
 
142
        self.assertEqual(expected, actual)
 
143
 
 
144
    def test_move_subdir(self):
 
145
        tree = self.make_branch_and_tree('.')
 
146
        self.build_tree(['a', 'b/', 'b/c'])
 
147
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
 
148
        root_id = tree.get_root_id()
 
149
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
150
                               ('b/c', 'c-id')], tree)
 
151
        a_contents = tree.get_file_text('a-id')
 
152
        tree.move(['a'], 'b')
 
153
        self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id'),
 
154
                               ('b/c', 'c-id')], tree)
 
155
        self.failIfExists('a')
 
156
        self.failUnlessExists('b/a')
 
157
        self.check_file_contents('b/a', a_contents)
 
158
 
 
159
    def test_move_parent_dir(self):
 
160
        tree = self.make_branch_and_tree('.')
 
161
        self.build_tree(['a', 'b/', 'b/c'])
 
162
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
 
163
        root_id = tree.get_root_id()
 
164
        c_contents = tree.get_file_text('c-id')
 
165
        tree.move(['b/c'], '')
 
166
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
167
                               ('c', 'c-id')], tree)
 
168
        self.failIfExists('b/c')
 
169
        self.failUnlessExists('c')
 
170
        self.check_file_contents('c', c_contents)
 
171
 
 
172
    def dont_test(self):
 
173
        self.run_bzr('mv', 'a', 'b')
 
174
        self.assertMoved('a','b')
 
175
 
 
176
        self.run_bzr('mv', 'b', 'subdir')
 
177
        self.assertMoved('b','subdir/b')
 
178
 
 
179
        self.run_bzr('mv', 'subdir/b', 'a')
 
180
        self.assertMoved('subdir/b','a')
 
181
 
 
182
        self.run_bzr('mv', 'a', 'c', 'subdir')
 
183
        self.assertMoved('a','subdir/a')
 
184
        self.assertMoved('c','subdir/c')
 
185
 
 
186
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
 
187
        self.assertMoved('subdir/a','subdir/newa')