<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import tempfile <EOL> import fixtures <EOL> import testtools <EOL> _TRUE_VALUES = ( '<STR_LIT:True>' , '<STR_LIT:true>' , '<STR_LIT:1>' , '<STR_LIT:yes>' ) <EOL> _LOG_FORMAT = "<STR_LIT>" <EOL> class BaseTestCase ( testtools . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( BaseTestCase , self ) . setUp ( ) <EOL> self . _set_timeout ( ) <EOL> self . _fake_output ( ) <EOL> self . _fake_logs ( ) <EOL> self . useFixture ( fixtures . NestedTempfile ( ) ) <EOL> self . useFixture ( fixtures . TempHomeDir ( ) ) <EOL> self . tempdirs = [ ] <EOL> def _set_timeout ( self ) : <EOL> test_timeout = os . environ . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> try : <EOL> test_timeout = int ( test_timeout ) <EOL> except ValueError : <EOL> test_timeout = <NUM_LIT:0> <EOL> if test_timeout > <NUM_LIT:0> : <EOL> self . useFixture ( fixtures . Timeout ( test_timeout , gentle = True ) ) <EOL> def _fake_output ( self ) : <EOL> if os . environ . get ( '<STR_LIT>' ) in _TRUE_VALUES : <EOL> stdout = self . useFixture ( fixtures . StringStream ( '<STR_LIT>' ) ) . stream <EOL> self . useFixture ( fixtures . MonkeyPatch ( '<STR_LIT>' , stdout ) ) <EOL> if os . environ . get ( '<STR_LIT>' ) in _TRUE_VALUES : <EOL> stderr = self . useFixture ( fixtures . StringStream ( '<STR_LIT>' ) ) . stream <EOL> self . useFixture ( fixtures . MonkeyPatch ( '<STR_LIT>' , stderr ) ) <EOL> def _fake_logs ( self ) : <EOL> if os . environ . get ( '<STR_LIT>' ) in _TRUE_VALUES : <EOL> level = logging . DEBUG <EOL> else : <EOL> level = logging . INFO <EOL> capture_logs = os . environ . get ( '<STR_LIT>' ) in _TRUE_VALUES <EOL> if capture_logs : <EOL> self . useFixture ( <EOL> fixtures . FakeLogger ( <EOL> format = _LOG_FORMAT , <EOL> level = level , <EOL> nuke_handlers = capture_logs , <EOL> ) <EOL> ) <EOL> else : <EOL> logging . basicConfig ( format = _LOG_FORMAT , level = level ) <EOL> def create_tempfiles ( self , files , ext = '<STR_LIT>' ) : <EOL> tempfiles = [ ] <EOL> for ( basename , contents ) in files : <EOL> if not os . path . isabs ( basename ) : <EOL> ( fd , path ) = tempfile . mkstemp ( prefix = basename , suffix = ext ) <EOL> else : <EOL> path = basename + ext <EOL> fd = os . open ( path , os . O_CREAT | os . O_WRONLY ) <EOL> tempfiles . append ( path ) <EOL> try : <EOL> os . write ( fd , contents ) <EOL> finally : <EOL> os . close ( fd ) <EOL> return tempfiles </s>
