/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_remove.py

  • Committer: Vincent Ladeuil
  • Date: 2007-06-26 20:32:49 UTC
  • mto: (2581.1.1 cleanup-runbzr)
  • mto: This revision was merged to the branch mainline in revision 2588.
  • Revision ID: v.ladeuil+lp@free.fr-20070626203249-sqm4afiai5dxofum
Deprecate the varargs syntax and fix the tests.

* bzrlib/tests/__init__.py:
(TestCase.run_bzr): Activate the deprecation warning.
(TestCase.run_bzr_error): Add error_regexes to kwargs or run_bzr
get confused.

* bzrlib/tests/blackbox/test_selftest.py:
(TestRunBzr.test_args): Activate.

* bzrlib/tests/blackbox/test_inventory.py:
(TestInventory.assertInventoryEqual): Build the command from args
if not None.

* bzrlib/tests/blackbox/test_ls.py:
(TestLS.ls_equals): Build the command from args if not None.

* bzrlib/tests/blackbox/test_remove_tree.py:
(TestRemoveTree.test_remove_tree_lightweight_checkout_explicit):
Nice catch, we were calling run_bzr instead of run_bzr_error. This
went unnoticed for some time...

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
 
18
 
import os
19
 
import sys
20
 
 
21
 
from bzrlib.tests import SymlinkFeature, TestSkipped
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
import os, re, shlex
 
19
 
22
20
from bzrlib.tests.blackbox import ExternalBase
23
21
from bzrlib.workingtree import WorkingTree
24
22
from bzrlib import osutils
33
31
 
34
32
class TestRemove(ExternalBase):
35
33
 
36
 
    def _make_tree_and_add(self, paths):
 
34
    def _make_add_and_assert_tree(self, files):
37
35
        tree = self.make_branch_and_tree('.')
38
 
        tree.lock_write()
39
 
        try:
40
 
            self.build_tree(paths)
41
 
            for path in paths:
42
 
                file_id=str(path).replace('/', '_') + _id
43
 
                tree.add(path, file_id)
44
 
        finally:
45
 
            tree.unlock()
 
36
        self.build_tree(files)
 
37
        for f in files:
 
38
            id=str(f).replace('/', '_') + _id
 
39
            tree.add(f, id)
 
40
            self.assertEqual(tree.path2id(f), id)
 
41
            self.failUnlessExists(f)
 
42
            self.assertInWorkingTree(f)
46
43
        return tree
47
44
 
48
45
    def assertFilesDeleted(self, files):
61
58
        f.write("\nsome other new content!")
62
59
        f.close()
63
60
 
64
 
    def run_bzr_remove_changed_files(self, error_regexes, files_to_remove,
65
 
                                     working_dir=None):
