def showWarnings(warningList, notConfirm=False): '''Function to write error message to log, to screen and exit''' if not warningList or len(warningList) == 0: return True for warning in warningList: from protlib_xmipp import warnStr print >> sys.stderr, warnStr("WARNING: %s"% warning) if notConfirm: return True answer = raw_input('Do you want to proceed? [y/N]:') if not answer or answer.lower() == 'n': return False return True
def runProgramTests(self, program): tests = self.progDict[program] n = len(tests) outPath = join(self.fnDir, program) outDir = outPath testName = "" testNo = 1 md = MetaData(self._statistics) for test, mpi, random, preruns, postruns, changeDirectory, testfiles, owner in tests: # for test, mpi, random, preruns, postruns, changeDirectory, testfiles in tests: objid = md.addObject() if n > 1: outDir = outPath + "_%02d" % testNo testName = "(%d of %d)" % (testNo, n) # test num md.setValue(MDL_BLOCK_NUMBER, testNo, objid) # program name # print type(program) md.setValue(MDL_PROGRAM, str(program), objid) dtBegin = datetime.now() timeStr = str(dtBegin) # beginning time md.setValue(MDL_DATE, str(timeStr), objid) print "------------------------------------------------------------------------------------" print warnStr(">>> Running test %(testName)s of %(program)s (%(timeStr)s)" % locals()) print " Output dir: " print " ", outDir print " Statistics file: " print " ", self._statistics print " Timeout: " print " %d seconds" % self._timeout if exists(outDir): shutil.rmtree(outDir) os.makedirs(outDir) self.outDir = outDir self.program = program test = self.expandFormat(test) self.runCommands(preruns, "prerun") if mpi: cmd = ( "mpirun -np 3 `which %s`" % program ) ##DO NOT REPLACE SO WE CAN TEST MPI EASILY.replace("xmipp_", "xmipp_mpi_") else: cmd = program if changeDirectory: cmd = "cd %s ; " % outDir + cmd + " %s > stdout.txt 2> stderr.txt" % test else: cmd += " %s > %s/stdout.txt 2> %s/stderr.txt" % (test, outDir, outDir) print " Command: " print " ", greenStr(cmd) # run the test itself command = Command(cmd) self._command = command try: command.run(timeout=self._timeout) except KeyboardInterrupt: command.terminate() # result = os.system(cmd) # result = subprocess.call(cmd, shell=True) self.runCommands(postruns, "postrun") tdEnd = (datetime.now() - dtBegin).total_seconds() # elapsed time md.setValue(MDL_TIME, tdEnd, objid) print " Elapsed time: %d seconds" % tdEnd error = self.checkResult(testfiles, outDir, random) if len(error): self.error += error self.errorFlag = True print redStr("ERRORS:\n" + error) md.setValue(MDL_ENABLED, -1, objid) else: md.setValue(MDL_ENABLED, 1, objid) testNo += 1 md.setValue(MDL_USER, str(owner), objid) md.write(self._statistics)