1
# Copyright (C) 2006, 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tests for interface conformance of 'WorkingTree.remove'"""
19
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
21
class TestRemove(TestCaseWithWorkingTree):
22
"""Tests WorkingTree.remove"""
24
files=['a','b/','b/c']
29
self.makeAndChdirToTestDir()
30
tree = self.make_branch_and_tree('.')
31
self.build_tree(TestRemove.files)
34
def test_remove_unchanged_files(self):
35
"""check that unchanged files are removed and deleted."""
37
tree.add(TestRemove.files)
38
tree.commit("files must not have changes")
40
self.assertInWorkingTree(TestRemove.files)
42
tree.remove(TestRemove.files, keep_files=False)
44
self.assertNotInWorkingTree(TestRemove.files)
45
self.failIfExists(TestRemove.files)
47
def test_remove_changed_files(self):
48
"""check that changed files are removed but not deleted."""
50
tree.add(TestRemove.files)
51
self.assertInWorkingTree(TestRemove.files)
53
tree.remove(TestRemove.files, keep_files=False)
55
self.assertNotInWorkingTree(TestRemove.files)
56
self.failUnlessExists(TestRemove.files)
58
def test_force_remove_changed_files(self):
59
"""check that changed files are removed and deleted when forced."""
61
tree.add(TestRemove.files)
62
self.assertInWorkingTree(TestRemove.files)
64
tree.remove(TestRemove.files, keep_files=False, force=True)
66
self.assertNotInWorkingTree(TestRemove.files)
67
self.failIfExists(TestRemove.files)
69
def test_remove_nonexisting_files(self):
70
"""delete files which does not exist."""
72
tree.remove(TestRemove.files, keep_files=False)
73
tree.remove([''], keep_files=False)
74
tree.remove(TestRemove.b, keep_files=False)
76
def test_remove_nonempty_directory(self):
78
tree.add(TestRemove.files)
79
tree.commit("make sure b is versioned")
80
self.assertInWorkingTree(TestRemove.files)
81
self.failUnlessExists(TestRemove.files)
82
tree.remove(TestRemove.b, keep_files=False)
83
self.assertNotInWorkingTree(TestRemove.b)
84
self.failUnlessExists(TestRemove.b)
86
def test_force_remove_nonempty_directory(self):
88
tree.add(TestRemove.files)
89
tree.commit("make sure b is versioned")
90
self.assertInWorkingTree(TestRemove.files)
91
self.failUnlessExists(TestRemove.files)
92
tree.remove(TestRemove.b, keep_files=False, force=True)
93
self.assertNotInWorkingTree(TestRemove.b_c)
94
self.failIfExists(TestRemove.b_c)
96
def test_remove_keep(self):
97
"""check that files are unversioned but not delete."""
99
tree.add(TestRemove.files)
100
self.assertInWorkingTree(TestRemove.files)
102
tree.remove(TestRemove.files)
103
self.assertNotInWorkingTree(TestRemove.files)
104
self.failUnlessExists(TestRemove.files)