How to use the junitparser.junitparser.Attr 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
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()
    time = FloatAttr()
    timestamp = Attr()
    tests = IntAttr()
    failures = IntAttr()
    errors = IntAttr()
    skipped = IntAttr()

    def __init__(self, name=None):
        super(TestSuite, self).__init__(self._tag)
        self.name = name
        self.filepath = None

    def __iter__(self):
        return super(TestSuite, self).iterchildren(TestCase)

    def __len__(self):
        return len(list(self.__iter__()))
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
self.name = name

    def __get__(self, instance, cls):
        """Gets value from attribute, return None if attribute doesn't exist."""
        value = instance._elem.attrib.get(self.name)
        if value is not None:
            return escape(value)
        return value

    def __set__(self, instance, value):
        """Sets XML element attribute."""
        if value is not None:
            instance._elem.attrib[self.name] = unicode(value)


class IntAttr(Attr):
    """An integer attribute for an XML element.

    This class is used internally for counting test cases, but you could use
    it for any specific purpose.
    """

    def __get__(self, instance, cls):
        result = super(IntAttr, self).__get__(instance, cls)
        if result is None and (
            isinstance(instance, JUnitXml) or isinstance(instance, TestSuite)
        ):
            instance.update_statistics()
            result = super(IntAttr, self).__get__(instance, cls)
        return int(result) if result else None

    def __set__(self, instance, value):
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
def attributed(cls):
    """Decorator to read XML element attribute name from class attribute."""
    for key, value in vars(cls).items():
        if isinstance(value, Attr):
            value.name = key
    return cls
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
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:
            self.type = type_

    def __eq__(self, other):
        return (
            self._tag == other._tag
            and self.type == other.type
            and self.message == other.message
        )
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
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

    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
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
"""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()
    time = FloatAttr()
    timestamp = Attr()
    tests = IntAttr()
    failures = IntAttr()
    errors = IntAttr()
    skipped = IntAttr()

    def __init__(self, name=None):
        super(TestSuite, self).__init__(self._tag)
        self.name = name
        self.filepath = None

    def __iter__(self):
        return super(TestSuite, self).iterchildren(TestCase)

    def __len__(self):
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
def __get__(self, instance, cls):
        result = super(IntAttr, self).__get__(instance, cls)
        if result is None and (
            isinstance(instance, JUnitXml) or isinstance(instance, TestSuite)
        ):
            instance.update_statistics()
            result = super(IntAttr, self).__get__(instance, cls)
        return int(result) if result else None

    def __set__(self, instance, value):
        if not isinstance(value, int):
            raise TypeError("Expected integer value.")
        super(IntAttr, self).__set__(instance, value)


class FloatAttr(Attr):
    """A float attribute for an XML element.

    This class is used internally for counting test durations, but you could
    use it for any specific purpose.
    """

    def __get__(self, instance, cls):
        result = super(FloatAttr, self).__get__(instance, cls)
        if result is None and (
            isinstance(instance, JUnitXml) or isinstance(instance, TestSuite)
        ):
            instance.update_statistics()
            result = super(FloatAttr, self).__get__(instance, cls)
        return float(result) if result else None

    def __set__(self, instance, value):
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
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_:
            self.type = type_

    def __eq__(self, other):
        return (
            self._tag == other._tag
            and self.type == other.type
            and self.message == other.message
        )
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
self.name = name

    def __get__(self, instance, cls):
        """Gets value from attribute, return None if attribute doesn't exist."""
        value = instance._elem.attrib.get(self.name)
        if value is not None:
            return escape(value)
        return value

    def __set__(self, instance, value):
        """Sets XML element attribute."""
        if value is not None:
            instance._elem.attrib[self.name] = unicode(value)


class IntAttr(Attr):
    """An integer attribute for an XML element.

    This class is used internally for counting test cases, but you could use
    it for any specific purpose.
    """

    def __get__(self, instance, cls):
        result = super(IntAttr, self).__get__(instance, cls)
        if result is None and (
            isinstance(instance, JUnitXml) or isinstance(instance, TestSuite)
        ):
            instance.update_statistics()
            result = super(IntAttr, self).__get__(instance, cls)
        return int(result) if result else None

    def __set__(self, instance, value):
github gastlygem / junitparser / junitparser / junitparser.py View on Github external
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

    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