42
class LoggingSupportTests(TestCase):
44
run_tests_with = AsynchronousDeferredRunTest
47
super(LoggingSupportTests, self).setUp()
48
self.temp_dir = tempfile.mkdtemp()
49
self.addCleanup(shutil.rmtree, self.temp_dir)
50
config.push('testing', dedent("""
55
globalErrorUtility.configure()
56
self.log_stream = StringIO.StringIO()
57
self.logger = logging.getLogger('test')
58
self.logger.setLevel(logging.DEBUG)
59
self.logger.addHandler(logging.StreamHandler(self.log_stream))
60
self.observer = OOPSLoggingObserver('test')
64
globalErrorUtility.configure()
65
super(LoggingSupportTests, self).tearDown()
67
def assertLogMatches(self, pattern):
68
"""Assert that the messages logged by self.logger matches a regexp."""
69
log_text = self.log_stream.getvalue()
70
self.failUnless(re.match(pattern, log_text, re.M))
73
def test_oops_reporting(self):
74
# Calling log.err should result in an OOPS being logged.
75
log.addObserver(self.observer.emit)
76
self.addCleanup(log.removeObserver, self.observer.emit)
77
error_time = datetime.datetime.now(UTC)
78
fail = makeFailure(RuntimeError)
79
log.err(fail, error_time=error_time)
80
flush_logged_errors(RuntimeError)
81
oops = self.oopses[-1]
82
self.assertEqual(oops['type'], 'RuntimeError')
83
self.assertLogMatches('^Logged OOPS id.*')
86
41
class TestLaunchpadLogFile(TestCase):