def Judge(self, filename, testProcedure, testId): # Look for a judging script scriptFilename = FUtils.ChangeExtension(filename, "py") try: # Set-up the judging script context. context = FJudgementContext(testProcedure, testId) if (os.path.exists(scriptFilename)): # Parse, compile and execute the judging script. judgingDictionary = { 'testProducedure': testProcedure, 'judgingObject': None } execfile(scriptFilename, judgingDictionary, judgingDictionary) if (judgingDictionary.has_key('judgingObject')): judgingObject = judgingDictionary['judgingObject'] # We have a juding object. # Look for and process all the wanted badge levels. for i in range(len(FGlobals.badgeLevels)): badgeLevel = FGlobals.badgeLevels[i] judgingLevel = "Judge" + badgeLevel if (judgingObject.__class__.__dict__.has_key( judgingLevel)): judgingFunction = judgingObject.__class__.__dict__[ judgingLevel] if (callable(judgingFunction)): # Run this judging function. judgement = judgingFunction( judgingObject, context) # Process the judgement if judgement: self.__judgingResults[ badgeLevel] = FJudgement.PASSED else: self.__judgingResults[ badgeLevel] = FJudgement.FAILED judgingLog = context.GetLog() if len(judgingLog) > 0: self.__judgingLogs[badgeLevel] = judgingLog elif judgement: self.__judgingLogs[ badgeLevel] = "Judgement passed." else: self.__judgingLogs[ badgeLevel] = "Judgement failed." context.ResetLog() else: self.__judgingResults[ badgeLevel] = FJudgement.MISSING_DATA self.__judgingLogs[ badgeLevel] = "Invalid judging script. '" + judgingLevel + "' is not a function." else: self.__judgingResults[ badgeLevel] = FJudgement.NO_SCRIPT self.__judgingLogs[ badgeLevel] = "Judging script does not include the '" + badgeLevel + "' badge." # We need that checksum too! self.__checksum += "\n" + FUtils.CalculateChecksum( scriptFilename) else: for i in range(len(FGlobals.badgeLevels)): badgeLevel = FGlobals.badgeLevels[i] self.__judgingResults[ badgeLevel] = FJudgement.MISSING_DATA self.__judgingLogs[ badgeLevel] = "Invalid judging script. Did not create the judging object." else: for i in range(len(FGlobals.badgeLevels)): badgeLevel = FGlobals.badgeLevels[i] self.__judgingResults[badgeLevel] = FJudgement.NO_SCRIPT self.__judgingLogs[ badgeLevel] = "No judging script provided." except Exception, info: print "------------------------------------------------------------" print "<FExecution> could not run judging script: '" + os.path.basename( scriptFilename) + "'." print 'Exception is thrown at line %d in FExecution.py' % sys.exc_traceback.tb_lineno print info[0] print 'Trace back stack is:\n' traceback.print_exc()
def ToHtml(self, path, testProcedure, showBlessed, showPrevious, width, height, keys = None): file = open(path, "w") checksumFilename = FUtils.ChangeExtension(path, "sha") checksumFile = open(checksumFilename, "w") checksumFile.write(FUtils.CalculateSuiteChecksum()) file.write( "<html>\n" + "<head>\n" + " <title>" + testProcedure.GetName() + "</title>\n" + "</head>\n" + "<body>\n" + " <h1><center>" + testProcedure.GetName() + "</center></h1>\n" + " <b><u>Statistics:</b></u>" + " <table>\n" + " <tr>\n" + " <td># of tests in test procedure:</td>\n" + " <td>" + FHtmlExporter.__REPLACE_TEST_PROCEDURE_COUNT + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td># of tests in HTML:</td>\n" + " <td>" + FHtmlExporter.__REPLACE_HTML_COUNT + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td># of tests passed in HTML:</td>\n" + " <td>" + FHtmlExporter.__REPLACE_PASSED_COUNT + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td># of tests failed in HTML:</td>\n" + " <td>" + FHtmlExporter.__REPLACE_FAILED_COUNT + "</td>\n" + " </tr>\n" + " <td># of tests warning in HTML:</td>\n" + " <td>" + FHtmlExporter.__REPLACE_WARNINGS_COUNT + "</td>\n" + " </tr>\n" + " <td># of tests errors in HTML:</td>\n" + " <td>" + FHtmlExporter.__REPLACE_ERRORS_COUNT + "</td>\n" + " </tr>\n" + " </tr>\n" + " <td>Badges earned:</td>\n" + " <td>" + FHtmlExporter.__REPLACE_BADGES_EARNED + "</td>\n" + " </tr>\n" + " </table>\n" + " <br><br>\n" + # TODO:take with respect to how user positions the columns " <center><table border=\"1\" cellspacing=\"0\" " + "cellpadding=\"5\" bordercolor=\"gray\">\n" + " <tr>\n" + " <th>\n" + " Test Id\n" + " </th>\n" + " <th>\n" + " Categories\n" + " </th>\n" + " <th>\n" + " Description\n" + " </th>\n" + " <th>\n" + " Test Filename\n" + " </th>\n" + " <th>\n" + " Blessed\n" + " </th>\n") for step, app, op, settings in testProcedure.GetStepGenerator(): if (op == VALIDATE and op not in OPS_NEEDING_APP): file.write( " <th>\n" + " <" + str(step) + "> " + op + "\n" + " </th>\n") else: file.write( " <th>\n" + " <" + str(step) + "> " + op + "(" + app + ")\n" + " </th>\n") file.write( " <th><div style=\"width: 300\">\n" + " Result\n" + " </div></th>\n"); for i in range(len(FGlobals.badgeLevels)): file.write( " <th>" + FGlobals.badgeLevels[i] + "</td>") file.write( " <th>\n" + " Different From Previous\n" + " </th>\n" + " <th><div style=\"width: 100\">\n" + " Time\n" + " </div></th>\n" + " <th>\n" + " Environment\n" + " </th>\n" + " <th>\n" + " Comments\n" + " </th>\n" + " </tr>\n") self.__filesDir = FUtils.GetProperFilename(path) + HTML_POSTFIX self.__filesDir = os.path.join(os.path.dirname(path), self.__filesDir) self.__filesDir = self.__GetAvailableDir(self.__filesDir) os.mkdir(self.__filesDir) self.__mainDir = os.path.dirname(path) self.__passedTestsCount = 0 self.__failedTestsCount = 0 self.__warningCount = 0 self.__errorCount = 0 # Prepare the badges earned results. testCount = 0 if (keys == None): for test in testProcedure.GetTestGenerator(): self.__AddTest(file, checksumFile, testProcedure, test, showBlessed, showPrevious, width, height) testCount = testCount + 1 else: for key in keys: self.__AddTest(file, checksumFile, testProcedure, testProcedure.GetTest(key), showBlessed, showPrevious, width, height) testCount = testCount + 1 file.write( " </table></center>\n" + "</body>\n" + "</html>\n") file.close() checksumFile.close() # Replace the statement tokens by their real values. badgesEarnedStatement = self.__judgementCompiler.GenerateStatement() if (len(badgesEarnedStatement) == 0): badgesEarnedStatement = "None" replaceDict = { FHtmlExporter.__REPLACE_TEST_PROCEDURE_COUNT : str(testProcedure.GetTestCount()), FHtmlExporter.__REPLACE_HTML_COUNT : str(testCount), FHtmlExporter.__REPLACE_PASSED_COUNT : str(self.__passedTestsCount), FHtmlExporter.__REPLACE_FAILED_COUNT : str(self.__failedTestsCount), FHtmlExporter.__REPLACE_WARNINGS_COUNT : str(self.__warningCount), FHtmlExporter.__REPLACE_ERRORS_COUNT : str(self.__errorCount), FHtmlExporter.__REPLACE_BADGES_EARNED : badgesEarnedStatement } tempFilename = FUtils.GetAvailableFilename(path + ".temp") f = open(tempFilename, "w") htmlFile = open(path) line = htmlFile.readline() while (line): for key in replaceDict.keys(): if (line.count(key) != 0): line = line.replace(key, replaceDict[key], 1) replaceDict.pop(key) break f.write(line) line = htmlFile.readline() htmlFile.close() f.close() shutil.copy2(tempFilename, path) os.remove(tempFilename)
def ToCsv(self, path, testProcedure, showBlessed, showPrevious, width, height, keys=None): file = open(path, "w") checksumFile = open(FUtils.ChangeExtension(path, "sha"), "w") checksumFile.write(FUtils.CalculateSuiteChecksum()) file.write("\nTest Procedure:,%s\n\n" % (testProcedure.GetName())) file.write("Statistics: \n" + "# of tests in test procedure:," + FCsvExporter.__REPLACE_TEST_PROCEDURE_COUNT + "\n" + "# of tests:," + FCsvExporter.__REPLACE_HTML_COUNT + "\n" + "# of tests passed:," + FCsvExporter.__REPLACE_PASSED_COUNT + "\n" + "# of tests failed:," + FCsvExporter.__REPLACE_FAILED_COUNT + "\n" + "# of tests warning:," + FCsvExporter.__REPLACE_WARNINGS_COUNT + "\n" + "# of tests errors:," + FCsvExporter.__REPLACE_ERRORS_COUNT + "\n" + "Badges earned:," + FCsvExporter.__REPLACE_BADGES_EARNED + "\n\n") file.write("Test Id,Categories,Description,Test Filename,Blessed,") for step, app, op, settings in testProcedure.GetStepGenerator(): if (op == VALIDATE and op not in OPS_NEEDING_APP): file.write("<" + str(step) + ">" + " " + op + ",") else: file.write("<" + str(step) + ">" + " " + op + " (" + app + "),") file.write("Results,") for i in range(len(FGlobals.badgeLevels)): file.write(FGlobals.badgeLevels[i] + ",") file.write("Different From Previous,Time,Environment,Comments\n") self.__filesDir = FUtils.GetProperFilename(path) + CSV_POSTFIX self.__filesDir = os.path.join(os.path.dirname(path), self.__filesDir) self.__filesDir = self.__GetAvailableDir(self.__filesDir) # os.mkdir(self.__filesDir) self.__mainDir = os.path.dirname(path) self.__passedTestsCount = 0 self.__failedTestsCount = 0 self.__warningCount = 0 self.__errorCount = 0 testCount = 0 if (keys == None): for test in testProcedure.GetTestGenerator(): self.__AddTest(file, checksumFile, testProcedure, test, showBlessed, showPrevious, width, height) testCount = testCount + 1 else: for key in keys: self.__AddTest(file, checksumFile, testProcedure, testProcedure.GetTest(key), showBlessed, showPrevious, width, height) testCount = testCount + 1 file.close() # Replace the statement tokens by their real values. badgesEarnedStatement = self.__judgementCompiler.GenerateStatement() if (len(badgesEarnedStatement) == 0): badgesEarnedStatement = "None" replaceDict = { FCsvExporter.__REPLACE_TEST_PROCEDURE_COUNT: str(testProcedure.GetTestCount()), FCsvExporter.__REPLACE_HTML_COUNT: str(testCount), FCsvExporter.__REPLACE_PASSED_COUNT: str(self.__passedTestsCount), FCsvExporter.__REPLACE_FAILED_COUNT: str(self.__failedTestsCount), FCsvExporter.__REPLACE_WARNINGS_COUNT: str(self.__warningCount), FCsvExporter.__REPLACE_ERRORS_COUNT: str(self.__errorCount), FCsvExporter.__REPLACE_BADGES_EARNED: badgesEarnedStatement } tempFilename = FUtils.GetAvailableFilename(path + ".temp") f = open(tempFilename, "w") csvFile = open(path) line = csvFile.readline() while (line): for key in replaceDict.keys(): if (line.count(key) != 0): line = line.replace(key, replaceDict[key], 1) replaceDict.pop(key) break f.write(line) line = csvFile.readline() csvFile.close() f.close() shutil.copy2(tempFilename, path) os.remove(tempFilename)