~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(gz) Backslash escape selftest output when printing to non-unicode consoles
 (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
import os
19
19
import sys
20
20
 
21
 
from bzrlib.tests import SymlinkFeature, TestSkipped
22
 
from bzrlib.tests.blackbox import ExternalBase
 
21
from bzrlib.tests import (
 
22
    script,
 
23
    SymlinkFeature,
 
24
    TestCaseWithTransport,
 
25
    TestSkipped,
 
26
    )
23
27
from bzrlib.workingtree import WorkingTree
24
28
from bzrlib import osutils
25
29
 
31
35
files=(a, b, c, d)
32
36
 
33
37
 
34
 
class TestRemove(ExternalBase):
 
38
class TestRemove(TestCaseWithTransport):
35
39
 
36
40
    def _make_tree_and_add(self, paths):
37
41
        tree = self.make_branch_and_tree('.')
61
65
        f.write("\nsome other new content!")
62
66
        f.close()
63
67
 
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:",
67
 
            'Use --keep to not delete them,'
68
 
            ' or --force to delete them regardless.'
69
 
            ])
70
 
        self.run_bzr_error(error_regexes,
71
 
                           ['remove'] + list(files_to_remove),
72
 
                           working_dir=working_dir)
73
 
        #see if we can force it now
74
 
        self.run_bzr(['remove', '--force'] + list(files_to_remove),
75
 
                     working_dir=working_dir)
 
68
    def run_bzr_remove_changed_files(self, files_to_remove, working_dir=None):
 
69
        self.run_bzr(['remove'] + list(files_to_remove),
 
70
           working_dir=working_dir)
76
71
 
77
72
    def test_remove_new_no_files_specified(self):
78
73
        tree = self.make_branch_and_tree('.')
177
172
    def test_remove_unversioned_files(self):
178
173
        self.build_tree(files)
179
174
        tree = self.make_branch_and_tree('.')
180
 
        self.run_bzr_remove_changed_files(
181
 
            ['unknown:[.\s]*d/[.\s]*b/c[.\s]*b/[.\s]*a'], files)
 
175
        self.run_bzr_remove_changed_files(files)
182
176
 
183
177
    def test_remove_changed_files(self):
184
178
        tree = self._make_tree_and_add(files)
185
179
        self.run_bzr("commit -m 'added files'")
186
180
        self.changeFile(a)
187
181
        self.changeFile(c)
188
 
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'], files)
 
182
        self.run_bzr_remove_changed_files(files)
189
183
 
190
184
    def test_remove_changed_ignored_files(self):
191
185
        tree = self._make_tree_and_add(['a'])
192
186
        self.run_bzr(['ignore', 'a'])
193
 
        self.run_bzr_remove_changed_files(['added:[.\s]*a'], ['a'])
 
187
        self.run_bzr_remove_changed_files(['a'])
194
188
 
195
189
    def test_remove_changed_files_from_child_dir(self):
196
190
        if sys.platform == 'win32':
200
194
        self.changeFile(a)
201
195
        self.changeFile(c)
202
196
        self.run_bzr_remove_changed_files(
203
 
            ['modified:[.\s]*a[.\s]*b/c'],
204
197
            ['../a', 'c', '.', '../d'], working_dir='b')
205
198
        self.assertNotInWorkingTree(files)
206
199
        self.failIfExists(files)
211
204
        self.run_bzr('remove --keep a', error_regexes=["a is not versioned."])
212
205
        self.assertFilesUnversioned(files)
213
206
 
 
207
    def test_remove_no_backup_unversioned_files(self):
 
208
        self.build_tree(files)
 
209
        tree = self.make_branch_and_tree('.')
 
210
        script.ScriptRunner().run_script(self, '''
 
211
        $ bzr remove --no-backup a b/ b/c d/
 
212
        2>deleted d
 
213
        2>removed b/c (but kept a copy: b/c.~1~)
 
214
        2>deleted b
 
215
        2>deleted a
 
216
        ''')
 
217
        self.assertFilesDeleted(files)
 
218
 
214
219
    def test_remove_force_unversioned_files(self):
215
220
        self.build_tree(files)
216
221
        tree = self.make_branch_and_tree('.')
217
 
        self.run_bzr(['remove', '--force'] + list(files),
218
 
                     error_regexes=["deleted a", "deleted b",
219
 
                                    "deleted b/c", "deleted d"])
 
222
        script.ScriptRunner().run_script(self, '''
 
223
        $ bzr remove --force a b/ b/c d/
 
224
        2>(The --force option is deprecated, rather use --no-backup in future.)
 
225
        2>deleted d
 
226
        2>removed b/c (but kept a copy: b/c.~1~)
 
227
        2>deleted b
 
228
        2>deleted a
 
229
        ''')
220
230
        self.assertFilesDeleted(files)
221
231
 
222
232
    def test_remove_deleted_files(self):