MCPcopy Index your code
hub / github.com/cpplint/cpplint / FormatJUnitXML

Method FormatJUnitXML

cpplint.py:1511–1552  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1509 self._junit_failures.append((filename, linenum, message, category, confidence))
1510
1511 def FormatJUnitXML(self):
1512 num_errors = len(self._junit_errors)
1513 num_failures = len(self._junit_failures)
1514
1515 testsuite = xml.etree.ElementTree.Element("testsuite")
1516 testsuite.attrib["errors"] = str(num_errors)
1517 testsuite.attrib["failures"] = str(num_failures)
1518 testsuite.attrib["name"] = "cpplint"
1519
1520 if num_errors == 0 and num_failures == 0:
1521 testsuite.attrib["tests"] = str(1)
1522 xml.etree.ElementTree.SubElement(testsuite, "testcase", name="passed")
1523
1524 else:
1525 testsuite.attrib["tests"] = str(num_errors + num_failures)
1526 if num_errors > 0:
1527 testcase = xml.etree.ElementTree.SubElement(testsuite, "testcase")
1528 testcase.attrib["name"] = "errors"
1529 error = xml.etree.ElementTree.SubElement(testcase, "error")
1530 error.text = "\n".join(self._junit_errors)
1531 if num_failures > 0:
1532 # Group failures by file
1533 failed_file_order = []
1534 failures_by_file = {}
1535 for failure in self._junit_failures:
1536 failed_file = failure[0]
1537 if failed_file not in failed_file_order:
1538 failed_file_order.append(failed_file)
1539 failures_by_file[failed_file] = []
1540 failures_by_file[failed_file].append(failure)
1541 # Create a testcase for each file
1542 for failed_file in failed_file_order:
1543 failures = failures_by_file[failed_file]
1544 testcase = xml.etree.ElementTree.SubElement(testsuite, "testcase")
1545 testcase.attrib["name"] = failed_file
1546 failure = xml.etree.ElementTree.SubElement(testcase, "failure")
1547 template = "{0}: {1} [{2}] [{3}]"
1548 texts = [template.format(f[1], f[2], f[3], f[4]) for f in failures]
1549 failure.text = "\n".join(texts)
1550
1551 xml_decl = '<?xml version="1.0" encoding="UTF-8" ?>\n'
1552 return xml_decl + xml.etree.ElementTree.tostring(testsuite, "utf-8").decode("utf-8")
1553
1554
1555_cpplint_state = _CppLintState()

Callers 2

testJUnitXMLMethod · 0.80
mainFunction · 0.80

Calls

no outgoing calls

Tested by 1

testJUnitXMLMethod · 0.64