~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_clean_tree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-13 06:08:53 UTC
  • mfrom: (4737.1.1 merge-2.0-into-devel)
  • Revision ID: pqm@pqm.ubuntu.com-20091013060853-erk2aaj80fnkrv25
(andrew) Merge lp:bzr/2.0 into lp:bzr, including fixes for #322807,
        #389413, #402623 and documentation improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
 
1
# Copyright (C) 2005, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
import errno
19
18
import os
20
 
import shutil
21
 
import sys
 
19
from StringIO import StringIO
22
20
 
23
 
from bzrlib import tests, ui
24
 
from bzrlib.controldir import (
25
 
    ControlDir,
 
21
from bzrlib.bzrdir import (
 
22
    BzrDir,
26
23
    )
27
24
from bzrlib.clean_tree import (
28
25
    clean_tree,
42
39
        if has_symlinks() is False:
43
40
            return
44
41
        os.mkdir('branch')
45
 
        ControlDir.create_standalone_workingtree('branch')
 
42
        BzrDir.create_standalone_workingtree('branch')
46
43
        os.symlink(os.path.realpath('no-die-please'), 'branch/die-please')
47
44
        os.mkdir('no-die-please')
48
 
        self.assertPathExists('branch/die-please')
 
45
        self.failUnlessExists('branch/die-please')
49
46
        os.mkdir('no-die-please/child')
50
47
 
51
48
        clean_tree('branch', unknown=True, no_prompt=True)
52
 
        self.assertPathExists('no-die-please')
53
 
        self.assertPathExists('no-die-please/child')
 
49
        self.failUnlessExists('no-die-please')
 
50
        self.failUnlessExists('no-die-please/child')
54
51
 
55
52
    def test_iter_deletable(self):
56
53
        """Files are selected for deletion appropriately"""
57
54
        os.mkdir('branch')
58
 
        tree = ControlDir.create_standalone_workingtree('branch')
 
55
        tree = BzrDir.create_standalone_workingtree('branch')
59
56
        transport = tree.bzrdir.root_transport
60
57
        transport.put_bytes('.bzrignore', '*~\n*.pyc\n.bzrignore\n')
61
58
        transport.put_bytes('file.BASE', 'contents')
79
76
            self.assertEqual([], dels)
80
77
        finally:
81
78
            tree.unlock()
82
 
 
83
 
    def test_delete_items_warnings(self):
84
 
        """Ensure delete_items issues warnings on EACCES. (bug #430785)
85
 
        """
86
 
        def _dummy_unlink(path):
87
 
            """unlink() files other than files named '0foo'.
88
 
            """
89
 
            if path.endswith('0foo'):
90
 
                # Simulate 'permission denied' error.
91
 
                # This should show up as a warning for the
92
 
                # user.
93
 
                e = OSError()
94
 
                e.errno = errno.EACCES
95
 
                raise e
96
 
 
97
 
        def _dummy_rmtree(path, ignore_errors=False, onerror=None):
98
 
            """Call user supplied error handler onerror.
99
 
            """
100
 
            # Indicate failure in removing 'path' if path is subdir0
101
 
            # We later check to ensure that this is indicated
102
 
            # to the user as a warning. We raise OSError to construct
103
 
            # proper excinfo that needs to be passed to onerror
104
 
            try:
105
 
                raise OSError
106
 
            except OSError, e:
107
 
                e.errno = errno.EACCES
108
 
                excinfo = sys.exc_info()
109
 
                function = os.remove
110
 
                if 'subdir0' not in path:
111
 
                    # onerror should show warning only for os.remove
112
 
                    # error. For any other failures the error should
113
 
                    # be shown to the user.
114
 
                    function = os.listdir
115
 
                onerror(function=function,
116
 
                    path=path, excinfo=excinfo)
117
 
 
118
 
        self.overrideAttr(os, 'unlink', _dummy_unlink)
119
 
        self.overrideAttr(shutil, 'rmtree', _dummy_rmtree)
120
 
        stdout = tests.StringIOWrapper()
121
 
        stderr = tests.StringIOWrapper()
122
 
        ui.ui_factory = tests.TestUIFactory(stdout=stdout, stderr=stderr)
123
 
 
124
 
        ControlDir.create_standalone_workingtree('.')
125
 
        self.build_tree(['0foo', '1bar', '2baz', 'subdir0/'])
126
 
        clean_tree('.', unknown=True, no_prompt=True)
127
 
        self.assertContainsRe(stderr.getvalue(),
128
 
            'bzr: warning: unable to remove.*0foo')
129
 
        self.assertContainsRe(stderr.getvalue(),
130
 
            'bzr: warning: unable to remove.*subdir0')
131
 
 
132
 
        # Ensure that error other than EACCES during os.remove are
133
 
        # not turned into warnings.
134
 
        self.build_tree(['subdir1/'])
135
 
        self.assertRaises(OSError, clean_tree, '.',
136
 
            unknown=True, no_prompt=True)
137