<s> import optparse <EOL> import os <EOL> import unittest <EOL> from pymon import meta <EOL> from pymon . testing import result <EOL> class CustomTestRunner ( unittest . TextTestRunner ) : <EOL> """<STR_LIT>""" <EOL> def _makeResult ( self ) : <EOL> return result . CustomTestResult ( <EOL> self . stream , self . descriptions , self . verbosity ) <EOL> def discover ( loader , top_level_directory ) : <EOL> names = [ ] <EOL> def _path_to_module ( path ) : <EOL> path = path . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return path . replace ( "<STR_LIT:/>" , "<STR_LIT:.>" ) <EOL> for dirpath , dirnames , filenames in os . walk ( top_level_directory ) : <EOL> modules = [ <EOL> _path_to_module ( os . path . join ( dirpath , x ) ) for x in filenames <EOL> if x . startswith ( "<STR_LIT>" ) and x . endswith ( "<STR_LIT>" ) ] <EOL> if not modules : <EOL> continue <EOL> names . extend ( modules ) <EOL> return loader . loadTestsFromNames ( names ) <EOL> def get_suite ( loader , top_level_directory , options ) : <EOL> print options . test_specific <EOL> if options . test_specific : <EOL> suite = loader . loadTestsFromName ( options . test_specific ) <EOL> elif hasattr ( loader , "<STR_LIT>" ) : <EOL> suite = loader . discover ( top_level_directory ) <EOL> else : <EOL> suite = discover ( loader , top_level_directory ) <EOL> return suite <EOL> def get_runner ( ) : <EOL> try : <EOL> runner = unittest . TextTestRunner ( <EOL> verbosity = <NUM_LIT:2> , resultclass = result . CustomTestResult ) <EOL> except TypeError : <EOL> runner = CustomTestRunner ( verbosity = <NUM_LIT:2> ) <EOL> return runner <EOL> def run_tests ( options ) : <EOL> loader = unittest . TestLoader ( ) <EOL> suite = get_suite ( loader , meta . library_name , options ) <EOL> get_runner ( ) . run ( suite ) <EOL> def main ( ) : <EOL> parser = optparse . OptionParser ( ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> run_tests ( options ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