66
 
        error_regexes.extend(["Can't safely remove modified or unknown files:",
 
61
    def run_bzr_remove_changed_files(self, error_regexes, files_to_remove):
 
62
        error_regexes.extend(["Can't remove changed or unknown files:",
67
63
            'Use --keep to not delete them,'
68
64
            ' or --force to delete them regardless.'
69
65
            ])
70
66
        self.run_bzr_error(error_regexes,
71
 
                           ['remove'] + list(files_to_remove),
72
 
                           working_dir=working_dir)
 
67
            'remove ' + ' '.join(files_to_remove))
73
68
        #see if we can force it now
74
 
        self.run_bzr(['remove', '--force'] + list(files_to_remove),
75
 
                     working_dir=working_dir)
76
 
 
77
 
    def test_remove_new_no_files_specified(self):
78
 
        tree = self.make_branch_and_tree('.')
 
69
        self.run_bzr('remove --force ' + ' '.join(files_to_remove))
 
70
 
 
71
    def test_remove_no_files_specified(self):
 
72
        tree = self._make_add_and_assert_tree([])
 
73
        self.run_bzr_error(["bzr: ERROR: Specify one or more files to remove, "
 
74
            "or use --new."], 'remove')
 
75
 
79
76
        self.run_bzr_error(["bzr: ERROR: No matching files."], 'remove --new')
80
 
        self.run_bzr_error(["bzr: ERROR: No matching files."], 'remove --new .')
81
 
 
82
 
    def test_remove_no_files_specified(self):
83
 
        tree = self._make_tree_and_add(['foo'])
84
 
        out, err = self.run_bzr(['rm'])
85
 
        self.assertEqual('', err)
86
 
        self.assertEqual('', out)
87
 
        self.assertInWorkingTree('foo', tree=tree)
88
 
        self.failUnlessExists('foo')
89
 
 
90
 
    def test_remove_no_files_specified_missing_dir_and_contents(self):
91
 
        tree = self._make_tree_and_add(
92
 
            ['foo', 'dir/', 'dir/missing/', 'dir/missing/child'])
93
 
        self.get_transport('.').delete_tree('dir/missing')
94
 
        out, err = self.run_bzr(['rm'])
95
 
        self.assertEqual('', out)
96
 
        self.assertEqual(
97
 
            'removed dir/missing/child\n'
98
 
            'removed dir/missing\n',
99
 
            err)
100
 
        # non-missing paths not touched:
101
 
        self.assertInWorkingTree('foo', tree=tree)
102
 
        self.failUnlessExists('foo')
103
 
        self.assertInWorkingTree('dir', tree=tree)
104
 
        self.failUnlessExists('dir')
105
 
        # missing files unversioned
106
 
        self.assertNotInWorkingTree('dir/missing', tree=tree)
107
 
        self.assertNotInWorkingTree('dir/missing/child', tree=tree)
108
 
 
109
 
    def test_remove_no_files_specified_already_deleted(self):
110
 
        tree = self._make_tree_and_add(['foo', 'bar'])
111
 
        tree.commit('save foo and bar')
112
 
        os.unlink('bar')
113
 
        self.run_bzr(['rm'])
114
 
        self.assertEqual(None, tree.path2id('bar'))
115
 
        # Running rm with a deleted file does not error.
116
 
        out, err = self.run_bzr(['rm'])
117
 
        self.assertEqual('', out)
118
 
        self.assertEqual('', err)
119
 
 
120
 
    def test_remove_no_files_specified_missing_file(self):
121
 
        tree = self._make_tree_and_add(['foo', 'bar'])
122
 
        os.unlink('bar')
123
 
        out, err = self.run_bzr(['rm'])
124
 
        self.assertEqual('', out)
125
 
        self.assertEqual('removed bar\n', err)
126
 
        # non-missing files not touched:
127
 
        self.assertInWorkingTree('foo', tree=tree)
128
 
        self.failUnlessExists('foo')
129
 
        # missing files unversioned
130
 
        self.assertNotInWorkingTree('bar', tree=tree)
131
 
 
132
 
    def test_remove_no_files_specified_missing_link(self):
133
 
        self.requireFeature(SymlinkFeature)
134
 
        tree = self._make_tree_and_add(['foo'])
135
 
        os.symlink('foo', 'linkname')
136
 
        tree.add(['linkname'])
137
 
        os.unlink('linkname')
138
 
        out, err = self.run_bzr(['rm'])
139
 
        self.assertEqual('', out)
140
 
        self.assertEqual('removed linkname\n', err)
141
 
        # non-missing files not touched:
142
 
        self.assertInWorkingTree('foo', tree=tree)
143
 
        self.failUnlessExists('foo')
144
 
        # missing files unversioned
145
 
        self.assertNotInWorkingTree('linkname', tree=tree)
 
77
 
 
78
        self.run_bzr_error(["bzr: ERROR: No matching files."],
 
79
            'remove --new .')
146
80
 
147
81
    def test_rm_one_file(self):
148
 
        tree = self._make_tree_and_add([a])
 
82
        tree = self._make_add_and_assert_tree([a])
149
83
        self.run_bzr("commit -m 'added a'")
150
84
        self.run_bzr('rm a', error_regexes=["deleted a"])
151
85
        self.assertFilesDeleted([a])
152
86
 
153
87
    def test_remove_one_file(self):
154
 
        tree = self._make_tree_and_add([a])
 
88
        tree = self._make_add_and_assert_tree([a])
155
89
        self.run_bzr("commit -m 'added a'")
156
90
        self.run_bzr('remove a', error_regexes=["deleted a"])
157
91
        self.assertFilesDeleted([a])
158
92
 
159
93
    def test_remove_keep_one_file(self):
160
 
        tree = self._make_tree_and_add([a])
 
94
        tree = self._make_add_and_assert_tree([a])
161
95
        self.run_bzr('remove --keep a', error_regexes=["removed a"])
162
96
        self.assertFilesUnversioned([a])
163
97
 
164
98
    def test_remove_one_deleted_file(self):
165
 
        tree = self._make_tree_and_add([a])
 
99
        tree = self._make_add_and_assert_tree([a])
166
100
        self.run_bzr("commit -m 'added a'")
167
101
        os.unlink(a)
168
102
        self.assertInWorkingTree(a)
172
106
    def test_remove_invalid_files(self):
173
107
        self.build_tree(files)
174
108
        tree = self.make_branch_and_tree('.')
175
 
        self.run_bzr(['remove', '.', 'xyz', 'abc/def'])
 
109
        self.run_bzr_remove_changed_files(['unknown:[.\s]*xyz[.\s]*abc/def'],
 
110
            ['.', 'xyz', 'abc/def'])
176
111
 
177
112
    def test_remove_unversioned_files(self):
178
113
        self.build_tree(files)
181
116
            ['unknown:[.\s]*d/[.\s]*b/c[.\s]*b/[.\s]*a'], files)
182
117
 
183
118
    def test_remove_changed_files(self):
184
 
        tree = self._make_tree_and_add(files)
 
