1
# Copyright (C) 2005 by Aaron Bentley
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
19
from StringIO import StringIO
20
from unittest import makeSuite
22
from bzrlib.bzrdir import BzrDir
24
from bzrlib.plugins.bzrtools.clean_tree import clean_tree, iter_deletables
26
from bzrtools.clean_tree import clean_tree, iter_deletables
27
from bzrlib.osutils import has_symlinks
28
from bzrlib.tests import TestCaseInTempDir
31
class TestCleanTree(TestCaseInTempDir):
32
def test_symlinks(self):
33
if has_symlinks() is False:
36
BzrDir.create_standalone_workingtree('branch')
37
os.symlink(os.path.realpath('no-die-please'), 'branch/die-please')
38
os.mkdir('no-die-please')
39
assert os.path.exists('branch/die-please')
40
os.mkdir('no-die-please/child')
43
assert os.path.exists('no-die-please')
44
assert os.path.exists('no-die-please/child')
46
def test_iter_deletable(self):
47
"""Files are selected for deletion appropriately"""
49
tree = BzrDir.create_standalone_workingtree('branch')
50
file('branch/file.BASE', 'wb').write('contents')
51
self.assertEqual(len(list(iter_deletables(tree))), 1)
52
file('branch/file~', 'wb').write('contents')
53
file('branch/file.pyc', 'wb').write('contents')
54
dels = [r for a,r in iter_deletables(tree)]
55
assert 'file~' not in dels
56
assert 'file.pyc' not in dels
57
dels = [r for a,r in iter_deletables(tree, detritus=True)]
58
assert 'file~' in dels
59
assert 'file.pyc' not in dels
60
dels = [r for a,r in iter_deletables(tree, ignored=True)]
61
assert 'file~' in dels
62
assert 'file.BASE' in dels
63
assert 'file.pyc' in dels
64
dels = [r for a,r in iter_deletables(tree, unknown=False)]
65
assert 'file.BASE' not in dels
68
return makeSuite(TestCleanTree)