~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_cleanup.py

  • Committer: Andrew Bennetts
  • Date: 2009-09-23 06:00:51 UTC
  • mto: (4744.3.1 robust-cleanup-in-commit)
  • mto: This revision was merged to the branch mainline in revision 4775.
  • Revision ID: andrew.bennetts@canonical.com-20090923060051-xmiz3cs0x3bd124h
Add unit test for -Dcleanup behaviour.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from cStringIO import StringIO
17
18
import re
18
19
 
19
 
from bzrlib.tests import TestCase
20
20
from bzrlib.cleanup import (
21
21
    do_with_cleanups,
22
22
    run_cleanup,
23
23
    )
 
24
from bzrlib.tests import TestCase
 
25
from bzrlib import (
 
26
    debug,
 
27
    trace,
 
28
    )
24
29
 
25
30
 
26
31
class CleanupsTestCase(TestCase):
71
76
        self.assertFalse(run_cleanup(self.failing_cleanup))
72
77
        self.assertLogContains('Cleanup failed:.*failing_cleanup goes boom')
73
78
 
 
79
    def test_cleanup_error_debug_flag(self):
 
80
        """The -Dcleanup debug flag causes cleanup errors to be propagated."""
 
81
        log = StringIO()
 
82
        trace.push_log_file(log)
 
83
        debug.debug_flags.add('cleanup')
 
84
        self.assertFalse(run_cleanup(self.failing_cleanup))
 
85
        self.assertContainsRe(
 
86
            log.getvalue(),
 
87
            "bzr: warning: Cleanup failed:.*failing_cleanup goes boom")
 
88
        
 
89
 
74
90
    def test_prior_error_cleanup_succeeds(self):
75
91
        """Calling run_cleanup from a finally block will not interfere with an
76
92
        exception from the try block.