def __ShowAssetTags(self, filename): assetFilename = os.path.abspath( FUtils.GetAvailableFilename(ASSET_FILENAME)) f = open(assetFilename, "w") xml.sax.parse(filename, FAssetHandler(f)) f.close() os.system("\"" + assetFilename + "\"") os.remove(assetFilename)
def RunApplication(self, command, workingDir): """RunApplication(command, workingDir) -> int Runs the command in another process. (It should *not* be overriden by any implemenations of application specific scripts) If detectCrash is "True" in the configuration file, then it will run the command with the timeout specified in the configuration file. The timeout is the amount of time without I/O that is allowed before considering that there is a crash and then will kill the process. The return value will be 1 if a crash was detected and needed to kill the command. The return value will be the return value of the command if it finished. If detectCrash is not "True" in the configuration file, it will run and wait for the command to return. The return value will be 0. arguments: command string representing the command to execute. workingDir string corresponding to the directory that the script files should be placed. This is a temporay directory and files placed in here should not be assumed to remain across different runnings of tests. """ dccFilename = os.path.join(workingDir, "temporaryDCCProcess.py") dccFilename = FUtils.GetAvailableFilename(dccFilename) file = open(dccFilename, "w") self.WriteCrashDetectBegin(file) self.WriteCrashDetect(file, command) if (self.configDict["detectCrash"] == "True"): file.write("sys.exit(p.poll())\n") file.close() returnValue = subprocess.call("\"" + self.configDict["pythonExecutable"] + "\" \"" + dccFilename + "\"") os.remove(dccFilename) return returnValue
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 __GetImageTag(self, exportedBlessed, exportedPrevious, filename, spacing, width, height, showBlessed = False, showPrevious = False): tag = spacing if (((exportedBlessed == None) or (len(exportedBlessed) == 1)) and ((exportedPrevious == None) or (len(exportedPrevious) == 1)) and (len(filename) == 1)): link = None else: animationFilename = os.path.join(self.__filesDir, "animation.html") animationFilename = FUtils.GetAvailableFilename(animationFilename) f = open(animationFilename, "w") htmlInMemory = ( "<html>\n" + "<head>\n" + " <title>Animation</title>\n" + "</head>\n" + "<body>\n" + " <table>\n" + " <tr>\n") if ((showBlessed) and (exportedBlessed != None)): htmlInMemory = htmlInMemory + " <th>Blessed</th>\n" if ((showPrevious) and (exportedPrevious != None)): htmlInMemory = htmlInMemory + " <th>Previous</th>\n" htmlInMemory = (htmlInMemory + " <th>Current</th>\n" + " </tr>\n") maxRows = len(filename) if ((showBlessed) and (exportedBlessed != None)): maxRows = max(maxRows, len(exportedBlessed)) if ((showPrevious) and (exportedPrevious != None)): maxRows = max(maxRows, len(exportedPrevious)) for i in range(maxRows): htmlInMemory = htmlInMemory + " <tr>\n" if ((showBlessed) and (exportedBlessed != None)): if (i < len(exportedBlessed)): htmlInMemory = (htmlInMemory + " <td>\n" + " " + self.__GetSingleImageTag(self.__filesDir, exportedBlessed[i], width, height) + "\n" + " </td>\n") else: htmlInMemory = (htmlInMemory + " <td> </td>") if ((showPrevious) and (exportedPrevious != None)): if (i < len(exportedPrevious)): htmlInMemory = (htmlInMemory + " <td>\n" + " " + self.__GetSingleImageTag(self.__filesDir, exportedPrevious[i], width, height) + "\n" + " </td>\n") else: htmlInMemory = (htmlInMemory + " <td> </td>") if (i < len(filename)): htmlInMemory = (htmlInMemory + " <td>\n" + " " + self.__GetSingleImageTag(self.__filesDir, filename[i], width, height) + "\n" + " </td>\n") else: htmlInMemory = (htmlInMemory + " <td> </td>") htmlInMemory = htmlInMemory + " </tr>\n" f.write(htmlInMemory + " </table>\n</body>\n</html>\n") f.close() link = animationFilename if (showBlessed): if (exportedBlessed == None): tag = (tag + "<img alt=\"No Blessed\" " + "border=\"1\" width=\"" + str(width) + "\" height=\"" + str(height) + "\"> ") else: tag = (tag + self.__GetSingleImageTag(self.__mainDir, exportedBlessed[-1], width, height, link) + " ") if (showPrevious): if (exportedPrevious == None): tag = (tag + "<img alt=\"No Previous\" " + "border=\"1\" width=\"" + str(width) + "\" height=\"" + str(height) + "\"> ") else: tag = (tag + self.__GetSingleImageTag(self.__mainDir, exportedPrevious[-1], width, height, link) + " ") tag = (tag + self.__GetSingleImageTag(self.__mainDir, filename[-1], width, height, link)) return tag
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)