<s> """<STR_LIT>""" <EOL> import contextlib <EOL> from nose . tools import assert_equal <EOL> from sklearn . base import BaseEstimator <EOL> from nilearn . _utils . logger import log <EOL> @ contextlib . contextmanager <EOL> def capture_output ( ) : <EOL> import sys <EOL> from nilearn . _utils . compat import StringIO <EOL> oldout , olderr = sys . stdout , sys . stderr <EOL> try : <EOL> out = [ StringIO ( ) , StringIO ( ) ] <EOL> sys . stdout , sys . stderr = out <EOL> yield out <EOL> finally : <EOL> sys . stdout , sys . stderr = oldout , olderr <EOL> out [ <NUM_LIT:0> ] = out [ <NUM_LIT:0> ] . getvalue ( ) <EOL> out [ <NUM_LIT:1> ] = out [ <NUM_LIT:1> ] . getvalue ( ) <EOL> def run ( ) : <EOL> log ( "<STR_LIT>" ) <EOL> def other_run ( ) : <EOL> log ( "<STR_LIT>" , stack_level = <NUM_LIT:100> ) <EOL> class Run3 ( object ) : <EOL> def run3 ( self ) : <EOL> log ( "<STR_LIT>" ) <EOL> run ( ) <EOL> class Run2 ( BaseEstimator ) : <EOL> def run2 ( self ) : <EOL> log ( "<STR_LIT>" ) <EOL> t = Run ( ) <EOL> t . run ( ) <EOL> class Run ( BaseEstimator ) : <EOL> def run ( self ) : <EOL> log ( "<STR_LIT>" ) <EOL> run ( ) <EOL> def test_log ( ) : <EOL> with capture_output ( ) as out : <EOL> t = Run3 ( ) <EOL> t . run3 ( ) <EOL> assert_equal ( out [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> with capture_output ( ) as out : <EOL> t = Run2 ( ) <EOL> t . run2 ( ) <EOL> assert_equal ( out [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> with capture_output ( ) as out : <EOL> t = Run ( ) <EOL> t . run ( ) <EOL> assert_equal ( out [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" ) <EOL> with capture_output ( ) as out : <EOL> run ( ) <EOL> assert_equal ( out [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> with capture_output ( ) as out : <EOL> other_run ( ) <EOL> assert_equal ( out [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> with capture_output ( ) as out : <EOL> log ( "<STR_LIT>" ) <EOL> assert_equal ( out [ <NUM_LIT:0> ] , "<STR_LIT>" ) </s>
