~benoit.pierre/bzrtools/shell_improvements

« back to all changes in this revision

Viewing changes to tests/clean_tree.py

  • Committer: Benoît Pierre
  • Date: 2009-08-02 12:55:24 UTC
  • mfrom: (682.1.36 bzrtools)
  • Revision ID: benoit.pierre@gmail.com-20090802125524-1p2oot1y2l0y3o9w
Merge with upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Aaron Bentley
2
 
#
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.
7
 
#
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.
12
 
#
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
16
 
 
17
 
 
18
 
import os
19
 
from StringIO import StringIO
20
 
from unittest import makeSuite
21
 
 
22
 
from bzrlib.bzrdir import BzrDir
23
 
from bzrlib.osutils import has_symlinks
24
 
from bzrlib.tests import TestCaseInTempDir
25
 
 
26
 
from bzrlib.plugins.bzrtools.clean_tree import clean_tree, iter_deletables
27
 
 
28
 
class TestCleanTree(TestCaseInTempDir):
29
 
    def test_symlinks(self):
30
 
        if has_symlinks() is False:
31
 
            return
32
 
        os.mkdir('branch')
33
 
        BzrDir.create_standalone_workingtree('branch')
34
 
        os.symlink(os.path.realpath('no-die-please'), 'branch/die-please')
35
 
        os.mkdir('no-die-please')
36
 
        assert os.path.exists('branch/die-please')
37
 
        os.mkdir('no-die-please/child')
38
 
 
39
 
        clean_tree('branch', unknown=True, no_prompt=True)
40
 
        assert os.path.exists('no-die-please')
41
 
        assert os.path.exists('no-die-please/child')
42
 
 
43
 
    def test_iter_deletable(self):
44
 
        """Files are selected for deletion appropriately"""
45
 
        os.mkdir('branch')
46
 
        tree = BzrDir.create_standalone_workingtree('branch')
47
 
        f = file('branch/.bzrignore', 'wb')
48
 
        try:
49
 
            f.write('*~\n*.pyc\n.bzrignore\n')
50
 
        finally:
51
 
            f.close()
52
 
        file('branch/file.BASE', 'wb').write('contents')
53
 
        tree.lock_write()
54
 
        try:
55
 
            self.assertEqual(len(list(iter_deletables(tree, unknown=True))), 1)
56
 
            file('branch/file', 'wb').write('contents')
57
 
            file('branch/file~', 'wb').write('contents')
58
 
            file('branch/file.pyc', 'wb').write('contents')
59
 
 
60
 
            dels = sorted([r for a,r in iter_deletables(tree, unknown=True)])
61
 
            assert sorted(['file', 'file.BASE']) == dels
62
 
 
63
 
            dels = [r for a,r in iter_deletables(tree, detritus=True)]
64
 
            assert sorted(['file~', 'file.BASE']) == dels
65
 
 
66
 
            dels = [r for a,r in iter_deletables(tree, ignored=True)]
67
 
            assert sorted(['file~', 'file.pyc', '.bzrignore']) == dels
68
 
 
69
 
            dels = [r for a,r in iter_deletables(tree, unknown=False)]
70
 
            assert [] == dels
71
 
        finally:
72
 
            tree.unlock()
73
 
 
74
 
def test_suite():
75
 
    return makeSuite(TestCleanTree)