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 """Encapsulates running tests defined in tests.py. | 6 """Encapsulates running tests defined in tests.py. |
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 18 matching lines...) Expand all Loading... |
29 """ | 29 """ |
30 import argparse | 30 import argparse |
31 import ConfigParser | 31 import ConfigParser |
32 import logging | 32 import logging |
33 import os | 33 import os |
34 import shutil | 34 import shutil |
35 import subprocess | 35 import subprocess |
36 import tempfile | 36 import tempfile |
37 import time | 37 import time |
38 | 38 |
39 from environment import Environment | |
40 import tests | 39 import tests |
41 | 40 |
42 | 41 |
43 # Just below logging.DEBUG, use for this script's debug messages instead | 42 # Just below logging.DEBUG, use for this script's debug messages instead |
44 # of logging.DEBUG, which is already used for detailed test debug messages. | 43 # of logging.DEBUG, which is already used for detailed test debug messages. |
45 SCRIPT_DEBUG = 9 | 44 SCRIPT_DEBUG = 9 |
46 | 45 |
47 | 46 |
48 class TestRunner(object): | 47 class TestRunner(object): |
49 """Runs tests for a single website.""" | 48 """Runs tests for a single website.""" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 On logging.INFO logging level, it returns the summary of how many tests | 165 On logging.INFO logging level, it returns the summary of how many tests |
167 passed and failed. | 166 passed and failed. |
168 On logging.DEBUG logging level, it returns the failure logs, if any. | 167 On logging.DEBUG logging level, it returns the failure logs, if any. |
169 (On SCRIPT_DEBUG it returns diagnostics for this script.) | 168 (On SCRIPT_DEBUG it returns diagnostics for this script.) |
170 | 169 |
171 Args: | 170 Args: |
172 config_path: The path to the config INI file. See the top of the file | 171 config_path: The path to the config INI file. See the top of the file |
173 for format description. | 172 for format description. |
174 """ | 173 """ |
175 | 174 |
176 environment = Environment("", "", "", None, False) | |
177 defaults = {("run_options", "tests_in_parallel"): "1"} | 175 defaults = {("run_options", "tests_in_parallel"): "1"} |
178 config = ConfigParser.ConfigParser() | 176 config = ConfigParser.ConfigParser() |
179 _apply_defaults(config, defaults) | 177 _apply_defaults(config, defaults) |
180 config.read(config_path) | 178 config.read(config_path) |
181 max_tests_in_parallel = config.getint("run_options", "tests_in_parallel") | 179 max_tests_in_parallel = config.getint("run_options", "tests_in_parallel") |
182 full_path = os.path.realpath(__file__) | 180 full_path = os.path.realpath(__file__) |
183 tests_dir = os.path.dirname(full_path) | 181 tests_dir = os.path.dirname(full_path) |
184 tests_path = os.path.join(tests_dir, "tests.py") | 182 tests_path = os.path.join(tests_dir, "tests.py") |
185 test_name_idx = 2 # Index of "test_name_placeholder" below. | 183 test_name_idx = 2 # Index of "test_name_placeholder" below. |
186 general_test_cmd = ["python", tests_path, "test_name_placeholder", | 184 general_test_cmd = ["python", tests_path, "test_name_placeholder", |
187 "--chrome-path", config.get("binaries", "chrome-path"), | 185 "--chrome-path", config.get("binaries", "chrome-path"), |
188 "--chromedriver-path", | 186 "--chromedriver-path", |
189 config.get("binaries", "chromedriver-path"), | 187 config.get("binaries", "chromedriver-path"), |
190 "--passwords-path", | 188 "--passwords-path", |
191 config.get("data_files", "passwords_path")] | 189 config.get("data_files", "passwords_path")] |
192 runners = [] | 190 runners = [] |
193 if config.has_option("run_options", "tests_to_run"): | 191 if config.has_option("run_options", "tests_to_run"): |
194 user_selected_tests = config.get("run_options", "tests_to_run").split(",") | 192 user_selected_tests = config.get("run_options", "tests_to_run").split(",") |
195 tests_to_run = user_selected_tests | 193 tests_to_run = user_selected_tests |
196 else: | 194 else: |
197 tests.Tests(environment) | 195 tests_to_run = tests.all_tests.keys() |
198 tests_to_run = [test.name for test in environment.websitetests] | |
199 | 196 |
200 logger = logging.getLogger("run_tests") | 197 logger = logging.getLogger("run_tests") |
201 logger.log(SCRIPT_DEBUG, "%d tests to run: %s", len(tests_to_run), | 198 logger.log(SCRIPT_DEBUG, "%d tests to run: %s", len(tests_to_run), |
202 tests_to_run) | 199 tests_to_run) |
203 results = [] # List of (name, bool_passed, failure_log). | 200 results = [] # List of (name, bool_passed, failure_log). |
204 while len(runners) + len(tests_to_run) > 0: | 201 while len(runners) + len(tests_to_run) > 0: |
205 i = 0 | 202 i = 0 |
206 # TODO(melandory): Rewrite with list comprehension to increase readability. | 203 # TODO(melandory): Rewrite with list comprehension to increase readability. |
207 while i < len(runners): | 204 while i < len(runners): |
208 result = runners[i].get_test_result() | 205 result = runners[i].get_test_result() |
(...skipping 19 matching lines...) Expand all Loading... |
228 def main(): | 225 def main(): |
229 parser = argparse.ArgumentParser() | 226 parser = argparse.ArgumentParser() |
230 parser.add_argument("config_path", metavar="N", | 227 parser.add_argument("config_path", metavar="N", |
231 help="Path to the config.ini file.") | 228 help="Path to the config.ini file.") |
232 args = parser.parse_args() | 229 args = parser.parse_args() |
233 run_tests(args.config_path) | 230 run_tests(args.config_path) |
234 | 231 |
235 | 232 |
236 if __name__ == "__main__": | 233 if __name__ == "__main__": |
237 main() | 234 main() |
OLD | NEW |