Esempio n. 1
0
    def test_push_log_file(self):
        """Can push and pop log file, and this catches mutter messages.

        This is primarily for use in the test framework.
        """
        tmp1 = tempfile.NamedTemporaryFile()
        tmp2 = tempfile.NamedTemporaryFile()
        try:
            memento1 = push_log_file(tmp1)
            mutter("comment to file1")
            try:
                memento2 = push_log_file(tmp2)
                try:
                    mutter("comment to file2")
                finally:
                    pop_log_file(memento2)
                mutter("again to file1")
            finally:
                pop_log_file(memento1)
            # the files were opened in binary mode, so should have exactly
            # these bytes.  and removing the file as the log target should
            # have caused them to be flushed out.  need to match using regexps
            # as there's a timestamp at the front.
            tmp1.seek(0)
            self.assertContainsRe(
                tmp1.read(),
                r"\d+\.\d+  comment to file1\n\d+\.\d+  again to file1\n")
            tmp2.seek(0)
            self.assertContainsRe(tmp2.read(), r"\d+\.\d+  comment to file2\n")
        finally:
            tmp1.close()
            tmp2.close()
Esempio n. 2
0
    def test_push_log_file(self):
        """Can push and pop log file, and this catches mutter messages.

        This is primarily for use in the test framework. 
        """
        tmp1 = tempfile.NamedTemporaryFile()
        tmp2 = tempfile.NamedTemporaryFile()
        try:
            memento1 = push_log_file(tmp1)
            mutter("comment to file1")
            try:
                memento2 = push_log_file(tmp2)
                try:
                    mutter("comment to file2")
                finally:
                    pop_log_file(memento2)
                mutter("again to file1")
            finally:
                pop_log_file(memento1)
            # the files were opened in binary mode, so should have exactly
            # these bytes.  and removing the file as the log target should
            # have caused them to be flushed out.  need to match using regexps
            # as there's a timestamp at the front.
            tmp1.seek(0)
            self.assertContainsRe(tmp1.read(),
                r"\d+\.\d+  comment to file1\n\d+\.\d+  again to file1\n")
            tmp2.seek(0)
            self.assertContainsRe(tmp2.read(),
                r"\d+\.\d+  comment to file2\n")
        finally:
            tmp1.close()
            tmp2.close()
Esempio n. 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")
Esempio n. 4
0
 def test_multiple_cleanup_failures_debug_flag(self):
     log = StringIO()
     trace.push_log_file(log)
     debug.debug_flags.add('cleanup')
     cleanups = self.make_two_failing_cleanup_funcs()
     self.assertRaises(ErrorA, _do_with_cleanups, cleanups,
         self.trivial_func)
     self.assertContainsRe(
         log.getvalue(), "bzr: warning: Cleanup failed:.*Error B\n")
     self.assertEqual(1, log.getvalue().count('bzr: warning:'),
             log.getvalue())
 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")
 def test_multiple_cleanup_failures_debug_flag(self):
     log = StringIO()
     trace.push_log_file(log)
     debug.debug_flags.add('cleanup')
     cleanups = self.make_two_failing_cleanup_funcs()
     self.assertRaises(ErrorA, _do_with_cleanups, cleanups,
                       self.trivial_func)
     self.assertContainsRe(log.getvalue(),
                           "bzr: warning: Cleanup failed:.*Error B\n")
     self.assertEqual(1,
                      log.getvalue().count('bzr: warning:'), log.getvalue())
Esempio n. 7
0
 def test_func_and_cleanup_errors_debug_flag(self):
     log = StringIO()
     trace.push_log_file(log)
     debug.debug_flags.add('cleanup')
     cleanups = self.make_two_failing_cleanup_funcs()
     self.assertRaises(ZeroDivisionError, _do_with_cleanups, cleanups,
         self.failing_func)
     self.assertContainsRe(
         log.getvalue(), "bzr: warning: Cleanup failed:.*Error A\n")
     self.assertContainsRe(
         log.getvalue(), "bzr: warning: Cleanup failed:.*Error B\n")
     self.assertEqual(2, log.getvalue().count('bzr: warning:'))
 def test_func_and_cleanup_errors_debug_flag(self):
     log = StringIO()
     trace.push_log_file(log)
     debug.debug_flags.add('cleanup')
     cleanups = self.make_two_failing_cleanup_funcs()
     self.assertRaises(ZeroDivisionError, _do_with_cleanups, cleanups,
                       self.failing_func)
     self.assertContainsRe(log.getvalue(),
                           "bzr: warning: Cleanup failed:.*Error A\n")
     self.assertContainsRe(log.getvalue(),
                           "bzr: warning: Cleanup failed:.*Error B\n")
     self.assertEqual(2, log.getvalue().count('bzr: warning:'))
Esempio n. 9
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.assertRaises(ZeroDivisionError, _do_with_cleanups,
         [(self.failing_cleanup, (), {})], self.failing_func)
     self.assertContainsRe(
         log.getvalue(),
         "bzr: warning: Cleanup failed:.*failing_cleanup goes boom")
     self.assertEqual(1, log.getvalue().count('bzr: warning:'))
Esempio n. 10
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.assertRaises(ZeroDivisionError, _do_with_cleanups,
                       [(self.failing_cleanup, (), {})], self.failing_func)
     self.assertContainsRe(
         log.getvalue(),
         "bzr: warning: Cleanup failed:.*failing_cleanup goes boom")
     self.assertEqual(1, log.getvalue().count('bzr: warning:'))