119
        tree = self._make_add_and_assert_tree(files)
185
120
        self.run_bzr("commit -m 'added files'")
186
121
        self.changeFile(a)
187
122
        self.changeFile(c)
188
123
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'], files)
189
124
 
190
 
    def test_remove_changed_ignored_files(self):
191
 
        tree = self._make_tree_and_add(['a'])
192
 
        self.run_bzr(['ignore', 'a'])
193
 
        self.run_bzr_remove_changed_files(['added:[.\s]*a'], ['a'])
194
 
 
195
125
    def test_remove_changed_files_from_child_dir(self):
196
 
        if sys.platform == 'win32':
197
 
            raise TestSkipped("Windows unable to remove '.' directory")
198
 
        tree = self._make_tree_and_add(files)
 
126
        tree = self._make_add_and_assert_tree(files)
199
127
        self.run_bzr("commit -m 'added files'")
200
128
        self.changeFile(a)
201
129
        self.changeFile(c)
202
 
        self.run_bzr_remove_changed_files(
203
 
            ['modified:[.\s]*a[.\s]*b/c'],
204
 
            ['../a', 'c', '.', '../d'], working_dir='b')
 
130
        os.chdir('b')
 
131
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'],
 
132
            ['../a', 'c', '.', '../d'])
 
133
        os.chdir('..')
205
134
        self.assertNotInWorkingTree(files)
206
135
        self.failIfExists(files)
207
136
 
214
143
    def test_remove_force_unversioned_files(self):
215
144
        self.build_tree(files)
216
145
        tree = self.make_branch_and_tree('.')
217
 
        self.run_bzr(['remove', '--force'] + list(files),
 
146
        self.run_bzr('remove --force ' + ' '.join(files),
218
147
                     error_regexes=["deleted a", "deleted b",
219
148
                                    "deleted b/c", "deleted d"])
220
149
        self.assertFilesDeleted(files)
221
150
 
222
151
    def test_remove_deleted_files(self):
223
 
        tree = self._make_tree_and_add(files)
 
152
        tree = self._make_add_and_assert_tree(files)
224
153
        self.run_bzr("commit -m 'added files'")
225
154
        my_files=[f for f in files]
226
155
        my_files.sort(reverse=True)
233
162
        self.failIfExists(files)
234
163
 
235
164
    def test_remove_non_existing_files(self):
236
 
        tree = self._make_tree_and_add([])
237
 
        self.run_bzr(['remove', 'b'])
 
165
        tree = self._make_add_and_assert_tree([])
 
166
        self.run_bzr_remove_changed_files(['unknown:[.\s]*b'], ['b'])
238
167
 
239
168
    def test_remove_keep_non_existing_files(self):
240
 
        tree = self._make_tree_and_add([])
 
169
        tree = self._make_add_and_assert_tree([])
241
170
        self.run_bzr('remove --keep b', error_regexes=["b is not versioned."])
242
171
 
243
172
    def test_remove_files(self):
244
 
        tree = self._make_tree_and_add(files)
 
173
        tree = self._make_add_and_assert_tree(files)
245
174
        self.run_bzr("commit -m 'added files'")
246
175
        self.run_bzr('remove a b b/c d',
247
176
                     error_regexes=["deleted a", "deleted b", "deleted b/c",
249
178
        self.assertFilesDeleted(files)
250
179
 
251
180
    def test_remove_keep_files(self):
252
 
        tree = self._make_tree_and_add(files)
 
181
        tree = self._make_add_and_assert_tree(files)
253
182
        self.run_bzr("commit -m 'added files'")
254
183
        self.run_bzr('remove --keep a b b/c d',
255
184
                     error_regexes=["removed a", "removed b", "removed b/c",
257
186
        self.assertFilesUnversioned(files)
258
187
 
259
188
    def test_remove_with_new(self):
260
 
        tree = self._make_tree_and_add(files)
 
189
        tree = self._make_add_and_assert_tree(files)
261
190
        self.run_bzr('remove --new --keep',
262
191
                     error_regexes=["removed a", "removed b", "removed b/c"])
263
192
        self.assertFilesUnversioned(files)
264
193
 
265
194
    def test_remove_with_new_in_dir1(self):
266
 
        tree = self._make_tree_and_add(files)
 
195
        tree = self._make_add_and_assert_tree(files)
267
196
        self.run_bzr('remove --new --keep b b/c',
268
197
                     error_regexes=["removed b", "removed b/c"])
269
198
        tree = WorkingTree.open('.')
272
201
        self.assertFilesUnversioned([b,c])
273
202
 
274
203
    def test_remove_with_new_in_dir2(self):
275
 
        tree = self._make_tree_and_add(files)
 
204
        tree = self._make_add_and_assert_tree(files)
276
205
        self.run_bzr('remove --new --keep .',
277
206
                     error_regexes=["removed a", "removed b", "removed b/c"])
278
207
        tree = WorkingTree.open('.')