Example #1
0
def xml_to_bytes(element, pretty_print=False):
    """Wrapper for etree.tostring, that takes care of unsupported pretty_print
    option and prepends an encoding header."""
    if use_lxml:
        xml = etree.tostring(
            element, encoding="UTF-8", xml_declaration=True, pretty_print=pretty_print
        )
    else:
        xml = etree.tostring(element, encoding="UTF-8")
        if not xml.startswith(b"<?xml "):
            xml = b'<?xml version="1.0" encoding="utf-8" ?>\n' + xml

    assert xml.startswith(b"<?xml ")  # ET should prepend an encoding header
    return xml
Example #2
0
def xml_to_bytes(element, pretty_print=False):
    """Wrapper for etree.tostring, that takes care of unsupported pretty_print
    option and prepends an encoding header."""
    if use_lxml:
        xml = etree.tostring(element,
                             encoding="UTF-8",
                             xml_declaration=True,
                             pretty_print=pretty_print)
    else:
        xml = etree.tostring(element, encoding="UTF-8")
        if not xml.startswith(b"<?xml "):
            xml = b'<?xml version="1.0" encoding="utf-8" ?>\n' + xml

    assert xml.startswith(b"<?xml ")  # ET should prepend an encoding header
    return xml
Example #3
0
    def load_file(self, path):
        self.controller.data = TestData.TestRunData()
        try:
            tree = et.parse(path)
        except Exception:
            raise FileNotFoundError
        root = tree.getroot()
        self.controller.get_frame("PageXML").set_xml(et.tostring(root))
        for i in range(len(root) - 1):
            test_case = root[i]
            self.steps.add_test_case(test_case.get("name"))
            test_case_data = self.controller.data.add_test_case(
                test_case.get("name"), i)
            for index, value in enumerate(test_case):
                elem = value
                status = elem[0]
                time = elem[1]
                description = elem[2]
                if status.text == "passed":
                    self.steps.step_pass(description.text, time.text)
                    test_case_data.add_step(index + 1,
                                            status="pass",
                                            description=description.text,
                                            time=time.text)
                if status.text == "failed":
                    error_element = elem[3]
                    func = error_element[0]
                    func_error_line = error_element[1]
                    func_error_message = error_element[2]
                    self.steps.step_fail(description.text,
                                         error_message=str(
                                             func_error_message.text),
                                         lines=str(func.text),
                                         error_line=str(func_error_line.text),
                                         time=time.text)
                    test_case_data.add_step(
                        order=index + 1,
                        status="fail",
                        description=description.text,
                        method=func.text,
                        error_line=func_error_line,
                        time=time.text,
                        error_message=func_error_message.text)

            self.steps.test_finish()
        console = root[-1]
        self.steps.write_console(console.text)
        self.controller.loaded_xml = True

        self.steps.text.see("1.0")
Example #4
0
    def write_result():
        """
        Writes the Batsim formatted platform.
        """

        def doctype():
            """
            Provides SimGrid doctype.
            """

            return "<!DOCTYPE platform SYSTEM \"https://simgrid.org/simgrid.dtd\">"

        with open(args.output_xml, "w", ) as output_f:
            output_f.write(xml_format.parseString("{}{}".format(doctype(),
                xml.tostring(xml_tree).decode())).toprettyxml(indent="  ",
                    encoding="utf-8").decode())
Example #5
0
    def write_result():
        """
        Writes the Batsim formatted platform.
        """
        def doctype():
            """
            Provides SimGrid doctype.
            """

            return "<!DOCTYPE platform SYSTEM \"https://simgrid.org/simgrid.dtd\">"

        with open(
                args.output_xml,
                "w",
        ) as output_f:
            output_f.write(
                xml_format.parseString("{}{}".format(
                    doctype(),
                    xml.tostring(xml_tree).decode())).toprettyxml(
                        indent="  ", encoding="utf-8").decode())
Example #6
0
    def _save_xml(self):
        """Create a string of the XML element 'test_run' with a pretty format (indented and with end lines)
        that later is writen in a XML file

        :return: None"""
        # Converts to string the 'xml' Element to string
        xml_string = et.tostring(self.xml,
                                 encoding='UTF-8',
                                 xml_declaration=True,
                                 pretty_print=True)
        # Replace the end of line with end of line that some programs can understand
        xml_string.replace(b'\n', b'\r\n')
        # Create a string with the name of the file
        xml_name = "test_history/" + _get_datetime() + ".xml"
        # Create and write the XML data to the file
        with open(xml_name, "wb") as f:
            f.write(xml_string)
            f.close()
        # Add the filename to the Queue in order to be read by the main thread
        self.queue.put(["xml_name", xml_name])