OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """A Module for LayoutTestAnalyzer main functions.""" | |
dennis_jeffrey
2011/08/24 17:40:47
'Main functions for the Layout Test Analyzer modul
imasaki1
2011/08/25 23:57:03
Done.
| |
7 | |
8 import csv | |
9 from datetime import datetime | |
10 import optparse | |
11 import os | |
12 import pickle | |
13 import time | |
14 | |
15 | |
16 from layouttests import LayoutTests | |
17 import layouttest_analyzer_helpers | |
18 from layouttest_analyzer_helpers import AnalyzerResultMap | |
dennis_jeffrey
2011/08/24 17:40:47
We probably don't need this if you already import
imasaki1
2011/08/25 23:57:03
Done.
| |
19 from test_expectations import TestExpectations | |
20 from trend_graph import TrendGraph | |
21 | |
22 # Predefined result directory. | |
23 RESULT_DIR = 'result' | |
24 | |
25 | |
26 def parse_option(): | |
27 """Parse command-line options using OptionParser. | |
28 | |
29 Returns: | |
30 options which contains all command-line option information. | |
dennis_jeffrey
2011/08/24 17:40:47
'options which contains' -->
'an object containing
imasaki1
2011/08/25 23:57:03
Done.
| |
31 """ | |
32 option_parser = optparse.OptionParser() | |
33 | |
34 option_parser.add_option('-r', '--receiver-email-address', | |
35 dest='receiver_email_address', | |
36 help="reciever's email adddress", | |
dennis_jeffrey
2011/08/24 17:40:47
might want to mention the default in this help str
imasaki1
2011/08/25 23:57:03
Done.
| |
37 default='imasaki@chromium.org') | |
38 option_parser.add_option('-g', '--debug-mode', dest='debug', | |
39 help=('Debug mode is used when you want to debug ' | |
40 'the analyzer by using local file rather ' | |
41 'than getting data from SVN. This shortens ' | |
42 'the debugging time.'), | |
43 action='store_true', default=False) | |
44 option_parser.add_option('-t', '--trend-graph-location', | |
45 dest='trend_graph_location', | |
46 help='trend graph location', metavar='FILE', | |
dennis_jeffrey
2011/08/24 17:40:47
might want to mention this default in this help st
imasaki1
2011/08/25 23:57:03
Done.
| |
47 default=os.path.join('graph', 'graph.html')) | |
48 option_parser.add_option('-a', '--bug-anno-file-location', | |
49 dest='bug_annotation_file_location', | |
50 help='bug annotation file location in CSV format', | |
dennis_jeffrey
2011/08/24 17:40:47
might want to mention this default in this help st
imasaki1
2011/08/25 23:57:03
Done.
| |
51 default=os.path.join('anno', 'anno.csv')) | |
52 (options, _) = option_parser.parse_args() | |
53 return options | |
dennis_jeffrey
2011/08/24 17:40:47
maybe combine the above 2 lines into this?
return
imasaki1
2011/08/25 23:57:03
Done.
| |
54 | |
55 | |
56 def main(): | |
57 """A main function for the analyzer.""" | |
58 options = parse_option() | |
59 t = datetime.now() | |
dennis_jeffrey
2011/08/24 17:40:47
maybe use a more descriptive variable name than 't
imasaki1
2011/08/25 23:57:03
Done.
| |
60 | |
61 # Do the main analysis. | |
62 if not options.debug: | |
63 layouttests = LayoutTests(csv_file_path=os.path.join('testname', | |
64 'media.csv')) | |
65 test_expectations = TestExpectations() | |
66 test_info_map = layouttests.JoinWithTestExpectation(test_expectations) | |
dennis_jeffrey
2011/08/24 17:40:47
Maybe combine the above 2 lines?
test_info_map =
imasaki1
2011/08/25 23:57:03
Done.
| |
67 analyzer_result_map = AnalyzerResultMap(test_info_map) | |
68 (prev_time, prev_analyzer_result_map) = ( | |
69 layouttest_analyzer_helpers.FindLatestResult('result')) | |
70 else: | |
71 analyzer_result_map = AnalyzerResultMap.Load(os.path.join(RESULT_DIR, | |
72 '2011-08-19-21')) | |
73 prev_time = '2011-08-19-11' | |
dennis_jeffrey
2011/08/24 17:40:47
you might want to consider making these date folde
imasaki1
2011/08/25 23:57:03
Done.
| |
74 prev_analyzer_result_map = AnalyzerResultMap.Load(os.path.join(RESULT_DIR, | |
75 '2011-08-19-11')) | |
dennis_jeffrey
2011/08/24 17:40:47
use "prev_time" instead here. Also fix the indent
imasaki1
2011/08/25 23:57:03
Done.
| |
76 | |
77 # Read bug annotations and generate a annotation map used for the status | |
dennis_jeffrey
2011/08/24 17:40:47
nit: 'a' --> 'an'
imasaki1
2011/08/25 23:57:03
Done.
| |
78 # email. | |
79 anno_map = {} | |
80 file_object = open(options.bug_annotation_file_location) | |
81 data = csv.reader(file_object) | |
82 for row in data: | |
83 anno_map[row[0]] = row[1] | |
84 file_object.close() | |
85 | |
86 layouttest_analyzer_helpers.SendStatusEmail(prev_time, analyzer_result_map, | |
87 prev_analyzer_result_map, | |
88 anno_map, | |
89 options.receiver_email_address) | |
90 if not options.debug: | |
91 # Save the current result. | |
92 date = t.strftime('%Y-%m-%d-%H') | |
93 file_path = os.path.join(RESULT_DIR, date) | |
94 analyzer_result_map.Save(file_path) | |
95 | |
96 # Trend graph update (if specified in the command-line argument). | |
97 trend_graph = TrendGraph(options.trend_graph_location) | |
98 datetime_string = t.strftime('%Y,%m,%d,%H,%M,%S') | |
99 # TODO(imasaki): add correct title and text instead of 'undefined'. | |
100 data_map = ( | |
101 {'whole': (str(len(analyzer_result_map.result_map['whole'].keys())), | |
102 'undefined', 'undefined'), | |
103 'skip': (str(len(analyzer_result_map.result_map['skip'].keys())), | |
104 'undefined', 'undefined'), | |
105 'nonskip': (str(len(analyzer_result_map.result_map['nonskip'].keys())), | |
106 'undefined', 'undefined'), | |
107 'passingrate': (str(analyzer_result_map.GetPassingRate()), | |
108 'undefined', 'undefined')}) | |
dennis_jeffrey
2011/08/24 17:40:47
nit: indent this line by 1 more space to make it c
imasaki1
2011/08/25 23:57:03
Done.
| |
109 trend_graph.Update(datetime_string, data_map) | |
110 | |
111 | |
112 if '__main__' == __name__: | |
113 main() | |
dennis_jeffrey
2011/08/24 17:40:47
nit: only indent this line 2 spaces, not 4.
imasaki1
2011/08/25 23:57:03
Done.
| |
OLD | NEW |