예제 #1
0
    def test_cleanup_with_args_kwargs(self):
        def func_taking_args_kwargs(*args, **kwargs):
            self.call_log.append(('func', args, kwargs))

        _run_cleanup(func_taking_args_kwargs, 'an arg', kwarg='foo')
        self.assertEqual([('func', ('an arg', ), {
            'kwarg': 'foo'
        })], self.call_log)
예제 #2
0
 def test_cleanup_error_debug_flag(self):
     """The -Dcleanup debug flag causes cleanup errors to be reported to the
     user.
     """
     log = StringIO()
     trace.push_log_file(log)
     debug.debug_flags.add('cleanup')
     self.assertFalse(_run_cleanup(self.failing_cleanup))
     self.assertContainsRe(
         log.getvalue(),
         "bzr: warning: Cleanup failed:.*failing_cleanup goes boom")
예제 #3
0
 def test_cleanup_error_debug_flag(self):
     """The -Dcleanup debug flag causes cleanup errors to be reported to the
     user.
     """
     log = StringIO()
     trace.push_log_file(log)
     debug.debug_flags.add('cleanup')
     self.assertFalse(_run_cleanup(self.failing_cleanup))
     self.assertContainsRe(
         log.getvalue(),
         "bzr: warning: Cleanup failed:.*failing_cleanup goes boom")
예제 #4
0
    def test_cleanup_error(self):
        """An error from the cleanup function is logged by _run_cleanup, but not
        propagated.

        This is there's no way for _run_cleanup to know if there's an existing
        exception in this situation::
            try:
              some_func()
            finally:
              _run_cleanup(cleanup_func)
        So, the best _run_cleanup can do is always log errors but never raise
        them.
        """
        self.assertFalse(_run_cleanup(self.failing_cleanup))
        self.assertLogContains('Cleanup failed:.*failing_cleanup goes boom')
예제 #5
0
    def test_cleanup_error(self):
        """An error from the cleanup function is logged by _run_cleanup, but not
        propagated.

        This is there's no way for _run_cleanup to know if there's an existing
        exception in this situation::
            try:
              some_func()
            finally:
              _run_cleanup(cleanup_func)
        So, the best _run_cleanup can do is always log errors but never raise
        them.
        """
        self.assertFalse(_run_cleanup(self.failing_cleanup))
        self.assertLogContains('Cleanup failed:.*failing_cleanup goes boom')
예제 #6
0
 def failing_operation():
     try:
         1/0
     finally:
         _run_cleanup(self.no_op_cleanup)
예제 #7
0
 def test_cleanup_with_args_kwargs(self):
     def func_taking_args_kwargs(*args, **kwargs):
         self.call_log.append(('func', args, kwargs))
     _run_cleanup(func_taking_args_kwargs, 'an arg', kwarg='foo')
     self.assertEqual(
         [('func', ('an arg',), {'kwarg': 'foo'})], self.call_log)
예제 #8
0
 def test_no_errors(self):
     """The function passed to _run_cleanup is run."""
     self.assertTrue(_run_cleanup(self.no_op_cleanup))
     self.assertEqual(['no_op_cleanup'], self.call_log)
예제 #9
0
 def failing_operation():
     try:
         1 / 0
     finally:
         _run_cleanup(self.no_op_cleanup)
예제 #10
0
 def test_no_errors(self):
     """The function passed to _run_cleanup is run."""
     self.assertTrue(_run_cleanup(self.no_op_cleanup))
     self.assertEqual(['no_op_cleanup'], self.call_log)