Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All Rights Reserved. | 2 # Copyright 2016 The Chromium Authors. All Rights Reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import argparse | 6 import argparse |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 'output_snippet' : tr['output_snippet'] | 34 'output_snippet' : tr['output_snippet'] |
| 35 } for tr in test_runs]) | 35 } for tr in test_runs]) |
| 36 return results_to_html(results_list, cs_base_url, master_name) | 36 return results_to_html(results_list, cs_base_url, master_name) |
| 37 | 37 |
| 38 # Convert list of test results into html format. | 38 # Convert list of test results into html format. |
| 39 def results_to_html(results, cs_base_url, master_name): | 39 def results_to_html(results, cs_base_url, master_name): |
| 40 def code_search(test): | 40 def code_search(test): |
| 41 search = test.replace('#', '.') | 41 search = test.replace('#', '.') |
| 42 return '%s/?q=%s&type=cs' % (cs_base_url, search) | 42 return '%s/?q=%s&type=cs' % (cs_base_url, search) |
| 43 | 43 |
| 44 # Summary of all suites. | |
| 45 suites_summary = [{'data': 'TOTAL', 'class' : 'center', | |
| 46 'action': 'showAllTests();'}, | |
| 47 {'data': 0, 'class': 'center'}, | |
| 48 {'data': 0, 'class': 'center'}, | |
| 49 {'data': 0, 'class': 'center'}, | |
| 50 {'data': 0, 'class': 'center'}] | |
| 51 | |
| 44 suite_row_dict = {} | 52 suite_row_dict = {} |
| 45 test_row_list = [] | 53 test_row_list = [] |
| 46 for result in results: | 54 for result in results: |
| 47 # Constructing test_row_list. | 55 # Constructing test_row_list. |
| 48 data = [{'data': result['name'], 'class': 'left', | 56 test_case = [{'data': result['name'], 'class': 'left', |
| 49 'link': code_search(result['name'])}, | 57 'link': code_search(result['name'])}, |
| 50 {'data': result['status'], | 58 {'data': result['status'], |
| 51 'class': 'center ' + result['status'].lower()}, | 59 'class': 'center ' + result['status'].lower()}, |
| 52 {'data': result['duration'], 'class': 'center'}, | 60 {'data': result['duration'], 'class': 'center'}, |
| 53 {'data': result['output_snippet'], | 61 {'data': result['output_snippet'], |
| 54 'class': 'left', 'is_pre': True}] | 62 'class': 'left', 'is_pre': True}] |
| 63 test_row_list.append(test_case) | |
| 55 | 64 |
| 56 test_row_list.append(data) | 65 # Constructing suite_row_dict and suites_summary |
| 57 | |
| 58 # Constructing suite_row_dict | |
| 59 test_case_path = result['name'] | 66 test_case_path = result['name'] |
| 60 suite_name = test_case_path.split('#')[0] | 67 suite_name = test_case_path.split('#')[0] |
| 61 # 'suite_row' is [name, success_count, fail_count, all_count, time]. | 68 # 'suite_row' is [name, success_count, fail_count, all_count, time]. |
| 62 SUCCESS_COUNT = 1 | 69 SUCCESS_COUNT = 1 |
| 63 FAIL_COUNT = 2 | 70 FAIL_COUNT = 2 |
| 64 ALL_COUNT = 3 | 71 ALL_COUNT = 3 |
| 65 TIME = 4 | 72 TIME = 4 |
| 66 | 73 |
| 67 if suite_name in suite_row_dict: | 74 if suite_name in suite_row_dict: |
| 68 suite_row = suite_row_dict[suite_name] | 75 suite_row = suite_row_dict[suite_name] |
| 69 else: | 76 else: |
| 70 suite_row = [{'data': suite_name, 'class' : 'left'}, | 77 suite_row = [{'data': suite_name, 'class' : 'left', |
| 78 'action': 'showTestsOfOneSuiteOnly(\'%s\');' % suite_name}, | |
|
the real yoland
2016/08/18 20:44:56
I think this is okay, but in general, it's a good
BigBossZhiling
2016/08/23 17:38:51
Done.
| |
| 71 {'data': 0, 'class': 'center'}, | 79 {'data': 0, 'class': 'center'}, |
| 72 {'data': 0, 'class': 'center'}, | 80 {'data': 0, 'class': 'center'}, |
| 73 {'data': 0, 'class': 'center'}, | 81 {'data': 0, 'class': 'center'}, |
| 74 {'data': 0, 'class': 'center'}] | 82 {'data': 0, 'class': 'center'}] |
| 75 suite_row_dict[suite_name] = suite_row | 83 suite_row_dict[suite_name] = suite_row |
| 76 | 84 |
| 77 suite_row[ALL_COUNT]['data'] += 1 | 85 suite_row[ALL_COUNT]['data'] += 1 |
| 86 suites_summary[ALL_COUNT]['data'] += 1 | |
| 78 if result['status'] == 'SUCCESS': | 87 if result['status'] == 'SUCCESS': |
| 79 suite_row[SUCCESS_COUNT]['data'] += 1 | 88 suite_row[SUCCESS_COUNT]['data'] += 1 |
| 89 suites_summary[SUCCESS_COUNT]['data'] += 1 | |
| 80 elif result['status'] == 'FAILURE': | 90 elif result['status'] == 'FAILURE': |
| 81 suite_row[FAIL_COUNT]['data'] += 1 | 91 suite_row[FAIL_COUNT]['data'] += 1 |
| 92 suites_summary[FAIL_COUNT]['data'] += 1 | |
| 82 suite_row[TIME]['data'] += result['duration'] | 93 suite_row[TIME]['data'] += result['duration'] |
| 94 suites_summary[TIME]['data'] += result['duration'] | |
| 83 | 95 |
| 84 for suite in suite_row_dict.values(): | 96 for suite in suite_row_dict.values(): |
| 85 if suite[FAIL_COUNT]['data'] > 0: | 97 if suite[FAIL_COUNT]['data'] > 0: |
| 86 suite[FAIL_COUNT]['class'] += ' failure' | 98 suite[FAIL_COUNT]['class'] += ' failure' |
| 87 else: | 99 else: |
| 88 suite[FAIL_COUNT]['class'] += ' success' | 100 suite[FAIL_COUNT]['class'] += ' success' |
| 101 if suites_summary[FAIL_COUNT]['data'] > 0: | |
| 102 suites_summary[FAIL_COUNT]['class'] += ' failure' | |
| 103 else: | |
| 104 suites_summary[FAIL_COUNT]['class'] += ' success' | |
| 89 | 105 |
| 90 test_table_values = { | 106 test_table_values = { |
| 91 'table_id' : 'test_table', | 107 'table_id' : 'test_table', |
|
the real yoland
2016/08/18 20:44:56
nit: test-table
sorry, didn't notice this one
http
BigBossZhiling
2016/08/23 17:38:51
Done.
| |
| 92 'table_headers' : [('text', 'test_name'), | 108 'table_headers' : [('text', 'test_name'), |
| 93 ('text', 'status'), | 109 ('text', 'status'), |
| 94 ('number', 'duration'), | 110 ('number', 'duration'), |
| 95 ('text', 'output_snippet'), | 111 ('text', 'output_snippet'), |
| 96 ], | 112 ], |
| 97 'table_rows' : test_row_list, | 113 'table_rows' : test_row_list, |
| 98 } | 114 } |
| 99 | 115 |
| 100 suite_table_values = { | 116 suite_table_values = { |
| 101 'table_id' : 'suite_table', | 117 'table_id' : 'suite_table', |
|
the real yoland
2016/08/18 20:44:56
suite-table
| |
| 102 'table_headers' : [('text', 'suite_name'), | 118 'table_headers' : [('text', 'suite_name'), |
| 103 ('number', 'number_success_tests'), | 119 ('number', 'number_success_tests'), |
| 104 ('number', 'number_fail_tests'), | 120 ('number', 'number_fail_tests'), |
| 105 ('number', 'all_tests'), | 121 ('number', 'all_tests'), |
| 106 ('number', 'elapsed_time_ms'), | 122 ('number', 'elapsed_time_ms'), |
| 107 ], | 123 ], |
| 108 'table_rows' : suite_row_dict.values(), | 124 'table_rows' : suite_row_dict.values(), |
| 125 'summary' : suites_summary, | |
| 109 } | 126 } |
| 110 | 127 |
| 111 main_template = jinja_environment.get_template( | 128 main_template = jinja_environment.get_template( |
| 112 os.path.join('template', 'main.html')) | 129 os.path.join('template', 'main.html')) |
| 113 return main_template.render( | 130 return main_template.render( |
| 114 {'tb_values': [suite_table_values, test_table_values], | 131 {'tb_values': [suite_table_values, test_table_values], |
| 115 'master_name': master_name}) | 132 'master_name': master_name}) |
| 116 | 133 |
| 117 def main(): | 134 def main(): |
| 118 logging.basicConfig(level=logging.INFO) | 135 logging.basicConfig(level=logging.INFO) |
| 119 parser = argparse.ArgumentParser() | 136 parser = argparse.ArgumentParser() |
| 120 parser.add_argument('--json-file', help='Path of json file.', required=True) | 137 parser.add_argument('--json-file', help='Path of json file.', required=True) |
| 121 parser.add_argument('--html-file', help='Path to store html file.', | 138 parser.add_argument('--html-file', help='Path to store html file.', |
| 122 required=True) | 139 required=True) |
| 123 parser.add_argument('--cs-base-url', help='Base url for code search.', | 140 parser.add_argument('--cs-base-url', help='Base url for code search.', |
| 124 default='http://cs.chromium.org') | 141 default='http://cs.chromium.org') |
| 125 parser.add_argument('--master-name', help='Master name in urls.') | 142 parser.add_argument('--master-name', help='Master name in urls.') |
| 126 | 143 |
| 127 args = parser.parse_args() | 144 args = parser.parse_args() |
| 128 if os.path.exists(args.json_file): | 145 if os.path.exists(args.json_file): |
| 129 result_html_string = result_details(args.json_file, args.cs_base_url, | 146 result_html_string = result_details(args.json_file, args.cs_base_url, |
| 130 args.master_name) | 147 args.master_name) |
| 131 | |
| 132 with open(args.html_file, 'w') as html: | 148 with open(args.html_file, 'w') as html: |
| 133 html.write(result_html_string) | 149 html.write(result_html_string) |
| 134 else: | 150 else: |
| 135 raise Exception('Json file of result details is not found.') | 151 raise Exception('Json file of result details is not found.') |
| 136 | 152 |
| 137 if __name__ == '__main__': | 153 if __name__ == '__main__': |
| 138 sys.exit(main()) | 154 sys.exit(main()) |
| OLD | NEW |