~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2007-07-15 11:24:18 UTC
  • mfrom: (2617 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070715112418-9nn4n6esxv60ny4b
merge bzr.dev@1617

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for interface conformance of 'WorkingTree.remove'"""
18
18
 
19
 
import re
20
19
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
21
20
from bzrlib import errors, osutils
22
21
 
23
22
class TestRemove(TestCaseWithWorkingTree):
24
23
    """Tests WorkingTree.remove"""
25
24
 
26
 
    files=['a', 'b/', 'b/c', 'd/']
 
25
    files = ['a', 'b/', 'b/c', 'd/']
 
26
    rfiles = ['b/c', 'b', 'a', 'd']
27
27
    a = ['a']
28
28
    b = ['b']
29
29
    b_c = ['b', 'b/c']
60
60
        tree = self.getTree()
61
61
        tree.add(TestRemove.files)
62
62
        self.assertInWorkingTree(TestRemove.files)
63
 
        try:
64
 
            tree.remove(TestRemove.files, keep_files=False)
65
 
            self.fail('Should throw BzrRemoveChangedFilesError')
66
 
        except errors.BzrRemoveChangedFilesError, e:
67
 
            self.assertTrue(re.match('Can\'t remove changed or unknown files:'
68
 
                '.*added:.*a.*b.*b/c.*d.*',
69
 
                str(e), re.DOTALL))
 
63
        err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
 
64
            TestRemove.files, keep_files=False)
 
65
        self.assertContainsRe(err.changes_as_text,
 
66
            '(?s)added:.*a.*b/.*b/c.*d/')
70
67
        self.assertInWorkingTree(TestRemove.files)
71
68
        self.failUnlessExists(TestRemove.files)
72
69
 
75
72
        tree = self.getTree()
76
73
        tree.add(TestRemove.a)
77
74
        tree.commit("make sure a is versioned")
78
 
        f = file('a', 'wb')
79
 
        f.write("some other new content!")
80
 
        f.close()
 
75
        self.build_tree_contents([('a', "some other new content!")])
81
76
        self.assertInWorkingTree(TestRemove.a)
82
 
        try:
83
 
            tree.remove(TestRemove.a, keep_files=False)
84
 
            self.fail('Should throw BzrRemoveChangedFilesError')
85
 
        except errors.BzrRemoveChangedFilesError, e:
86
 
            self.assertTrue(re.match('Can\'t remove changed or unknown files:'
87
 
                '.*modified:.*a.*',
88
 
                str(e), re.DOTALL))
 
77
        err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
 
78
            TestRemove.a, keep_files=False)
 
79
        self.assertContainsRe(err.changes_as_text, '(?s)modified:.*a')
89
80
        self.assertInWorkingTree(TestRemove.a)
90
81
        self.failUnlessExists(TestRemove.a)
91
82
 
94
85
        tree = self.getTree()
95
86
        tree.add(TestRemove.files)
96
87
        tree.commit("make sure files are versioned")
97
 
        for f in ['b/c', 'b', 'a', 'd']:
 
88
        for f in TestRemove.rfiles:
98
89
            osutils.delete_any(f)
99
90
        self.assertInWorkingTree(TestRemove.files)
100
91
        self.failIfExists(TestRemove.files)
104
95
        self.assertNotInWorkingTree(TestRemove.files)
105
96
        self.failIfExists(TestRemove.files)
106
97
 
 
98
    def test_remove_renamed_files(self):
 
99
        """Check that files are removed even if they are renamed."""
 
100
        tree = self.getTree()
 
101
        tree.add(TestRemove.files)
 
102
        tree.commit("make sure files are versioned")
 
103
 
 
104
        for f in TestRemove.rfiles:
 
105
            tree.rename_one(f,f+'x')
 
106
        rfilesx = ['bx/cx', 'bx', 'ax', 'dx']
 
107
        self.assertInWorkingTree(rfilesx)
 
108
        self.failUnlessExists(rfilesx)
 
109
 
 
110
        tree.remove(rfilesx, keep_files=False)
 
111
 
 
112
        self.assertNotInWorkingTree(rfilesx)
 
113
        self.failIfExists(rfilesx)
 
114
 
 
115
    def test_remove_renamed_changed_files(self):
 
116
        """Check that files are not removed if they are renamed and changed."""
 
117
        tree = self.getTree()
 
118
        tree.add(TestRemove.files)
 
119
        tree.commit("make sure files are versioned")
 
120
 
 
121
        for f in TestRemove.rfiles:
 
122
            tree.rename_one(f,f+'x')
 
123
        rfilesx = ['bx/cx', 'bx', 'ax', 'dx']
 
124
        self.build_tree_contents([('ax','changed and renamed!'),
 
125
                                  ('bx/cx','changed and renamed!')])
 
126
        self.assertInWorkingTree(rfilesx)
 
127
        self.failUnlessExists(rfilesx)
 
128
 
 
129
        err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
 
130
            rfilesx, keep_files=False)
 
131
        self.assertContainsRe(err.changes_as_text,
 
132
            '(?s)modified:.*ax.*bx/cx')
 
133
        self.assertInWorkingTree(rfilesx)
 
134
        self.failUnlessExists(rfilesx)
 
135
 
107
136
    def test_force_remove_changed_files(self):
108
137
        """Check that changed files are removed and deleted when forced."""
109
138
        tree = self.getTree()
118
147
    def test_remove_unknown_files(self):
119
148
        """Try to delete unknown files."""
120
149
        tree = self.getTree()
121
 
        try:
122
 
            tree.remove(TestRemove.files, keep_files=False)
123
 
            self.fail('Should throw BzrRemoveChangedFilesError')
124
 
        except errors.BzrRemoveChangedFilesError, e:
125
 
            self.assertTrue(re.match('Can\'t remove changed or unknown files:'
126
 
                '.*unknown:.*b/c.*b.*a.*d.*',
127
 
                str(e), re.DOTALL))
 
150
        err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
 
151
            TestRemove.files, keep_files=False)
 
152
        self.assertContainsRe(err.changes_as_text,
 
153
            '(?s)unknown:.*d/.*b/c.*b/.*a.*')
128
154
 
129
155
    def test_remove_nonexisting_files(self):
130
156
        """Try to delete non-existing files."""
131
157
        tree = self.getTree()
132
158
        tree.remove([''], keep_files=False)
133
 
        try:
134
 
            tree.remove(['xyz', 'abc/def'], keep_files=False)
135
 
            self.fail('Should throw BzrRemoveChangedFilesError')
136
 
        except errors.BzrRemoveChangedFilesError, e:
137
 
            self.assertTrue(re.match('Can\'t remove changed or unknown files:'
138
 
                '.*unknown:.*xyz.*abc/def.*',
139
 
                str(e), re.DOTALL))
 
159
        tree.remove(['xyz', 'abc/def'], keep_files=False)
140
160
 
141
161
    def test_remove_nonempty_directory(self):
142
162
        """Unchanged non-empty directories should be deleted."""
156
176
        tree.commit("make sure b is versioned")
157
177
        self.assertInWorkingTree(TestRemove.files)
158
178
        self.failUnlessExists(TestRemove.files)
159
 
        f = file('b/my_unknown_file', 'wb')
160
 
        f.write("some content!")
161
 
        f.close()
162
 
        try:
163
 
            tree.remove(TestRemove.b, keep_files=False)
164
 
            self.fail('Should throw BzrRemoveChangedFilesError')
165
 
        except errors.BzrRemoveChangedFilesError, e:
166
 
            self.assertTrue(re.match('Can\'t remove changed or unknown files:'
167
 
                '.*unknown:.*b/my_unknown_file.*',
168
 
                str(e), re.DOTALL))
 
179
        self.build_tree(['b/my_unknown_file'])
 
180
        err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
 
181
            TestRemove.b, keep_files=False)
 
182
        self.assertContainsRe(err.changes_as_text,
 
183
            '(?s)unknown:.*b/my_unknown_file')
169
184
        self.assertInWorkingTree(TestRemove.b)
170
185
        self.failUnlessExists(TestRemove.b)
171
186
 
184
199
        tree = self.getTree()
185
200
        tree.add(TestRemove.b_c)
186
201
        tree.commit("make sure b and c are versioned")
187
 
        f = file('b/c', 'wb')
188
 
        f.write("some other new content!")
189
 
        f.close()
 
202
        self.build_tree_contents([('b/c', "some other new content!")])
190
203
        self.assertInWorkingTree(TestRemove.b_c)
191
 
        try:
192
 
            tree.remove(TestRemove.b, keep_files=False)
193
 
            self.fail('Should throw BzrRemoveChangedFilesError')
194
 
        except errors.BzrRemoveChangedFilesError, e:
195
 
            self.assertTrue(re.match('Can\'t remove changed or unknown files:'
196
 
                '.*modified:.*b/c.*',
197
 
                str(e), re.DOTALL))
 
204
        err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
 
205
            TestRemove.b, keep_files=False)
 
206
        self.assertContainsRe(err.changes_as_text, '(?s)modified:.*b/c')
198
207
        self.assertInWorkingTree(TestRemove.b_c)
199
208
        self.failUnlessExists(TestRemove.b_c)
200
209