#NEWLINE# def run_tests( tests , test_input , timeout = 60 , waittime = 0.1 ) : #NEWLINE# #INDENT# '\n    Runs all the tests given by directly executing them. If they return\n    with a non-zero exit code, it adds them to the dictionary returned.\n\n    Keyword arguments:\n        tests -- a list of paths to executable test files\n        test_input -- dictionary of key value pairs to provide to the test\n        timeout -- how many seconds to let the tests run\n        waittime -- how many seconds to wait in between test polls\n    ' #NEWLINE# failed_tests = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for t in tests : #NEWLINE# #INDENT# log . debug ( 'Executing test %s' , t ) #NEWLINE# p = subprocess . Popen ( t , stdin = subprocess . PIPE ) #NEWLINE# to_send = json . dumps ( test_input ) #NEWLINE# log . debug ( 'Sending test_input to test: %s' , to_send ) #NEWLINE# try : #NEWLINE# #INDENT# p . stdin . write ( ( to_send + os . linesep ) ) #NEWLINE# p . stdin . close ( ) #NEWLINE# countdown = int ( ( timeout / waittime ) ) #NEWLINE# while countdown : #NEWLINE# #INDENT# retcode = p . poll ( ) #NEWLINE# if ( retcode is not None ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# time . sleep ( waittime ) #NEWLINE# countdown = ( countdown - 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# p . terminate ( ) #NEWLINE# log . warn ( 'Test %s timed out' , t ) #NEWLINE# p . wait ( ) #NEWLINE# retcode = 'TIMEOUT' #NEWLINE# #UNINDENT# #UNINDENT# except IOError as e : #NEWLINE# #INDENT# log . warn ( 'Caught IOError from process: %s' , e ) #NEWLINE# retcode = e #NEWLINE# #UNINDENT# if retcode : #NEWLINE# #INDENT# failed_tests [ t ] = retcode #NEWLINE# log . error ( 'Test %s failed with code %s' , t , retcode ) #NEWLINE# #UNINDENT# #UNINDENT# return failed_tests