Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 write_xml(obj, filepath=None, pretty=False):
tree = etree.ElementTree(obj._elem)
if filepath is None:
filepath = obj.filepath
if filepath is None:
raise JUnitXmlError("Missing filepath argument.")
if pretty:
from xml.dom.minidom import parseString
text = etree.tostring(obj._elem)
xml = parseString(text)
with open(filepath, "wb") as xmlfile:
xmlfile.write(xml.toprettyxml(encoding="utf-8"))
else:
tree.write(filepath, encoding="utf-8", xml_declaration=True)
def write_xml(obj, filepath=None, pretty=False):
tree = etree.ElementTree(obj._elem)
if filepath is None:
filepath = obj.filepath
if filepath is None:
raise JUnitXmlError("Missing filepath argument.")
if pretty:
from xml.dom.minidom import parseString
text = etree.tostring(obj._elem)
xml = parseString(text)
with open(filepath, "wb") as xmlfile:
xmlfile.write(xml.toprettyxml(encoding="utf-8"))
else:
tree.write(filepath, encoding="utf-8", xml_declaration=True)
def result(self):
"""One of the Failure, Skipped, or Error objects."""
results = []
for res in POSSIBLE_RESULTS:
result = self.child(res)
if result is not None:
results.append(result)
if len(results) > 1:
raise JUnitXmlError("Only one result allowed per test case.")
elif len(results) == 0:
return None
else:
return results[0]
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 result(self):
"""One of the Failure, Skipped, or Error objects."""
results = []
for res in POSSIBLE_RESULTS:
result = self.child(res)
if result is not None:
results.append(result)
if len(results) > 1:
raise JUnitXmlError("Only one result allowed per test case.")
elif len(results) == 0:
return None
else:
return results[0]