llvm.org GIT mirror llvm / 9470bd6
Refactor xunit test case builder to not use as much str addition String concatenation in python is slow. Refactor to not concatenate the possibly large strings of test output and instead write them directly to the output file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332064 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Matthews 1 year, 6 months ago
2 changed file(s) with 12 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
359359 """
360360 return self.suite.config.is_early
361361
362 def getJUnitXML(self):
362 def writeJUnitXML(self, fil):
363 """Write the test's report xml representation to a file handle."""
363364 test_name = escape(self.path_in_suite[-1])
364365 test_path = self.path_in_suite[:-1]
365366 safe_test_path = [x.replace(".","_") for x in test_path]
369370 class_name = safe_name + "." + "/".join(safe_test_path)
370371 else:
371372 class_name = safe_name + "." + safe_name
372
373 xml = "
375 xml += " time='{:.2f}'".format(
376 self.result.elapsed if self.result.elapsed is not None else 0.0)
373 testcase_template = u"
374 elapsed_time = self.result.elapsed if self.result.elapsed is not None else 0.0
375 testcase_xml = testcase_template.format(class_name=class_name, test_name=test_name, time=elapsed_time)
376 fil.write(testcase_xml)
377377 if self.result.code.isFailure:
378 xml += ">\n\t\n" + escape(self.result.output)
379 xml += "\n\t\n"
378 fil.write(">\n\t\n")
379 fil.write(escape(self.result.output))
380 fil.write("\n\t\n")
380381 else:
381 xml += "/>"
382 return xml
382 fil.write("/>")
613613 xunit_output_file.write(" failures='" + str(suite['failures']) +
614614 "'>\n")
615615 for result_test in suite['tests']:
616 xunit_output_file.write(result_test.getJUnitXML() + "\n")
616 result_test.writeJUnitXML(xunit_output_file)
617 xunit_output_file.write("\n")
617618 xunit_output_file.write("\n")
618619 xunit_output_file.write("")
619620 xunit_output_file.close()