MCPcopy Create free account
hub / github.com/alibaba/GraphScope / FormatJUnitXML

Method FormatJUnitXML

analytical_engine/misc/cpplint.py:1373–1414  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1371 confidence))
1372
1373 def FormatJUnitXML(self):
1374 num_errors = len(self._junit_errors)
1375 num_failures = len(self._junit_failures)
1376
1377 testsuite = xml.etree.ElementTree.Element('testsuite')
1378 testsuite.attrib['errors'] = str(num_errors)
1379 testsuite.attrib['failures'] = str(num_failures)
1380 testsuite.attrib['name'] = 'cpplint'
1381
1382 if num_errors == 0 and num_failures == 0:
1383 testsuite.attrib['tests'] = str(1)
1384 xml.etree.ElementTree.SubElement(testsuite, 'testcase', name='passed')
1385
1386 else:
1387 testsuite.attrib['tests'] = str(num_errors + num_failures)
1388 if num_errors > 0:
1389 testcase = xml.etree.ElementTree.SubElement(testsuite, 'testcase')
1390 testcase.attrib['name'] = 'errors'
1391 error = xml.etree.ElementTree.SubElement(testcase, 'error')
1392 error.text = '\n'.join(self._junit_errors)
1393 if num_failures > 0:
1394 # Group failures by file
1395 failed_file_order = []
1396 failures_by_file = {}
1397 for failure in self._junit_failures:
1398 failed_file = failure[0]
1399 if failed_file not in failed_file_order:
1400 failed_file_order.append(failed_file)
1401 failures_by_file[failed_file] = []
1402 failures_by_file[failed_file].append(failure)
1403 # Create a testcase for each file
1404 for failed_file in failed_file_order:
1405 failures = failures_by_file[failed_file]
1406 testcase = xml.etree.ElementTree.SubElement(testsuite, 'testcase')
1407 testcase.attrib['name'] = failed_file
1408 failure = xml.etree.ElementTree.SubElement(testcase, 'failure')
1409 template = '{0}: {1} [{2}] [{3}]'
1410 texts = [template.format(f[1], f[2], f[3], f[4]) for f in failures]
1411 failure.text = '\n'.join(texts)
1412
1413 xml_decl = '<?xml version="1.0" encoding="UTF-8" ?>\n'
1414 return xml_decl + xml.etree.ElementTree.tostring(testsuite, 'utf-8').decode('utf-8')
1415
1416
1417_cpplint_state = _CppLintState()

Callers 1

mainFunction · 0.80

Calls 4

appendMethod · 0.65
joinMethod · 0.45
formatMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected