How to use the junitparser.junitparser.Element function in junitparser

To help you get started, we’ve selected a few junitparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gastlygem / junitparser / junitparser / junitparser.py View on Github external
elem = self._elem.find(Child._tag)
        return Child.fromelem(elem)

    def remove(self, sub_elem):
        """Remove a sub element."""
        for elem in self._elem.iterfind(sub_elem._tag):
            child = sub_elem.__class__.fromelem(elem)
            if child == sub_elem:
                self._elem.remove(child._elem)

    def tostring(self):
        """Converts element to XML string."""
        return etree.tostring(self._elem, encoding="utf-8")


class JUnitXml(Element):
    """The JUnitXml root object.

    It may contains a :class:`TestSuites` or a :class:`TestSuite`.

    Attributes:
        name: test suite name if it only contains one test suite
        time: time consumed by the test suites
        tests: total number of tests
        failures: number of failed cases
        errors: number of cases with errors
        skipped: number of skipped cases
    """

    _tag = "testsuites"
    name = Attr()
    time = FloatAttr()
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
elem = self.child(SystemErr)
        if elem is not None:
            return elem.text
        return None

    @system_err.setter
    def system_err(self, value):
        err = self.child(SystemErr)
        if err is not None:
            err.text = value
        else:
            err = SystemErr(value)
            self.append(err)


class System(Element):
    """Parent class for SystemOut and SystemErr.

    Attributes:
        text: the output message
    """
    _tag = ""

    def __init__(self, content=None):
        super(System, self).__init__(self._tag)
        self.text = content

    @property
    def text(self):
        return self._elem.text

    @text.setter
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
super(Property, self).__init__(self._tag)
        self.name = name
        self.value = value

    def __eq__(self, other):
        return self.name == other.name and self.value == other.value

    def __ne__(self, other):
        return not self == other

    def __lt__(self, other):
        """Supports sort() for properties."""
        return self.name > other.name


class Result(Element):
    """Base class for test result.

    Attributes:
        message: result as message string
        type: message type
    """

    _tag = None
    message = Attr()
    type = Attr()

    def __init__(self, message=None, type_=None):
        super(Result, self).__init__(self._tag)
        if message:
            self.message = message
        if type:
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
if props is None:
            return
        for prop in props:
            if prop == property_:
                props.remove(property_)

    def properties(self):
        """Iterates through all properties."""
        props = self.child(Properties)
        if props is None:
            return
        for prop in props:
            yield prop


class TestSuite(Element, PropertiesFunc):
    """The  object.

    Attributes:
        name: test suite name
        hostname: name of the test machine
        time: time concumed by the test suite
        timestamp: when the test was run
        tests: total number of tests
        failures: number of failed tests
        errors: number of cases with errors
        skipped: number of skipped cases
    """

    _tag = "testsuite"
    name = Attr()
    hostname = Attr()
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
return super(Properties, self).iterchildren(Property)

    def __eq__(self, other):
        p1 = list(self)
        p2 = list(other)
        p1.sort()
        p2.sort()
        if len(p1) != len(p2):
            return False
        for e1, e2 in zip(p1, p2):
            if e1 != e2:
                return False
        return True


class Property(Element):
    """A key/value pare that's stored in the test suite.

    Use it to store anything you find interesting or useful.

    Attributes:
        name: the property name
        value: the property value
    """
    _tag = "property"
    name = Attr()
    value = Attr()

    def __init__(self, name=None, value=None):
        super(Property, self).__init__(self._tag)
        self.name = name
        self.value = value
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
if props is None:
            return
        for prop in props:
            if prop == property_:
                props.remove(property_)

    def testsuites(self):
        """Iterates through all testsuites."""
        for suite in self.iterchildren(TestSuite):
            yield suite

    def write(self, filepath=None, pretty=False):
        write_xml(self, filepath=filepath, pretty=pretty)


class Properties(Element):
    """A list of properties inside a test suite.

    See :class:`Property`
    """

    _tag = "properties"

    def __init__(self):
        super(Properties, self).__init__(self._tag)

    def add_property(self, property_):
        self.append(property_)

    def __iter__(self):
        return super(Properties, self).iterchildren(Property)
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
return super(Properties, self).iterchildren(Property)

    def __eq__(self, other):
        p1 = list(self)
        p2 = list(other)
        p1.sort()
        p2.sort()
        if len(p1) != len(p2):
            return False
        for e1, e2 in zip(p1, p2):
            if e1 != e2:
                return False
        return True


class Property(Element):
    """A key/value pare that's stored in the test suite or the test case.

    Use it to store anything you find interesting or useful.

    Attributes:
        name: the property name
        value: the property value
    """
    _tag = "property"
    name = Attr()
    value = Attr()

    def __init__(self, name=None, value=None):
        super(Property, self).__init__(self._tag)
        self.name = name
        self.value = value
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
def __eq__(self, other):
        return super(Failure, self).__eq__(other)


class Error(Result):
    """Test result when the case has errors during execution."""
    _tag = "error"

    def __eq__(self, other):
        return super(Error, self).__eq__(other)


POSSIBLE_RESULTS = {Failure, Error, Skipped}


class TestCase(Element, PropertiesFunc):
    """Object to store a testcase and its result.

    Attributes:
        name: case name
        classname: the parent class of the case
        time: how much time is consumed by the test

    Properties:
        result: Failure, Skipped, or Error
        system_out: stdout
        system_err: stderr
    """

    _tag = "testcase"
    name = Attr()
    classname = Attr()
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
elem = self._elem.find(Child._tag)
        return Child.fromelem(elem)

    def remove(self, sub_elem):
        """Remove a sub element."""
        for elem in self._elem.iterfind(sub_elem._tag):
            child = sub_elem.__class__.fromelem(elem)
            if child == sub_elem:
                self._elem.remove(child._elem)

    def tostring(self):
        """Converts element to XML string."""
        return etree.tostring(self._elem, encoding="utf-8")


class JUnitXml(Element):
    """The JUnitXml root object.

    It may contains a :class:`TestSuites` or a :class:`TestSuite`.

    Attributes:
        name: test suite name if it only contains one test suite
        time: time consumed by the test suites
        tests: total number of tests
        failures: number of failed cases
        errors: number of cases with errors
        skipped: number of skipped cases
    """

    _tag = "testsuites"
    name = Attr()
    time = FloatAttr()
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
def __eq__(self, other):
        return super(Failure, self).__eq__(other)


class Error(Result):
    """Test result when the case has errors during execution."""
    _tag = "error"

    def __eq__(self, other):
        return super(Error, self).__eq__(other)


POSSIBLE_RESULTS = {Failure, Error, Skipped}


class TestCase(Element):
    """Object to store a testcase and its result.

    Attributes:
        name: case name
        classname: the parent class of the case
        time: how much time is consumed by the test

    Properties:
        result: Failure, Skipped, or Error
        system_out: stdout
        system_err: stderr
    """

    _tag = "testcase"
    name = Attr()
    classname = Attr()