<s> import logbook <EOL> from . utils import capturing_stderr_context <EOL> def test_null_handler ( activation_strategy , logger ) : <EOL> with capturing_stderr_context ( ) as captured : <EOL> with activation_strategy ( logbook . NullHandler ( ) ) : <EOL> with activation_strategy ( logbook . TestHandler ( level = '<STR_LIT>' ) ) as handler : <EOL> logger . error ( '<STR_LIT>' ) <EOL> logger . warn ( '<STR_LIT>' ) <EOL> assert captured . getvalue ( ) == '<STR_LIT>' <EOL> assert ( not handler . has_warning ( '<STR_LIT>' ) ) <EOL> assert handler . has_error ( '<STR_LIT>' ) <EOL> def test_blackhole_setting ( activation_strategy ) : <EOL> null_handler = logbook . NullHandler ( ) <EOL> heavy_init = logbook . LogRecord . heavy_init <EOL> with activation_strategy ( null_handler ) : <EOL> def new_heavy_init ( self ) : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> logbook . LogRecord . heavy_init = new_heavy_init <EOL> try : <EOL> with activation_strategy ( null_handler ) : <EOL> logbook . warn ( '<STR_LIT>' ) <EOL> finally : <EOL> logbook . LogRecord . heavy_init = heavy_init <EOL> null_handler . bubble = True <EOL> with capturing_stderr_context ( ) as captured : <EOL> logbook . warning ( '<STR_LIT>' ) <EOL> assert captured . getvalue ( ) != '<STR_LIT>' <EOL> def test_null_handler_filtering ( activation_strategy ) : <EOL> logger1 = logbook . Logger ( "<STR_LIT:1>" ) <EOL> logger2 = logbook . Logger ( "<STR_LIT:2>" ) <EOL> outer = logbook . TestHandler ( ) <EOL> inner = logbook . NullHandler ( ) <EOL> inner . filter = lambda record , handler : record . dispatcher is logger1 <EOL> with activation_strategy ( outer ) : <EOL> with activation_strategy ( inner ) : <EOL> logger1 . warn ( "<STR_LIT:1>" ) <EOL> logger2 . warn ( "<STR_LIT:2>" ) <EOL> assert outer . has_warning ( '<STR_LIT:2>' , channel = '<STR_LIT:2>' ) <EOL> assert ( not outer . has_warning ( '<STR_LIT:1>' , channel = '<STR_LIT:1>' ) ) </s>
