/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_cleanup.py

  • Committer: Andrew Bennetts
  • Date: 2009-09-23 06:31:48 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-20090923063148-hu5061v0yk0ebn11
More tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
        self.assertLogContains('Cleanup failed:.*failing_cleanup goes boom')
78
78
 
79
79
    def test_cleanup_error_debug_flag(self):
80
 
        """The -Dcleanup debug flag causes cleanup errors to be propagated."""
 
80
        """The -Dcleanup debug flag causes cleanup errors to be reported to the
 
81
        user.
 
82
        """
81
83
        log = StringIO()
82
84
        trace.push_log_file(log)
83
85
        debug.debug_flags.add('cleanup')
85
87
        self.assertContainsRe(
86
88
            log.getvalue(),
87
89
            "bzr: warning: Cleanup failed:.*failing_cleanup goes boom")
88
 
        
89
90
 
90
91
    def test_prior_error_cleanup_succeeds(self):
91
92
        """Calling run_cleanup from a finally block will not interfere with an
183
184
        gone wrong), the first error is propagated, and subsequent errors are
184
185
        logged.
185
186
        """
186
 
        class ErrorA(Exception): pass
187
 
        class ErrorB(Exception): pass
188
 
        def raise_a():
189
 
            raise ErrorA()
190
 
        def raise_b():
191
 
            raise ErrorB()
 
187
        cleanups = self.make_two_failing_cleanup_funcs()
192
188
        self.assertRaises(ErrorA, do_with_cleanups, self.trivial_func,
193
 
            [raise_a, raise_b])
 
189
            cleanups)
194
190
        self.assertLogContains('Cleanup failed:.*ErrorB')
195
191
        log = self._get_log(keep_log_file=True)
196
192
        self.assertFalse('ErrorA' in log)
197
193
 
 
194
    def make_two_failing_cleanup_funcs(self):
 
195
        def raise_a():
 
196
            raise ErrorA('Error A')
 
197
        def raise_b():
 
198
            raise ErrorB('Error B')
 
199
        return [raise_a, raise_b]
 
200
 
 
201
    def test_multiple_cleanup_failures_debug_flag(self):
 
202
        log = StringIO()
 
203
        trace.push_log_file(log)
 
204
        debug.debug_flags.add('cleanup')
 
205
        cleanups = self.make_two_failing_cleanup_funcs()
 
206
        self.assertRaises(ErrorA, do_with_cleanups, self.trivial_func, cleanups)
 
207
        self.assertContainsRe(
 
208
            log.getvalue(), "bzr: warning: Cleanup failed:.*Error B\n")
 
209
        self.assertEqual(1, log.getvalue().count('bzr: warning:'),
 
210
                log.getvalue())
 
211
 
 
212
    def test_func_and_cleanup_errors_debug_flag(self):
 
213
        log = StringIO()
 
214
        trace.push_log_file(log)
 
215
        debug.debug_flags.add('cleanup')
 
216
        cleanups = self.make_two_failing_cleanup_funcs()
 
217
        self.assertRaises(ZeroDivisionError, do_with_cleanups,
 
218
            self.failing_func, cleanups)
 
219
        self.assertContainsRe(
 
220
            log.getvalue(), "bzr: warning: Cleanup failed:.*Error A\n")
 
221
        self.assertContainsRe(
 
222
            log.getvalue(), "bzr: warning: Cleanup failed:.*Error B\n")
 
223
        self.assertEqual(2, log.getvalue().count('bzr: warning:'))
 
224
 
198
225
    def test_func_may_mutate_cleanups(self):
199
226
        """The main func may mutate the cleanups before it returns.
200
227
        
212
239
        self.assertEqual('result', result)
213
240
        self.assertEqual(
214
241
            ['func_that_adds_cleanups', 'no_op_cleanup'], self.call_log)
 
242
 
 
243
    def test_cleanup_error_debug_flag(self):
 
244
        """The -Dcleanup debug flag causes cleanup errors to be reported to the
 
245
        user.
 
246
        """
 
247
        log = StringIO()
 
248
        trace.push_log_file(log)
 
249
        debug.debug_flags.add('cleanup')
 
250
        self.assertRaises(ZeroDivisionError, do_with_cleanups,
 
251
            self.failing_func, [self.failing_cleanup])
 
252
        self.assertContainsRe(
 
253
            log.getvalue(),
 
254
            "bzr: warning: Cleanup failed:.*failing_cleanup goes boom")
 
255
        self.assertEqual(1, log.getvalue().count('bzr: warning:'))
 
256
 
 
257
 
 
258
class ErrorA(Exception): pass
 
259
class ErrorB(Exception): pass