Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: scripts/slave/recipe_modules/chromium_android/resources/test_results_presentation.py

Issue 2224173002: Added different colors for success/failure and code search. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: fixes Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 11
12 # Load jinja2. 12 # Load jinja2.
13 CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) 13 CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
14 BASE_DIR = os.path.abspath(os.path.join( 14 BASE_DIR = os.path.abspath(os.path.join(
15 CURRENT_DIR, '..', '..', '..', '..', '..')) 15 CURRENT_DIR, '..', '..', '..', '..', '..'))
16 sys.path.append(os.path.join(BASE_DIR, 'third_party', 'markupsafe')) 16 sys.path.append(os.path.join(BASE_DIR, 'third_party', 'markupsafe'))
17 sys.path.append(os.path.join(BASE_DIR, 'third_party', 'jinja2')) 17 sys.path.append(os.path.join(BASE_DIR, 'third_party', 'jinja2'))
18 import jinja2 18 import jinja2
19 jinja_environment = jinja2.Environment( 19 jinja_environment = jinja2.Environment(
20 loader = jinja2.FileSystemLoader(os.path.dirname(__file__))) 20 loader = jinja2.FileSystemLoader(os.path.dirname(__file__)))
21 21
22 # Get result details from json path and then convert results to html. 22 # Get result details from json path and then convert results to html.
23 def result_details(json_path): 23 def result_details(json_path, cs_base_url):
24 with open(json_path) as json_file: 24 with open(json_path) as json_file:
25 json_object = json.loads(json_file.read()) 25 json_object = json.loads(json_file.read())
26 results_list = [] 26 results_list = []
27 for testsuite_run in json_object['per_iteration_data']: 27 for testsuite_run in json_object['per_iteration_data']:
28 for test, test_runs in testsuite_run.iteritems(): 28 for test, test_runs in testsuite_run.iteritems():
29 results_list.extend([ 29 results_list.extend([
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, cs_base_url)
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, cs_base_url):
40 def code_search(test):
41 search = test.replace('#', '.')
42 url = cs_base_url if cs_base_url else 'https://cs.chromium.org'
mikecase (-- gone --) 2016/08/12 18:58:52 Should probably either set http://cs.chromium.or
BigBossZhiling 2016/08/12 21:23:03 Done.
43 return '%s/?q=%s&type=cs' % (url, search)
44
40 suite_row_dict = {} 45 suite_row_dict = {}
41 test_row_list = [] 46 test_row_list = []
42 for result in results: 47 for result in results:
43 data = [{'data': result['name'], 'class': 'align-left'}, 48 # Constructing test_row_list.
44 {'data': result['status'], 'class': 'align-center'}, 49 data = [{'data': result['name'], 'class': 'left',
45 {'data': result['duration'], 'class': 'align-center'}, 50 'link': code_search(result['name'])},
46 {'data': result['output_snippet'], 'class': 'align-left is-pre'}] 51 {'data': result['status'],
52 'class': 'center ' + result['status'].lower()},
53 {'data': result['duration'], 'class': 'center'},
54 {'data': result['output_snippet'],
55 'class': 'left', 'is_pre': True}]
47 56
48 test_row_list.append(data) 57 test_row_list.append(data)
49 suite_name = result['name'][:result['name'].index('#')]
50 58
59 # Constructing suite_row_dict
60 test_case_path = result['name']
61 suite_name = test_case_path[:test_case_path.index('#')]
mikecase (-- gone --) 2016/08/12 18:58:52 super nit: I usually this this done by... test_c
BigBossZhiling 2016/08/12 21:23:03 Done.
51 # 'suite_row' is [name, success_count, fail_count, all_count, time]. 62 # 'suite_row' is [name, success_count, fail_count, all_count, time].
52 SUCCESS_COUNT = 1 63 SUCCESS_COUNT = 1
53 FAIL_COUNT = 2 64 FAIL_COUNT = 2
54 ALL_COUNT = 3 65 ALL_COUNT = 3
55 TIME = 4 66 TIME = 4
56 67
57 if suite_name in suite_row_dict: 68 if suite_name in suite_row_dict:
58 suite_row = suite_row_dict[suite_name] 69 suite_row = suite_row_dict[suite_name]
59 else: 70 else:
60 suite_row = [{'data': suite_name, 'class' : 'align-left'}, 71 suite_row = [{'data': suite_name, 'class' : 'left'},
61 {'data': 0, 'class': 'align-center'}, 72 {'data': 0, 'class': 'center'},
62 {'data': 0, 'class': 'align-center'}, 73 {'data': 0, 'class': 'center'},
63 {'data': 0, 'class': 'align-center'}, 74 {'data': 0, 'class': 'center'},
64 {'data': 0, 'class': 'align-center'}] 75 {'data': 0, 'class': 'center'}]
65 suite_row_dict[suite_name] = suite_row 76 suite_row_dict[suite_name] = suite_row
66 77
67 suite_row[ALL_COUNT]['data'] += 1 78 suite_row[ALL_COUNT]['data'] += 1
68 if result['status'] == 'SUCCESS': 79 if result['status'] == 'SUCCESS':
69 suite_row[SUCCESS_COUNT]['data'] += 1 80 suite_row[SUCCESS_COUNT]['data'] += 1
70 elif result['status'] == 'FAILURE': 81 elif result['status'] == 'FAILURE':
71 suite_row[FAIL_COUNT]['data'] += 1 82 suite_row[FAIL_COUNT]['data'] += 1
72 suite_row[TIME]['data'] += result['duration'] 83 suite_row[TIME]['data'] += result['duration']
73 84
85 for suite in suite_row_dict.values():
86 if suite[FAIL_COUNT]['data'] > 0:
87 suite[FAIL_COUNT]['class'] += ' failure'
88 else:
89 suite[FAIL_COUNT]['class'] += ' success'
90
74 test_table_values = { 91 test_table_values = {
75 'table_id' : 'test_table', 92 'table_id' : 'test_table',
76 'table_headers' : [('text', 'test_name'), 93 'table_headers' : [('text', 'test_name'),
77 ('text', 'status'), 94 ('text', 'status'),
78 ('number', 'duration'), 95 ('number', 'duration'),
79 ('text', 'output_snippet'), 96 ('text', 'output_snippet'),
80 ], 97 ],
81 'table_rows' : test_row_list, 98 'table_rows' : test_row_list,
82 } 99 }
83 100
(...skipping 12 matching lines...) Expand all
96 os.path.join('template', 'main.html')) 113 os.path.join('template', 'main.html'))
97 return main_template.render( 114 return main_template.render(
98 {'tb_values': [suite_table_values, test_table_values]}) 115 {'tb_values': [suite_table_values, test_table_values]})
99 116
100 def main(): 117 def main():
101 logging.basicConfig(level=logging.INFO) 118 logging.basicConfig(level=logging.INFO)
102 parser = argparse.ArgumentParser() 119 parser = argparse.ArgumentParser()
103 parser.add_argument('--json-file', help='Path of json file.', required=True) 120 parser.add_argument('--json-file', help='Path of json file.', required=True)
104 parser.add_argument('--html-file', help='Path to store html file.', 121 parser.add_argument('--html-file', help='Path to store html file.',
105 required=True) 122 required=True)
123 parser.add_argument('--cs-base-url', help='Base url for code search.')
mikecase (-- gone --) 2016/08/12 18:58:52 consider adding cs.chromium.org the default arg va
BigBossZhiling 2016/08/12 21:23:03 Done.
124
106 args = parser.parse_args() 125 args = parser.parse_args()
107 if os.path.exists(args.json_file): 126 if os.path.exists(args.json_file):
108 result_html_string = result_details(args.json_file) 127 result_html_string = result_details(args.json_file, args.cs_base_url)
109 128
110 with open(args.html_file, 'w') as html: 129 with open(args.html_file, 'w') as html:
111 html.write(result_html_string) 130 html.write(result_html_string)
112 else: 131 else:
113 raise exception('Json file of result details is not found.') 132 raise Exception('Json file of result details is not found.')
114 133
115 if __name__ == '__main__': 134 if __name__ == '__main__':
116 sys.exit(main()) 135 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698