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

Side by Side Diff: build/android/pylib/host_driven/python_test_base.py

Issue 21008004: Changes argument passing to use options objects (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes imports, removes intermediate variables Created 7 years, 4 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
OLDNEW
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 """Base class for Android Python-driven tests. 5 """Base class for Android Python-driven tests.
6 6
7 This test case is intended to serve as the base class for any Python-driven 7 This test case is intended to serve as the base class for any Python-driven
8 tests. It is similar to the Python unitttest module in that the user's tests 8 tests. It is similar to the Python unitttest module in that the user's tests
9 inherit from this case and add their tests in that case. 9 inherit from this case and add their tests in that case.
10 10
11 When a PythonTestBase object is instantiated, its purpose is to run only one of 11 When a PythonTestBase object is instantiated, its purpose is to run only one of
12 its tests. The test runner gives it the name of the test the instance will 12 its tests. The test runner gives it the name of the test the instance will
13 run. The test runner calls SetUp with the Android device ID which the test will 13 run. The test runner calls SetUp with the Android device ID which the test will
14 run against. The runner runs the test method itself, collecting the result, 14 run against. The runner runs the test method itself, collecting the result,
15 and calls TearDown. 15 and calls TearDown.
16 16
17 Tests can basically do whatever they want in the test methods, such as call 17 Tests can basically do whatever they want in the test methods, such as call
18 Java tests using _RunJavaTests. Those methods have the advantage of massaging 18 Java tests using _RunJavaTests. Those methods have the advantage of massaging
19 the Java test results into Python test results. 19 the Java test results into Python test results.
20 """ 20 """
21 21
22 import logging 22 import logging
23 import os 23 import os
24 import time 24 import time
25 25
26 from pylib import android_commands 26 from pylib import android_commands
27 from pylib.base import base_test_result 27 from pylib.base import base_test_result
28 from pylib.instrumentation import test_options
28 from pylib.instrumentation import test_package 29 from pylib.instrumentation import test_package
29 from pylib.instrumentation import test_result 30 from pylib.instrumentation import test_result
30 from pylib.instrumentation import test_runner 31 from pylib.instrumentation import test_runner
31 32
32 33
33 # aka the parent of com.google.android 34 # aka the parent of com.google.android
34 BASE_ROOT = 'src' + os.sep 35 BASE_ROOT = 'src' + os.sep
35 36
36 37
37 class PythonTestBase(object): 38 class PythonTestBase(object):
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 fname: filename for the test (e.g. foo/bar/baz/tests/FooTest.py) 72 fname: filename for the test (e.g. foo/bar/baz/tests/FooTest.py)
72 suite: name of the Java test suite (e.g. FooTest) 73 suite: name of the Java test suite (e.g. FooTest)
73 test: name of the test method to run (e.g. testFooBar) 74 test: name of the test method to run (e.g. testFooBar)
74 75
75 Returns: 76 Returns:
76 TestRunResults object with a single test result. 77 TestRunResults object with a single test result.
77 """ 78 """
78 test = self._ComposeFullTestName(fname, suite, test) 79 test = self._ComposeFullTestName(fname, suite, test)
79 test_pkg = test_package.TestPackage( 80 test_pkg = test_package.TestPackage(
80 self.options.test_apk_path, self.options.test_apk_jar_path) 81 self.options.test_apk_path, self.options.test_apk_jar_path)
81 java_test_runner = test_runner.TestRunner(self.options.build_type, 82 instrumentation_options = test_options.InstrumentationOptions(
82 self.options.test_data, 83 self.options.build_type,
83 self.options.save_perf_json, 84 self.options.tool,
84 self.options.screenshot_failures, 85 self.options.cleanup_test_files,
85 self.options.tool, 86 self.options.push_deps,
86 self.options.wait_for_debugger, 87 self.options.annotations,
87 self.options.disable_assertions, 88 self.options.exclude_annotations,
88 self.options.push_deps, 89 self.options.test_filter,
89 self.options.cleanup_test_files, 90 self.options.test_data,
91 self.options.save_perf_json,
92 self.options.screenshot_failures,
93 self.options.disable_assertions,
94 self.options.wait_for_debugger,
95 self.options.test_apk,
96 self.options.test_apk_path,
97 self.options.test_apk_jar_path)
98 java_test_runner = test_runner.TestRunner(instrumentation_options,
90 self.device_id, 99 self.device_id,
91 self.shard_index, test_pkg, 100 self.shard_index, test_pkg,
92 self.ports_to_forward) 101 self.ports_to_forward)
93 try: 102 try:
94 java_test_runner.SetUp() 103 java_test_runner.SetUp()
95 return java_test_runner.RunTest(test)[0] 104 return java_test_runner.RunTest(test)[0]
96 finally: 105 finally:
97 java_test_runner.TearDown() 106 java_test_runner.TearDown()
98 107
99 def _RunJavaTests(self, fname, tests): 108 def _RunJavaTests(self, fname, tests):
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 143
135 def _ComposeFullTestName(self, fname, suite, test): 144 def _ComposeFullTestName(self, fname, suite, test):
136 package_name = self._GetPackageName(fname) 145 package_name = self._GetPackageName(fname)
137 return package_name + '.' + suite + '#' + test 146 return package_name + '.' + suite + '#' + test
138 147
139 def _GetPackageName(self, fname): 148 def _GetPackageName(self, fname):
140 """Extracts the package name from the test file path.""" 149 """Extracts the package name from the test file path."""
141 dirname = os.path.dirname(fname) 150 dirname = os.path.dirname(fname)
142 package = dirname[dirname.rfind(BASE_ROOT) + len(BASE_ROOT):] 151 package = dirname[dirname.rfind(BASE_ROOT) + len(BASE_ROOT):]
143 return package.replace(os.sep, '.') 152 return package.replace(os.sep, '.')
OLDNEW
« no previous file with comments | « build/android/pylib/gtest/test_runner.py ('k') | build/android/pylib/host_driven/run_python_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698