Exemplo n.º 1
0
    def export(self, source):
        """Create multiple XML files in the given directory for each top level test group report."""
        xml_dir = self.cfg.xml_dir

        if os.path.exists(xml_dir):
            shutil.rmtree(xml_dir)

        os.makedirs(xml_dir)

        files = set(os.listdir(xml_dir))

        for child_report in source:
            filename = '{}.xml'.format(slugify(child_report.name))
            filename = unique_name(filename, files)
            files.add(filename)
            file_path = os.path.join(self.cfg.xml_dir, filename)

            # If a report has XML string attribute it was mostly generated via parsing
            # a JUnit compatible XML file already, meaning we don't need to re-generate
            # the XML contents, but can directly write the contents to a file instead.
            if hasattr(child_report, 'xml_string'):
                with open(file_path, 'w') as xml_target:
                    xml_target.write(child_report.xml_string)
            else:
                renderer = self.renderer_map.get(child_report.category, BaseRenderer)()
                element = etree.ElementTree(renderer.render(child_report))
                element.write(
                    file_path,
                    pretty_print=True,
                    xml_declaration=True,
                    encoding='UTF-8'
                )

        TESTPLAN_LOGGER.exporter_info(
            '%s XML files created at: %s', len(source), xml_dir)
Exemplo n.º 2
0
    def export(self, source: TestReport) -> str:
        """
        Creates multiple XML files in the given directory for MultiTest.

        :param source:
        :return:
        """
        xml_dir = pathlib.Path(self.cfg.xml_dir).resolve()

        if xml_dir.exists():
            shutil.rmtree(xml_dir)

        xml_dir.mkdir(parents=True, exist_ok=True)

        files = set(os.listdir(xml_dir))

        for child_report in source:
            filename = "{}.xml".format(slugify(child_report.name))
            filename = unique_name(filename, files)
            files.add(filename)
            file_path = xml_dir / filename

            # TODO: "mostly" - is this just confidence or proven?
            # If a report has XML string attribute it was mostly
            # generated via parsing a JUnit compatible XML file
            # already, meaning we don't need to re-generate the XML
            # contents, but can directly write the contents to a file
            # instead.
            if hasattr(child_report, "xml_string"):
                with open(file_path, "w") as xml_target:
                    xml_target.write(child_report.xml_string)
            else:
                renderer = self.renderer_map.get(child_report.category,
                                                 BaseRenderer)()
                element = etree.ElementTree(renderer.render(child_report))
                element.write(
                    str(file_path),
                    pretty_print=True,
                    xml_declaration=True,
                    encoding="utf-8",
                )

        self.logger.exporter_info("%s XML files created at %s", len(source),
                                  xml_dir)
        return str(xml_dir)
Exemplo n.º 3
0
    def export(self, source):
        """
        Create multiple XML files in the given directory for each top
        level test group report.
        """
        xml_dir = self.cfg.xml_dir

        if os.path.exists(xml_dir):
            shutil.rmtree(xml_dir)

        os.makedirs(xml_dir)

        files = set(os.listdir(xml_dir))

        for child_report in source:
            filename = "{}.xml".format(slugify(child_report.name))
            filename = unique_name(filename, files)
            files.add(filename)
            file_path = os.path.join(xml_dir, filename)

            # If a report has XML string attribute it was mostly
            # generated via parsing a JUnit compatible XML file
            # already, meaning we don't need to re-generate the XML
            # contents, but can directly write the contents to a file
            # instead.
            if hasattr(child_report, "xml_string"):
                with open(file_path, "w") as xml_target:
                    xml_target.write(child_report.xml_string)
            else:
                renderer = self.renderer_map.get(child_report.category,
                                                 BaseRenderer)()
                element = etree.ElementTree(renderer.render(child_report))
                element.write(
                    file_path,
                    pretty_print=True,
                    xml_declaration=True,
                    encoding="utf-8",
                )

        xml_dir = os.path.abspath(xml_dir)
        self.logger.exporter_info("%s XML files created at %s", len(source),
                                  xml_dir)
        return xml_dir
Exemplo n.º 4
0
    def export(self, source):
        xml_dir = self.cfg.xml_dir

        if os.path.exists(xml_dir):
            shutil.rmtree(xml_dir)

        os.makedirs(xml_dir)

        files = set(os.listdir(xml_dir))

        for child_report in source:
            renderer = self.renderer_map[child_report.category]()
            element = etree.ElementTree(renderer.render(child_report))
            filename = '{}.xml'.format(slugify(child_report.name))
            filename = unique_name(filename, files)
            files.add(filename)

            file_path = os.path.join(self.cfg.xml_dir, filename)
            element.write(file_path, pretty_print=True)

        TESTPLAN_LOGGER.exporter_info(
            '%s XML files created at: %s', len(source), xml_dir)