コード例 #1
0
ファイル: FHtmlExporter.py プロジェクト: yazici/COLLADA-CTS
    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)
コード例 #2
0
ファイル: FCsvExporter.py プロジェクト: yazici/COLLADA-CTS
    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)