Clone of official tools
Diff: test_exporters.py
- Revision:
- 13:ab47a20b66f0
- Parent:
- 0:66f3b5499f7f
- Child:
- 22:9e85236d8716
--- a/test_exporters.py Tue Jun 14 11:33:06 2016 +0100 +++ b/test_exporters.py Thu Jul 14 20:21:19 2016 +0100 @@ -17,8 +17,8 @@ Author: Przemyslaw Wirkus <Przemyslaw.wirkus@arm.com> """ -from tools.utils import construct_enum - +from tools.utils import construct_enum, mkdir +import os ResultExporterType = construct_enum(HTML='Html_Exporter', JUNIT='JUnit_Exporter', @@ -72,7 +72,8 @@ self.result_exporter_type = result_exporter_type self.package = package - def report(self, test_summary_ext, test_suite_properties=None): + def report(self, test_summary_ext, test_suite_properties=None, + print_log_for_failures=True): """ Invokes report depending on exporter_type set in constructor """ if self.result_exporter_type == ResultExporterType.HTML: @@ -86,7 +87,7 @@ return self.exporter_junit_ioper(test_summary_ext, test_suite_properties) elif self.result_exporter_type == ResultExporterType.PRINT: # JUNIT exporter for interoperability test - return self.exporter_print(test_summary_ext) + return self.exporter_print(test_summary_ext, print_log_for_failures=print_log_for_failures) return None def report_to_file(self, test_summary_ext, file_name, test_suite_properties=None): @@ -97,6 +98,9 @@ def write_to_file(self, report, file_name): if report is not None: + dirname = os.path.dirname(file_name) + if dirname: + mkdir(dirname) with open(file_name, 'w') as f: f.write(report) @@ -191,10 +195,11 @@ unique_test_ids = self.get_all_unique_test_ids(test_result_ext) targets = sorted(test_result_ext.keys()) - result += '<table><tr>' + result += '<table>' for target in targets: toolchains = sorted(test_result_ext[target].keys()) for toolchain in toolchains: + result += '<tr>' result += '<td></td>' result += '<td></td>' @@ -293,11 +298,15 @@ test_suites.append(ts) return TestSuite.to_xml_string(test_suites) - def exporter_print_helper(self, array): + def exporter_print_helper(self, array, print_log=False): for item in array: print " * %s::%s::%s" % (item["target_name"], item["toolchain_name"], item["id"]) + if print_log: + log_lines = item["output"].split("\n") + for log_line in log_lines: + print " %s" % log_line - def exporter_print(self, test_result_ext): + def exporter_print(self, test_result_ext, print_log_for_failures=False): """ Export test results in print format. """ failures = [] @@ -316,15 +325,18 @@ for test_runner in test_runs: #test_run = test_result_ext[target][toolchain][test][test_run_number][0] test_run = test_runner[0] - - if test_run["result"] == "FAIL": - failures.append(test_run) - elif test_run["result"] == "SKIP" or test_run["result"] == "NOT_SUPPORTED": - skips.append(test_run) - elif test_run["result"] == "OK": - successes.append(test_run) + + if "result" in test_run: + if test_run["result"] == "FAIL": + failures.append(test_run) + elif test_run["result"] == "SKIP" or test_run["result"] == "NOT_SUPPORTED": + skips.append(test_run) + elif test_run["result"] == "OK": + successes.append(test_run) + else: + raise Exception("Unhandled result type: %s" % (test_run["result"])) else: - raise Exception("Unhandled result type: %s" % (test_run["result"])) + raise Exception("'test_run' did not have a 'result' value") if successes: print "\n\nBuild successes:" @@ -336,7 +348,7 @@ if failures: print "\n\nBuild failures:" - self.exporter_print_helper(failures) + self.exporter_print_helper(failures, print_log=print_log_for_failures) return False else: return True