Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __iter__(self):
return super(JUnitXml, self).iterchildren(TestSuite)
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 __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 __iter__(self):
return super(JUnitXml, self).iterchildren(TestSuite)
def __iadd__(self, other):
if other._elem.tag == "testsuites":
for suite in other:
self.add_testsuite(suite)
elif other._elem.tag == "testsuite":
suite = TestSuite(name=other.name)
for case in other:
suite._add_testcase_no_update_stats(case)
self.add_testsuite(suite)
self.update_statistics()
return self
def remove_testcase(self, testcase):
"""Removes a test case from the suite."""
for case in self:
if case == testcase:
super(TestSuite, self).remove(case)
self.update_statistics()
def fromfile(cls, filepath):
"""Initiate the object from a report file."""
tree = etree.parse(filepath)
root_elem = tree.getroot()
if root_elem.tag == "testsuites":
instance = cls()
elif root_elem.tag == "testsuite":
instance = TestSuite()
else:
raise JUnitXmlError("Invalid format.")
instance._elem = root_elem
instance.filepath = filepath
return instance
def fromfile(cls, filepath):
"""Initiate the object from a report file."""
tree = etree.parse(filepath)
root_elem = tree.getroot()
if root_elem.tag == "testsuites":
instance = cls()
elif root_elem.tag == "testsuite":
instance = TestSuite()
else:
raise JUnitXmlError("Invalid format.")
instance._elem = root_elem
instance.filepath = filepath
return instance
def __iadd__(self, other):
if other._elem.tag == "testsuites":
for suite in other:
self.add_testsuite(suite)
elif other._elem.tag == "testsuite":
suite = TestSuite(name=other.name)
for case in other:
suite._add_testcase_no_update_stats(case)
self.add_testsuite(suite)
self.update_statistics()
return self
def remove_testcase(self, testcase):
"""Removes a test case from the suite."""
for case in self:
if case == testcase:
super(TestSuite, self).remove(case)
self.update_statistics()