#!/usr/local/bin/python '''This script must be executed in the top level (in the cipres directory) of a CIPRES_CVS_ROOT directory that has been used to build CIPRES. It launches the CIPRES application and then runs all of the tests in cipres/framework/python (some of these test require a running registry). Test std{out|err} goes to this scripts std{out|err}. CIPRES app's stdout and stderr are redirected to ./.cipresApplicationTestOutput.txt Note: currently pauses to give the CIPRES app time to launch, we will probably need something more robust soon (if test fail and complain about not being able to connect to the registry, this is probably the problem).''' from subprocess import Popen import os import signal import sys import time sleepInterval = 5 startTime = time.time() cipresOutput = open('.cipresApplicationTestOutput.txt', 'w') cipres = Popen(['java', '-jar', 'cipres_dist/cipres.jar'], stdout = cipresOutput, stderr=subprocess.STDOUT) try: if cipres.poll() is not None: print 'CIPRES did not launch' sys.exit(-1) time.sleep(sleepInterval) # hack to let the registry get ready to respond # (actually this is usually not necessary because the initial tests don't need # the registry). Obviously, we need a better solution eventually. pathToPIPRES = os.path.join(os.path.abspath(os.curdir), 'framework', 'python') pipresTestScript = Popen(['python', os.path.join(pathToPIPRES, 'PIPRes', 'scripts', 'run_pipres_tests.py')], cwd = pathToPIPRES) pipresTestScript.wait() finally: os.kill(cipres.pid, signal.SIGKILL) if cipres.poll() is not None: time.sleep(sleepInterval) if cipres.poll() is not None: sys.exit('Could not kill the CIPRES application!''') cipresOutput.close() print 'returning', pipresTestScript.returncode endTime = time.time() secondsTaken = round(endTime - startTime - sleepInterval, 1) if secondsTaken < 60.0: print 'Time required for all tests: %.1f seconds' % secondsTaken else: minutesTaken = int(secondsTaken/60) secondsTaken = int(round(secondsTaken)) % 60 print 'Time required: %d minutes, %d seconds' % (minutesTaken, secondsTaken) sys.exit(pipresTestScript.returncode)