This method is about 50% faster than the existing implementation which uses junit.py.
Signed-off-by: Dylan Baker <[email protected]> --- framework/summary.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/framework/summary.py b/framework/summary.py index 40f5ec0..9ceb3ba 100644 --- a/framework/summary.py +++ b/framework/summary.py @@ -808,3 +808,58 @@ class NewSummary: file.write(empty_status.render(page=page, pages=pages)) file.close() + + def generateJUnit(self, destination): + """ + Public: Generate JUnit XML output with mako + + This method only works when a single resultsfile is given, and has no + way to do comparisons. + """ + # Since JUnit only hanles one result, set a short name for that result + result = self.results[0].tests + + xmlOutput = [] + + def get_class(input): + """ + Helper method that takes the test as an input and returns in in + class form (foo.bar.oink) + + Essentially replaces '/' with '.', but also replaces any '.' + already in the test names with '_', since '.' is special in JUnit. + """ + + input.replace('.', '_') # replace . with _ + out = input.split('/') # create a list splitting on / + out.insert(0, 'piglit') # insert piglit at the front + out.pop() # Remove the extrea '' + return ".".join(out) + + def get_name(input): + """ + Helper that splits just the name out of the full test path + """ + + return input.split('/')[-1] + + # Build a list with all of the information that mako is going to need + # to generate the XML + for test in self.tests['all']: + xmlOutput.append({'classname': get_class(test). + encode('utf-8', 'xmlcharrefreplace'), + 'testname': get_name(test). + encode('utf-8', 'xmlcharrefreplace'), + 'time': result[test]['time'], + 'system-out': result[test]['command']. + encode('utf-8', 'xmlcharrefreplace'), + 'system-err': result[test]['info']. + encode('utf-8', 'xmlcharrefreplace')}) + + # Use mako to generate the XML + template = Template(filename="templates/junit.mako", + output_encoding="utf-8", + module_directory=".makotmp") + file = open(destination, 'w') + file.write(template.render(tests=xmlOutput)) + file.close() -- 1.8.1.4 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
