OLD | NEW |
---|---|
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 configured and run the tests. | 6 """This file allows the bots to be easily configured and run the tests. |
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: |
10 | 10 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 """ | 198 """ |
199 for (section, option) in defaults: | 199 for (section, option) in defaults: |
200 if not config.has_section(section): | 200 if not config.has_section(section): |
201 config.add_section(section) | 201 config.add_section(section) |
202 if not config.has_option(section, option): | 202 if not config.has_option(section, option): |
203 config.set(section, option, defaults[(section, option)]) | 203 config.set(section, option, defaults[(section, option)]) |
204 | 204 |
205 def run_tests(config_path): | 205 def run_tests(config_path): |
206 """ Runs automated tests. """ | 206 """ Runs automated tests. """ |
207 environment = Environment("", "", "", None, False) | 207 environment = Environment("", "", "", None, False) |
208 tests.Tests(environment) | |
209 defaults = { ("output", "save-path"): "/dev/null", | 208 defaults = { ("output", "save-path"): "/dev/null", |
210 ("run_options", "tests_in_parallel"): "1", | 209 ("run_options", "tests_in_parallel"): "1", |
211 ("run_options", "write_to_sheet"): "false" } | 210 ("run_options", "write_to_sheet"): "false" } |
212 config = ConfigParser.ConfigParser() | 211 config = ConfigParser.ConfigParser() |
213 _apply_defaults(config, defaults) | 212 _apply_defaults(config, defaults) |
214 config.read(config_path) | 213 config.read(config_path) |
215 date = datetime.now().strftime('%Y-%m-%dT%H:%M:%S') | 214 date = datetime.now().strftime('%Y-%m-%dT%H:%M:%S') |
216 max_tests_in_parallel = config.getint("run_options", "tests_in_parallel") | 215 max_tests_in_parallel = config.getint("run_options", "tests_in_parallel") |
217 sheet_writer = SheetWriter(config) | 216 sheet_writer = SheetWriter(config) |
218 full_path = os.path.realpath(__file__) | 217 full_path = os.path.realpath(__file__) |
219 tests_dir = os.path.dirname(full_path) | 218 tests_dir = os.path.dirname(full_path) |
220 tests_path = os.path.join(tests_dir, "tests.py") | 219 tests_path = os.path.join(tests_dir, "tests.py") |
221 general_test_cmd = ["python", tests_path, "test_name_placeholder", | 220 general_test_cmd = ["python", tests_path, "test_name_placeholder", |
222 "--chrome-path", config.get("binaries", "chrome-path"), | 221 "--chrome-path", config.get("binaries", "chrome-path"), |
223 "--chromedriver-path", config.get("binaries", "chromedriver-path"), | 222 "--chromedriver-path", config.get("binaries", "chromedriver-path"), |
224 "--passwords-path", config.get("data_files", "passwords_path")] | 223 "--passwords-path", config.get("data_files", "passwords_path")] |
225 runners = [] | 224 runners = [] |
226 tests_to_run = [test.name for test in environment.websitetests] | |
227 if config.has_option("run_options", "tests_to_run"): | 225 if config.has_option("run_options", "tests_to_run"): |
228 user_selected_tests = config.get("run_options", "tests_to_run").split(',') | 226 user_selected_tests = config.get("run_options", "tests_to_run").split(',') |
229 # TODO((dvadym) Validate the user selected tests are available. | 227 tests_to_run = user_selected_tests |
vabr (Chromium)
2015/03/09 14:52:17
You know Python better than me, so this is just to
melandory
2015/03/09 15:00:27
Variable scope is determined by function or module
vabr (Chromium)
2015/03/09 15:02:28
Acknowledged.
| |
230 tests_to_run = list(set(tests_to_run) & set(user_selected_tests)) | 228 else: |
229 tests.Tests(environment) | |
230 tests_to_run = [test.name for test in environment.websitetests] | |
231 | 231 |
232 with open(config.get("output", "save-path"), 'w') as savefile: | 232 with open(config.get("output", "save-path"), 'w') as savefile: |
233 print "Tests to run %d\nTests: %s" % (len(tests_to_run), tests_to_run) | 233 print "Tests to run %d\nTests: %s" % (len(tests_to_run), tests_to_run) |
234 while len(runners) + len(tests_to_run) > 0: | 234 while len(runners) + len(tests_to_run) > 0: |
235 i = 0 | 235 i = 0 |
236 while i < len(runners): | 236 while i < len(runners): |
237 result = runners[i].get_test_result() | 237 result = runners[i].get_test_result() |
238 if result: # This test run is finished. | 238 if result: # This test run is finished. |
239 status, log = result | 239 status, log = result |
240 testinfo = [runners[i].test_name, status, date, " | ".join(log)] | 240 testinfo = [runners[i].test_name, status, date, " | ".join(log)] |
241 sheet_writer.write_line_to_sheet(testinfo) | 241 sheet_writer.write_line_to_sheet(testinfo) |
242 print>>savefile, " ".join(testinfo) | 242 print>>savefile, " ".join(testinfo) |
243 del runners[i] | 243 del runners[i] |
244 else: | 244 else: |
245 i += 1 | 245 i += 1 |
246 while len(runners) < max_tests_in_parallel and len(tests_to_run) > 0: | 246 while len(runners) < max_tests_in_parallel and len(tests_to_run) > 0: |
247 runners.append(TestRunner(general_test_cmd, tests_to_run.pop())) | 247 runners.append(TestRunner(general_test_cmd, tests_to_run.pop())) |
248 time.sleep(1) # Let us wait for worker process to finish. | 248 time.sleep(1) # Let us wait for worker process to finish. |
249 | 249 |
250 if __name__ == "__main__": | 250 if __name__ == "__main__": |
251 if len(sys.argv) != 2: | 251 if len(sys.argv) != 2: |
252 print "Synopsis:\n python run_tests.py <config_path>" | 252 print "Synopsis:\n python run_tests.py <config_path>" |
253 config_path = sys.argv[1] | 253 config_path = sys.argv[1] |
254 run_tests(config_path) | 254 run_tests(config_path) |
OLD | NEW |