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 19 matching lines...) Expand all Loading... | |
| 30 { | 30 { |
| 31 'name': test, | 31 'name': test, |
| 32 'status': tr['status'], | 32 'status': tr['status'], |
| 33 'duration': tr['elapsed_time_ms'], | 33 'duration': tr['elapsed_time_ms'], |
| 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) | 36 return results_to_html(results_list) |
| 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): | 39 def results_to_html(results): |
| 40 def code_search(test): | |
|
the real yoland
2016/08/08 22:34:51
nice, this is much cleaner than my idea of using j
BigBossZhiling
2016/08/10 20:17:00
Acknowledged.
| |
| 41 search = test.replace('#', '.') | |
| 42 return 'https://cs.corp.google.com/search/?q=%s&type=cs' % search | |
|
the real yoland
2016/08/08 22:34:51
this is a bit tricky, because internal links can't
BigBossZhiling
2016/08/10 20:16:59
Done.
| |
| 40 suite_row_dict = {} | 43 suite_row_dict = {} |
| 41 test_row_list = [] | 44 test_row_list = [] |
| 42 for result in results: | 45 for result in results: |
| 43 data = [{'data': result['name'], 'class': 'align-left'}, | 46 data = [{'data': result['name'], 'class': 'left', |
|
the real yoland
2016/08/08 22:34:51
nit: extra space
BigBossZhiling
2016/08/10 20:17:00
Done.
| |
| 44 {'data': result['status'], 'class': 'align-center'}, | 47 'link': code_search(result['name'])}, |
| 45 {'data': result['duration'], 'class': 'align-center'}, | 48 {'data': result['status'], |
| 46 {'data': result['output_snippet'], 'class': 'align-left is-pre'}] | 49 'class': 'center ' + result['status'].lower()}, |
| 50 {'data': result['duration'], 'class': 'center'}, | |
| 51 {'data': result['output_snippet'], | |
| 52 'class': 'left', 'is_pre': True}] | |
| 47 | 53 |
| 48 test_row_list.append(data) | 54 test_row_list.append(data) |
| 49 suite_name = result['name'][:result['name'].index('#')] | 55 suite_name = result['name'][:result['name'].index('#')] |
|
the real yoland
2016/08/08 22:34:50
nit: add the comment here to separate construction
BigBossZhiling
2016/08/10 20:16:59
Done.
| |
| 50 | 56 |
| 51 # 'suite_row' is [name, success_count, fail_count, all_count, time]. | 57 # 'suite_row' is [name, success_count, fail_count, all_count, time]. |
| 52 SUCCESS_COUNT = 1 | 58 SUCCESS_COUNT = 1 |
| 53 FAIL_COUNT = 2 | 59 FAIL_COUNT = 2 |
| 54 ALL_COUNT = 3 | 60 ALL_COUNT = 3 |
| 55 TIME = 4 | 61 TIME = 4 |
| 56 | 62 |
| 57 if suite_name in suite_row_dict: | 63 if suite_name in suite_row_dict: |
| 58 suite_row = suite_row_dict[suite_name] | 64 suite_row = suite_row_dict[suite_name] |
| 59 else: | 65 else: |
| 60 suite_row = [{'data': suite_name, 'class' : 'align-left'}, | 66 suite_row = [{'data': suite_name, 'class' : 'left'}, |
| 61 {'data': 0, 'class': 'align-center'}, | 67 {'data': 0, 'class': 'center'}, |
| 62 {'data': 0, 'class': 'align-center'}, | 68 {'data': 0, 'class': 'center'}, |
| 63 {'data': 0, 'class': 'align-center'}, | 69 {'data': 0, 'class': 'center'}, |
| 64 {'data': 0, 'class': 'align-center'}] | 70 {'data': 0, 'class': 'center'}] |
| 65 suite_row_dict[suite_name] = suite_row | 71 suite_row_dict[suite_name] = suite_row |
| 66 | 72 |
| 67 suite_row[ALL_COUNT]['data'] += 1 | 73 suite_row[ALL_COUNT]['data'] += 1 |
| 68 if result['status'] == 'SUCCESS': | 74 if result['status'] == 'SUCCESS': |
| 69 suite_row[SUCCESS_COUNT]['data'] += 1 | 75 suite_row[SUCCESS_COUNT]['data'] += 1 |
| 70 elif result['status'] == 'FAILURE': | 76 elif result['status'] == 'FAILURE': |
| 71 suite_row[FAIL_COUNT]['data'] += 1 | 77 suite_row[FAIL_COUNT]['data'] += 1 |
| 72 suite_row[TIME]['data'] += result['duration'] | 78 suite_row[TIME]['data'] += result['duration'] |
| 73 | 79 |
| 80 for suite in suite_row_dict.values(): | |
| 81 if suite[FAIL_COUNT]['data'] > 0: | |
| 82 suite[FAIL_COUNT]['class'] += ' failure' | |
| 83 else: | |
| 84 suite[FAIL_COUNT]['class'] += ' success' | |
| 85 | |
| 74 test_table_values = { | 86 test_table_values = { |
| 75 'table_id' : 'test_table', | 87 'table_id' : 'test_table', |
| 76 'table_headers' : [('text', 'test_name'), | 88 'table_headers' : [('text', 'test_name'), |
| 77 ('text', 'status'), | 89 ('text', 'status'), |
| 78 ('number', 'duration'), | 90 ('number', 'duration'), |
| 79 ('text', 'output_snippet'), | 91 ('text', 'output_snippet'), |
| 80 ], | 92 ], |
| 93 'table_class' : 'info', | |
| 81 'table_rows' : test_row_list, | 94 'table_rows' : test_row_list, |
| 82 } | 95 } |
| 83 | 96 |
| 84 suite_table_values = { | 97 suite_table_values = { |
| 85 'table_id' : 'suite_table', | 98 'table_id' : 'suite_table', |
| 86 'table_headers' : [('text', 'suite_name'), | 99 'table_headers' : [('text', 'suite_name'), |
| 87 ('number', 'number_success_tests'), | 100 ('number', 'number_success_tests'), |
| 88 ('number', 'number_fail_tests'), | 101 ('number', 'number_fail_tests'), |
| 89 ('number', 'all_tests'), | 102 ('number', 'all_tests'), |
| 90 ('number', 'elapsed_time_ms'), | 103 ('number', 'elapsed_time_ms'), |
| 91 ], | 104 ], |
| 105 'table_class' : 'info', | |
| 92 'table_rows' : suite_row_dict.values(), | 106 'table_rows' : suite_row_dict.values(), |
| 93 } | 107 } |
| 94 | 108 |
| 95 main_template = jinja_environment.get_template( | 109 main_template = jinja_environment.get_template( |
| 96 os.path.join('template', 'main.html')) | 110 os.path.join('template', 'main.html')) |
| 97 return main_template.render( | 111 return main_template.render( |
| 98 {'tb_values': [suite_table_values, test_table_values]}) | 112 {'tb_values': [suite_table_values, test_table_values]}) |
| 99 | 113 |
| 100 def main(): | 114 def main(): |
| 101 logging.basicConfig(level=logging.INFO) | 115 logging.basicConfig(level=logging.INFO) |
| 102 parser = argparse.ArgumentParser() | 116 parser = argparse.ArgumentParser() |
| 103 parser.add_argument('--json-file', help='Path of json file.', required=True) | 117 parser.add_argument('--json-file', help='Path of json file.', required=True) |
| 104 parser.add_argument('--html-file', help='Path to store html file.', | 118 parser.add_argument('--html-file', help='Path to store html file.', |
| 105 required=True) | 119 required=True) |
| 106 args = parser.parse_args() | 120 args = parser.parse_args() |
| 107 if os.path.exists(args.json_file): | 121 if os.path.exists(args.json_file): |
| 108 result_html_string = result_details(args.json_file) | 122 result_html_string = result_details(args.json_file) |
| 109 | 123 |
| 110 with open(args.html_file, 'w') as html: | 124 with open(args.html_file, 'w') as html: |
| 111 html.write(result_html_string) | 125 html.write(result_html_string) |
| 112 else: | 126 else: |
| 113 raise exception('Json file of result details is not found.') | 127 raise Exception('Json file of result details is not found.') |
| 114 | 128 |
| 115 if __name__ == '__main__': | 129 if __name__ == '__main__': |
| 116 sys.exit(main()) | 130 sys.exit(main()) |
| OLD | NEW |