#NEWLINE# @ pytest . mark . parametrize ( 'set_root_logger_level' , [ True , False ] ) #NEWLINE# def test_basic_compat( request , set_root_logger_level ) : #NEWLINE# #INDENT# import logging #NEWLINE# from logbook.compat import redirected_logging #NEWLINE# request . addfinalizer ( functools . partial ( logging . root . setLevel , logging . root . level ) ) #NEWLINE# logging . root . setLevel ( logging . WARNING ) #NEWLINE# name = ( 'test_logbook-%d' % randrange ( ( 1 << 32 ) ) ) #NEWLINE# logger = logging . getLogger ( name ) #NEWLINE# with logbook . TestHandler ( bubble = True ) as handler : #NEWLINE# #INDENT# with capturing_stderr_context ( ) as captured : #NEWLINE# #INDENT# with redirected_logging ( set_root_logger_level ) : #NEWLINE# #INDENT# logger . debug ( 'This is from the old system' ) #NEWLINE# logger . info ( 'This is from the old system' ) #NEWLINE# logger . warn ( 'This is from the old %s' , 'system' ) #NEWLINE# logger . error ( 'This is from the old system' ) #NEWLINE# logger . critical ( 'This is from the old system' ) #NEWLINE# logger . error ( 'This is a %(what)s %(where)s' , { #NEWLINE# #INDENT# 'what' : 'mapping' , #NEWLINE# 'where' : 'test' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# assert ( ( 'WARNING: %s: This is from the old system' % name ) in captured . getvalue ( ) ) #NEWLINE# assert ( ( 'ERROR: %s: This is a mapping test' % name ) in captured . getvalue ( ) ) #NEWLINE# #UNINDENT# if set_root_logger_level : #NEWLINE# #INDENT# assert ( handler . records [ 0 ] . level == logbook . DEBUG ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert ( handler . records [ 0 ] . level == logbook . WARNING ) #NEWLINE# assert ( handler . records [ 0 ] . msg == 'This is from the old %s' )