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

Side by Side Diff: components/test/data/password_manager/automated_tests/run_tests.py

Issue 977043003: [Password manager tests] Provide default config values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 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 """This file allows the bots to be easily configure and run the tests. 6 """This file allows the bots to be easily configure and run the tests.
engedy 2015/03/04 13:20:30 nit: configured
vabr (Chromium) 2015/03/04 13:25:34 Done.
7 7
8 Running this script requires passing --config-path with a path to a config file 8 Running this script requires passing --config-path with a path to a config file
9 of the following structure: 9 of the following structure:
engedy 2015/03/04 13:20:31 nit: Add newline here.
vabr (Chromium) 2015/03/04 13:25:34 Done.
10 [data_files] 10 [data_files]
11 passwords_path=<path to a file with passwords> 11 passwords_path=<path to a file with passwords>
12 [binaries] 12 [binaries]
13 chrome-path=<chrome binary path> 13 chrome-path=<chrome binary path>
14 chromedriver-path=<chrome driver path> 14 chromedriver-path=<chrome driver path>
15 [run_options] 15 [run_options]
16 # |write_to_sheet| is optional, the default value is false.
16 write_to_sheet=[false|true] 17 write_to_sheet=[false|true]
17 tests_in_parrallel=<number of parallel tests> 18 # |tests_in_parallel| is optional, the default value is 1.
19 tests_in_parallel=<number of parallel tests>
18 # |tests_to_runs| field is optional, if it is absent all tests will be run. 20 # |tests_to_runs| field is optional, if it is absent all tests will be run.
19 tests_to_run=<test names to run, comma delimited> 21 tests_to_run=<test names to run, comma delimited>
20 [output] 22 [output]
23 # |save-path| is optional, the default value is /dev/null.
21 save-path=<file where to save result> 24 save-path=<file where to save result>
22 [sheet_info] 25 [sheet_info]
23 # This section is required only when write_to_sheet=true 26 # This section is required only when write_to_sheet=true
24 pkey=full_path 27 pkey=full_path
25 client_email=email_assigned_by_google_dev_console 28 client_email=email_assigned_by_google_dev_console
26 sheet_key=sheet_key_from_sheet_url 29 sheet_key=sheet_key_from_sheet_url
27 """ 30 """
28 from datetime import datetime 31 from datetime import datetime
29 import ConfigParser 32 import ConfigParser
30 import sys 33 import sys
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 except Exception: 173 except Exception:
171 pass 174 pass
172 try: 175 try:
173 shutil.rmtree(self.profile_path) 176 shutil.rmtree(self.profile_path)
174 except Exception: 177 except Exception:
175 pass 178 pass
176 self.max_test_runs_left -= 1 179 self.max_test_runs_left -= 1
177 print "Run of test %s started" % self.test_name 180 print "Run of test %s started" % self.test_name
178 self.runner_process = subprocess.Popen(self.test_cmd) 181 self.runner_process = subprocess.Popen(self.test_cmd)
179 182
183 def _apply_defaults(config, defaults):
184 """Adds default values from |defaults| to |config|.
185
186 Note: This differs from ConfigParser's mechanism for providing defaults in
187 two points:
engedy 2015/03/04 13:20:31 nit: s/points/aspects/
vabr (Chromium) 2015/03/04 13:25:34 Done.
188 * The "defaults" here become explicit, and are associated with sections.
189 * Sections get created for the added defaults where needed, they need not
engedy 2015/03/04 13:20:31 nit: ..., that is, if
vabr (Chromium) 2015/03/04 13:25:34 Done.
190 exist before.
191
192 Args:
193 config: A ConfigParser instance to be updated
194 defaults: A dictionary with keys (section_string, option_string) and
engedy 2015/03/04 13:20:30 Phrasing suggestion: A dictionary mapping (section
vabr (Chromium) 2015/03/04 13:25:34 Done.
195 string values. For every section/option combination not already
196 contained in |config|, the value from |defaults| is stored in |config|.
197 """
198 for (section, option) in defaults:
199 if not config.has_section(section):
200 config.add_section(section)
201 if not config.has_option(section, option):
202 config.set(section, option, defaults[(section, option)])
203
180 def run_tests(config_path): 204 def run_tests(config_path):
181 """ Runs automated tests. """ 205 """ Runs automated tests. """
182 environment = Environment("", "", "", None, False) 206 environment = Environment("", "", "", None, False)
183 tests.Tests(environment) 207 tests.Tests(environment)
208 defaults = { ("output", "save-path"): "/dev/null",
209 ("run_options", "tests_in_parallel"): "1",
210 ("run_options", "write_to_sheet"): "false" }
184 config = ConfigParser.ConfigParser() 211 config = ConfigParser.ConfigParser()
212 _apply_defaults(config, defaults)
185 config.read(config_path) 213 config.read(config_path)
186 date = datetime.now().strftime('%Y-%m-%dT%H:%M:%S') 214 date = datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
187 max_tests_in_parrallel = config.getint("run_options", "tests_in_parrallel") 215 max_tests_in_parallel = config.getint("run_options", "tests_in_parallel")
188 sheet_writer = SheetWriter(config) 216 sheet_writer = SheetWriter(config)
189 full_path = os.path.realpath(__file__) 217 full_path = os.path.realpath(__file__)
190 tests_dir = os.path.dirname(full_path) 218 tests_dir = os.path.dirname(full_path)
191 tests_path = os.path.join(tests_dir, "tests.py") 219 tests_path = os.path.join(tests_dir, "tests.py")
192 general_test_cmd = ["python", tests_path, "test_name_placeholder", 220 general_test_cmd = ["python", tests_path, "test_name_placeholder",
193 "--chrome-path", config.get("binaries", "chrome-path"), 221 "--chrome-path", config.get("binaries", "chrome-path"),
194 "--chromedriver-path", config.get("binaries", "chromedriver-path"), 222 "--chromedriver-path", config.get("binaries", "chromedriver-path"),
195 "--passwords-path", config.get("data_files", "passwords_path")] 223 "--passwords-path", config.get("data_files", "passwords_path")]
196 runners = [] 224 runners = []
197 tests_to_run = [test.name for test in environment.websitetests] 225 tests_to_run = [test.name for test in environment.websitetests]
198 if config.has_option("run_options", "tests_to_run"): 226 if config.has_option("run_options", "tests_to_run"):
199 user_selected_tests = config.get("run_options", "tests_to_run").split(',') 227 user_selected_tests = config.get("run_options", "tests_to_run").split(',')
200 # TODO((dvadym) Validate the user selected tests are available. 228 # TODO((dvadym) Validate the user selected tests are available.
201 tests_to_run = list(set(tests_to_run) & set(user_selected_tests)) 229 tests_to_run = list(set(tests_to_run) & set(user_selected_tests))
202 230
203 with open(config.get("output", "save-path"), 'w') as savefile: 231 with open(config.get("output", "save-path"), 'w') as savefile:
204 print "Tests to run %d\nTests: %s" % (len(tests_to_run), tests_to_run) 232 print "Tests to run %d\nTests: %s" % (len(tests_to_run), tests_to_run)
205 while len(runners) + len(tests_to_run) > 0: 233 while len(runners) + len(tests_to_run) > 0:
206 i = 0 234 i = 0
207 while i < len(runners): 235 while i < len(runners):
208 result = runners[i].get_test_result() 236 result = runners[i].get_test_result()
209 if result: # This test run is finished. 237 if result: # This test run is finished.
210 status, log = result 238 status, log = result
211 testinfo = [runners[i].test_name, status, date, " | ".join(log)] 239 testinfo = [runners[i].test_name, status, date, " | ".join(log)]
212 sheet_writer.write_line_to_sheet(testinfo) 240 sheet_writer.write_line_to_sheet(testinfo)
213 print>>savefile, " ".join(testinfo) 241 print>>savefile, " ".join(testinfo)
214 del runners[i] 242 del runners[i]
215 else: 243 else:
216 i += 1 244 i += 1
217 while len(runners) < max_tests_in_parrallel and len(tests_to_run) > 0: 245 while len(runners) < max_tests_in_parallel and len(tests_to_run) > 0:
218 runners.append(TestRunner(general_test_cmd, tests_to_run.pop())) 246 runners.append(TestRunner(general_test_cmd, tests_to_run.pop()))
219 time.sleep(1) # Let us wait for worker process to finish. 247 time.sleep(1) # Let us wait for worker process to finish.
220 248
221 if __name__ == "__main__": 249 if __name__ == "__main__":
222 if len(sys.argv) != 2: 250 if len(sys.argv) != 2:
223 print "Synopsis:\n python run_tests.py <config_path>" 251 print "Synopsis:\n python run_tests.py <config_path>"
224 config_path = sys.argv[1] 252 config_path = sys.argv[1]
225 run_tests(config_path) 253 run_tests(config_path)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698