419
419
self.assertEquals(len(self.out), 0)
422
def test_startLoggingTwice(self):
424
There are some obscure error conditions that can occur when logging is
425
started twice. See http://twistedmatrix.com/trac/ticket/3289 for more
428
# The bug is particular to the way that the t.p.log 'global' function
429
# handle stdout. If we use our own stream, the error doesn't occur. If
430
# we use our own LogPublisher, the error doesn't occur.
431
sys.stdout = StringIO()
432
self.addCleanup(setattr, sys, 'stdout', sys.__stdout__)
434
def showError(eventDict):
435
if eventDict['isError']:
436
sys.__stdout__.write(eventDict['failure'].getTraceback())
438
log.addObserver(showError)
439
self.addCleanup(log.removeObserver, showError)
440
observer = log.startLogging(sys.stdout)
441
self.addCleanup(observer.stop)
442
# At this point, we expect that sys.stdout is a StdioOnnaStick object.
443
self.assertIsInstance(sys.stdout, log.StdioOnnaStick)
444
fakeStdout = sys.stdout
445
observer = log.startLogging(sys.stdout)
446
self.assertIdentical(sys.stdout, fakeStdout)
422
449
class PythonLoggingObserverTestCase(unittest.TestCase):
424
451
Test the bridge with python logging module.