OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Runs the Python tests (relies on using the Java test runner).""" | 5 """Runs the Python tests (relies on using the Java test runner).""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import sys | 9 import sys |
10 import types | 10 import types |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 return os.path.splitext(os.path.basename(python_file))[0] | 47 return os.path.splitext(os.path.basename(python_file))[0] |
48 | 48 |
49 | 49 |
50 def DispatchPythonTests(options): | 50 def DispatchPythonTests(options): |
51 """Dispatches the Python tests. If there are multiple devices, use sharding. | 51 """Dispatches the Python tests. If there are multiple devices, use sharding. |
52 | 52 |
53 Args: | 53 Args: |
54 options: command line options. | 54 options: command line options. |
55 | 55 |
56 Returns: | 56 Returns: |
57 A list of test results. | 57 A tuple of (base_test_result.TestRunResults object, exit code) |
58 | 58 |
59 Raises: | 59 Raises: |
60 Exception: If there are no attached devices. | 60 Exception: If there are no attached devices. |
61 """ | 61 """ |
62 | 62 |
63 attached_devices = android_commands.GetAttachedDevices() | 63 attached_devices = android_commands.GetAttachedDevices() |
64 if not attached_devices: | 64 if not attached_devices: |
65 raise Exception('You have no devices attached or visible!') | 65 raise Exception('You have no devices attached or visible!') |
66 if options.test_device: | 66 if options.test_device: |
67 attached_devices = [options.test_device] | 67 attached_devices = [options.test_device] |
68 | 68 |
69 test_collection = TestInfoCollection() | 69 test_collection = TestInfoCollection() |
70 all_tests = _GetAllTests(options.python_test_root, options.official_build) | 70 all_tests = _GetAllTests(options.python_test_root, options.official_build) |
71 test_collection.AddTests(all_tests) | 71 test_collection.AddTests(all_tests) |
72 test_names = [t.qualified_name for t in all_tests] | 72 test_names = [t.qualified_name for t in all_tests] |
73 logging.debug('All available tests: ' + str(test_names)) | 73 logging.debug('All available tests: ' + str(test_names)) |
74 | 74 |
75 available_tests = test_collection.GetAvailableTests( | 75 available_tests = test_collection.GetAvailableTests( |
76 options.annotations, options.exclude_annotations, options.test_filter) | 76 options.annotations, options.exclude_annotations, options.test_filter) |
77 | 77 |
78 if not available_tests: | 78 if not available_tests: |
79 logging.warning('No Python tests to run with current args.') | 79 logging.warning('No Python tests to run with current args.') |
80 return base_test_result.TestRunResults() | 80 return (base_test_result.TestRunResults(), 0) |
81 | 81 |
82 test_names = [t.qualified_name for t in available_tests] | 82 test_names = [t.qualified_name for t in available_tests] |
83 logging.debug('Final list of tests to run: ' + str(test_names)) | 83 logging.debug('Final list of tests to run: ' + str(test_names)) |
84 | 84 |
85 # Copy files to each device before running any tests. | 85 # Copy files to each device before running any tests. |
86 for device_id in attached_devices: | 86 for device_id in attached_devices: |
87 logging.debug('Pushing files to device %s', device_id) | 87 logging.debug('Pushing files to device %s', device_id) |
88 test_pkg = test_package.TestPackage(options.test_apk_path, | 88 test_pkg = test_package.TestPackage(options.test_apk_path, |
89 options.test_apk_jar_path) | 89 options.test_apk_jar_path) |
90 test_files_copier = test_runner.TestRunner( | 90 test_files_copier = test_runner.TestRunner( |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 Returns: | 208 Returns: |
209 List of test case objects for all available test methods. | 209 List of test case objects for all available test methods. |
210 """ | 210 """ |
211 if not test_root: | 211 if not test_root: |
212 return [] | 212 return [] |
213 all_tests = [] | 213 all_tests = [] |
214 test_module_list = _GetTestModules(test_root, is_official_build) | 214 test_module_list = _GetTestModules(test_root, is_official_build) |
215 for module in test_module_list: | 215 for module in test_module_list: |
216 all_tests.extend(_GetTestClassesFromModule(module)) | 216 all_tests.extend(_GetTestClassesFromModule(module)) |
217 return all_tests | 217 return all_tests |
OLD | NEW |