Пример #1
0
    def generate_report(self):
        """Generates html and pdf report"""
        html_filename = os.path.join(self.test_directory,
                                     self.test_filename) + ".html"
        pdf_filename = os.path.join(self.test_directory,
                                    self.test_filename) + ".pdf"
        archive_filename = os.path.join(\
           self.test_directory,
           datetime.now().strftime("%Y_%m_%d_%H") + "_" + \
           self.test_filename)

        try:
            output_file = open(html_filename, "w")
            output_file.write(SimpleHTML.create_html_start(\
                "Beamline test summary"))
            output_file.write("<h1>Beamline %s Test results</h1>" % \
                              self.beamline_name)
            output_file.write("<h2>Executed tests:</h2>")
            table_cells = []
            for test in self.results_list:
                table_cells.append(\
                  ["bgcolor=%s" % TEST_COLORS_TABLE[test["result_bit"]],
                   "<a href=#%s>%s</a>" % \
                   (test["short_name"], test["full_name"]),
                   test["result_short"],
                   test["start_time"],
                   test["end_time"]])

            table_rec = SimpleHTML.create_table(\
                ["Name", "Result", "Start time", "End time"],
                table_cells)
            for row in table_rec:
                output_file.write(row)
            output_file.write("\n<hr>\n")

            for test_result in self.results_html_list:
                output_file.write(test_result + "\n")

            output_file.write(SimpleHTML.create_html_end())
            output_file.close()

            self.emit("htmlGenerated", html_filename)
            logging.getLogger("HWR").info(\
               "BeamlineTest: Test result written in file %s" % \
               html_filename)
        except:
            logging.getLogger("HWR").error(\
               "BeamlineTest: Unable to generate html report file %s" % \
               html_filename)

        try:
            pdfkit.from_url(html_filename, pdf_filename)
            logging.getLogger("GUI").info(\
               "PDF report %s generated" % pdf_filename)
        except:
            logging.getLogger("HWR").error(\
               "BeamlineTest: Unable to generate pdf report file %s" % \
               pdf_filename)

        self.emit('testFinished', html_filename)
    def generate_html_report(self, test_list):
        """
        Descript. :
        """
        html_filename = os.path.join(\
           self.test_directory,
           self.test_filename)
        archive_filename = os.path.join(\
           self.test_directory,
           datetime.now().strftime("%Y_%m_%d_%H") + "_" + \
           self.test_filename)

        try:
            output_file = open(html_filename, "w") 
            output_file.write(SimpleHTML.create_html_start("Beamline test summary"))
            output_file.write("<h1>Beamline %s Test results</h1>" % self.beamline_name)

            output_file.write("<h2>Executed tests:</h2>")
            table_cells = []
            for test in self.results_list:
                table_cells.append(["bgcolor=%s" % TEST_COLORS_TABLE[test["result_bit"]],
                                   "<a href=#%s>%s</a>" % (test["short_name"], test["full_name"]), 
                                   test["result_short"],
                                   test["start_time"],
                                   test["end_time"]])
           
            table_rec = SimpleHTML.create_table(\
                ["Name", "Result", "Start time", "End time"], 
                table_cells)
            for row in table_rec:
                output_file.write(row)
            output_file.write("\n<hr>\n")
         
            for test_result in self.results_html_list:
                output_file.write(test_result + "\n")
      
            output_file.write(SimpleHTML.create_html_end())
            output_file.close()
 
            self.emit("htmlGenerated", html_filename)
            logging.getLogger("HWR").info(\
               "BeamlineTest: Test result written in file %s" % html_filename)
        except:
            logging.getLogger("HWR").error(\
               "BeamlineTest: Unable to generate html report file %s" % html_filename)

        try: 
            output_file = open(html_filename, "r")
            archive_file = open(archive_filename, "w")

            for line in output_file.readlines():
                archive_file.write(line)
            output_file.close()
            archive_file.close()

            logging.getLogger("HWR").info("Archive file :%s generated" % archive_filename)
        except:
            logging.getLogger("HWR").error(\
              "BeamlineTest: Unable to generate html report file %s" % archive_filename)