~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Marius Kruger
  • Date: 2007-08-09 16:50:51 UTC
  • mto: (2778.1.1 rm.marius)
  • mto: This revision was merged to the branch mainline in revision 2782.
  • Revision ID: amanic@gmail.com-20070809165051-0kyj9w1hox2ng2n1
* workingtree_implementations/test_remove
  - Let getTree check if the files were really created.
  - Add utility method getCommittedTree.
  - Fix test_remove_nonempty_directory to not check for the removal of empty 
    directories.
  - Fix test_dont_remove_directory_with_unknowns to check if we refuse to 
    delete directories containing unknown files or directories.
  - Fix some method names and docstrings as per review
* workingtree.remove
  - Don't automatically remove empty directories.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    b = ['b']
29
29
    b_c = ['b', 'b/c']
30
30
 
31
 
    def getTree(self):
 
31
    def getTree(self, files=None):
 
32
        if not files:
 
33
            files = TestRemove.files
32
34
        tree = self.make_branch_and_tree('.')
33
 
        self.build_tree(TestRemove.files)
 
35
        self.build_tree(files)
 
36
        self.failUnlessExists(files)
 
37
        return tree
 
38
 
 
39
    def getCommittedTree(self, message, files):
 
40
        tree = self.getTree(files)
 
41
        tree.add(files)
 
42
        tree.commit(message)
 
43
        self.assertInWorkingTree(files)
34
44
        return tree
35
45
 
36
46
    def test_remove_keep(self):
169
179
        tree.remove(['xyz', 'abc/def'], keep_files=False)
170
180
 
171
181
    def test_remove_nonempty_directory(self):
172
 
        """Unchanged non-empty directories should be deleted."""
173
 
        tree = self.make_branch_and_tree('.')
 
182
        """Unchanged directories should be deleted."""
174
183
        files = ['b/', 'b/c', 'b/sub_directory/', 'b/sub_directory/with_file']
175
 
        self.build_tree(files)
 
184
        tree = self.getTree(files)
176
185
        tree.add(files)
177
186
        tree.commit("make sure b is versioned")
178
187
        self.assertInWorkingTree(files)
179
188
        self.failUnlessExists(files)
180
 
        self.build_tree(['b/unknown_directory/', 'b/unknown_directory/ud2/'])
181
189
        tree.remove('b', keep_files=False)
182
190
        self.assertNotInWorkingTree('b')
183
191
        self.failIfExists('b')
184
192
 
185
 
    def test_remove_nonempty_directory_with_unknowns(self):
186
 
        """Unchanged non-empty directories should not be deleted."""
187
 
        tree = self.getTree()
188
 
        tree.add(TestRemove.files)
189
 
        tree.commit("make sure b is versioned")
190
 
        self.assertInWorkingTree(TestRemove.files)
191
 
        self.failUnlessExists(TestRemove.files)
192
 
        self.build_tree(['b/my_unknown_file'])
193
 
 
194
 
        err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
195
 
            TestRemove.b, keep_files=False)
196
 
        self.assertContainsRe(err.changes_as_text,
197
 
            '(?s)unknown:.*b/my_unknown_file')
198
 
 
199
 
        self.assertInWorkingTree(TestRemove.b)
200
 
        self.failUnlessExists(TestRemove.b)
201
 
 
202
 
    def test_force_remove_nonempty_directory(self):
 
193
    def test_dont_remove_directory_with_unknowns(self):
 
194
        """Directories with unknowns should not be deleted."""
 
195
        directories = ['a/', 'b/', 'c/', 'c/c/']
 
196
        tree = self.getCommittedTree("make sure directories is versioned",
 
197
            directories)
 
198
 
 
199
        self.build_tree(['a/unknown_file'])
 
200
        err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
 
201
            'a', keep_files=False)
 
202
        self.assertContainsRe(err.changes_as_text,
 
203
            '(?s)unknown:.*a/unknown_file')
 
204
 
 
205
        self.build_tree(['b/unknown_directory'])
 
206
        err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
 
207
            'b', keep_files=False)
 
208
        self.assertContainsRe(err.changes_as_text,
 
209
            '(?s)unknown:.*b/unknown_directory')
 
210
 
 
211
        self.build_tree(['c/c/unknown_file'])
 
212
        err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
 
213
            'c/c', keep_files=False)
 
214
        self.assertContainsRe(err.changes_as_text,
 
215
            '(?s)unknown:.*c/c/unknown_file')
 
216
 
 
217
        self.assertInWorkingTree(directories)
 
218
        self.failUnlessExists(directories)
 
219
 
 
220
    def test_force_remove_directory_with_unknowns(self):
203
221
        """Unchanged non-empty directories should be deleted when forced."""
204
222
        tree = self.getTree()
205
223
        tree.add(TestRemove.files)