<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import types <EOL> from . import loader , runner <EOL> from . signals import installHandler <EOL> __unittest = True <EOL> FAILFAST = "<STR_LIT>" <EOL> CATCHBREAK = "<STR_LIT>" <EOL> BUFFEROUTPUT = "<STR_LIT>" <EOL> USAGE_AS_MAIN = """<STR_LIT>""" <EOL> USAGE_FROM_MODULE = """<STR_LIT>""" <EOL> class TestProgram ( object ) : <EOL> """<STR_LIT>""" <EOL> USAGE = USAGE_FROM_MODULE <EOL> failfast = catchbreak = buffer = progName = None <EOL> def __init__ ( self , module = '<STR_LIT:__main__>' , defaultTest = None , argv = None , <EOL> testRunner = None , testLoader = loader . defaultTestLoader , <EOL> exit = True , verbosity = <NUM_LIT:1> , failfast = None , catchbreak = None , <EOL> buffer = None ) : <EOL> if isinstance ( module , str ) : <EOL> self . module = __import__ ( module ) <EOL> for part in module . split ( '<STR_LIT:.>' ) [ <NUM_LIT:1> : ] : <EOL> self . module = getattr ( self . module , part ) <EOL> else : <EOL> self . module = module <EOL> if argv is None : <EOL> argv = sys . argv <EOL> self . exit = exit <EOL> self . failfast = failfast <EOL> self . catchbreak = catchbreak <EOL> self . verbosity = verbosity <EOL> self . buffer = buffer <EOL> self . defaultTest = defaultTest <EOL> self . testRunner = testRunner <EOL> self . testLoader = testLoader <EOL> self . progName = os . path . basename ( argv [ <NUM_LIT:0> ] ) <EOL> self . parseArgs ( argv ) <EOL> self . runTests ( ) <EOL> def usageExit ( self , msg = None ) : <EOL> if msg : <EOL> print ( msg ) <EOL> usage = { '<STR_LIT>' : self . progName , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> if self . failfast != False : <EOL> usage [ '<STR_LIT>' ] = FAILFAST <EOL> if self . catchbreak != False : <EOL> usage [ '<STR_LIT>' ] = CATCHBREAK <EOL> if self . buffer != False : <EOL> usage [ '<STR_LIT>' ] = BUFFEROUTPUT <EOL> print ( self . USAGE % usage ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> def parseArgs ( self , argv ) : <EOL> if len ( argv ) > <NUM_LIT:1> and argv [ <NUM_LIT:1> ] . lower ( ) == '<STR_LIT>' : <EOL> self . _do_discovery ( argv [ <NUM_LIT:2> : ] ) <EOL> return <EOL> import getopt <EOL> long_opts = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> try : <EOL> options , args = getopt . getopt ( argv [ <NUM_LIT:1> : ] , '<STR_LIT>' , long_opts ) <EOL> for opt , value in options : <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . usageExit ( ) <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . verbosity = <NUM_LIT:0> <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . verbosity = <NUM_LIT:2> <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if self . failfast is None : <EOL> self . failfast = True <EOL> if opt in ( '<STR_LIT:-c>' , '<STR_LIT>' ) : <EOL> if self . catchbreak is None : <EOL> self . catchbreak = True <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if self . buffer is None : <EOL> self . buffer = True <EOL> if len ( args ) == <NUM_LIT:0> and self . defaultTest is None : <EOL> self . testNames = None <EOL> elif len ( args ) > <NUM_LIT:0> : <EOL> self . testNames = args <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> self . module = None <EOL> else : <EOL> self . testNames = ( self . defaultTest , ) <EOL> self . createTests ( ) <EOL> except getopt . error as msg : <EOL> self . usageExit ( msg ) <EOL> def createTests ( self ) : <EOL> if self . testNames is None : <EOL> self . test = self . testLoader . loadTestsFromModule ( self . module ) <EOL> else : <EOL> self . test = self . testLoader . loadTestsFromNames ( self . testNames , <EOL> self . module ) <EOL> def _do_discovery ( self , argv , Loader = loader . TestLoader ) : <EOL> self . progName = '<STR_LIT>' % self . progName <EOL> import optparse <EOL> parser = optparse . OptionParser ( ) <EOL> parser . prog = self . progName <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , default = False , <EOL> help = '<STR_LIT>' , action = '<STR_LIT:store_true>' ) <EOL> if self . failfast != False : <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , default = False , <EOL> help = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' ) <EOL> if self . catchbreak != False : <EOL> parser . add_option ( '<STR_LIT:-c>' , '<STR_LIT>' , dest = '<STR_LIT>' , default = False , <EOL> help = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' ) <EOL> if self . buffer != False : <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , default = False , <EOL> help = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:start>' , default = '<STR_LIT:.>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , default = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , default = None , <EOL> help = '<STR_LIT>' ) <EOL> options , args = parser . parse_args ( argv ) <EOL> if len ( args ) > <NUM_LIT:3> : <EOL> self . usageExit ( ) <EOL> for name , value in zip ( ( '<STR_LIT:start>' , '<STR_LIT>' , '<STR_LIT>' ) , args ) : <EOL> setattr ( options , name , value ) <EOL> if self . failfast is None : <EOL> self . failfast = options . failfast <EOL> if self . catchbreak is None : <EOL> self . catchbreak = options . catchbreak <EOL> if self . buffer is None : <EOL> self . buffer = options . buffer <EOL> if options . verbose : <EOL> self . verbosity = <NUM_LIT:2> <EOL> start_dir = options . start <EOL> pattern = options . pattern <EOL> top_level_dir = options . top <EOL> loader = Loader ( ) <EOL> self . test = loader . discover ( start_dir , pattern , top_level_dir ) <EOL> def runTests ( self ) : <EOL> if self . catchbreak : <EOL> installHandler ( ) <EOL> if self . testRunner is None : <EOL> self . testRunner = runner . TextTestRunner <EOL> if isinstance ( self . testRunner , type ) : <EOL> try : <EOL> testRunner = self . testRunner ( verbosity = self . verbosity , <EOL> failfast = self . failfast , <EOL> buffer = self . buffer ) <EOL> except TypeError : <EOL> testRunner = self . testRunner ( ) <EOL> else : <EOL> testRunner = self . testRunner <EOL> self . result = testRunner . run ( self . test ) <EOL> if self . exit : <EOL> sys . exit ( not self . result . wasSuccessful ( ) ) <EOL> main = TestProgram <EOL> def main_ ( ) : <EOL> TestProgram . USAGE = USAGE_AS_MAIN <EOL> main ( module = None ) </s>
