#NEWLINE# def testFmtdLog( self ) : #NEWLINE# #INDENT# tmpDir = tempfile . mkdtemp ( ) #NEWLINE# try : #NEWLINE# #INDENT# origHandlers = log . fmtLogger . handlers [ : ] #NEWLINE# logPath = os . path . join ( tmpDir , 'log.xml' ) #NEWLINE# log . openFormattedLog ( logPath ) #NEWLINE# log . pushLogDescriptor ( 'foo' ) #NEWLINE# self . captureOutput ( log . debug , 'debug message' ) #NEWLINE# log . pushLogDescriptor ( 'bar' ) #NEWLINE# self . captureOutput ( log . info , 'info message' ) #NEWLINE# log . popLogDescriptor ( ) #NEWLINE# self . captureOutput ( log . warning , 'warning message' ) #NEWLINE# log . popLogDescriptor ( ) #NEWLINE# self . captureOutput ( log . error , 'error message' ) #NEWLINE# log . pushLogDescriptor ( 'bad_descriptor' ) #NEWLINE# hdlr = [ x for x in log . fmtLogger . handlers if ( x not in origHandlers ) ] [ 0 ] #NEWLINE# hdlr . close ( ) #NEWLINE# log . fmtLogger . handlers . remove ( hdlr ) #NEWLINE# data = open ( logPath ) . read ( ) . splitlines ( ) #NEWLINE# self . assertFalse ( ( 'bad_descriptor' in data [ ( - 2 ) ] ) , "descriptor stack wasn't cleared on log close." ) #NEWLINE# self . assertEquals ( data [ ( - 1 ) ] , '</log>' ) #NEWLINE# self . assertEquals ( len ( data ) , 9 ) #NEWLINE# self . assertSubstring ( '<level>DEBUG</level>' , data [ 2 ] ) #NEWLINE# self . assertSubstring ( '<message>begin log</message>' , data [ 2 ] ) #NEWLINE# self . assertSubstring ( '<level>DEBUG</level>' , data [ ( - 2 ) ] ) #NEWLINE# self . assertSubstring ( '<message>end log</message>' , data [ ( - 2 ) ] ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# util . rmtree ( tmpDir )