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

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

Issue 12921004: [Android] Enable running uiautomator tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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.test_result import SingleTestResult, TestResults 27 from pylib.base.test_result import SingleTestResult, TestResults
28 from pylib.instrumentation import apk_info 28 from pylib.instrumentation import test_package
29 from pylib.instrumentation import test_runner 29 from pylib.instrumentation import test_runner
30 30
31 31
32 # aka the parent of com.google.android 32 # aka the parent of com.google.android
33 BASE_ROOT = 'src' + os.sep 33 BASE_ROOT = 'src' + os.sep
34 34
35 35
36 class PythonTestBase(object): 36 class PythonTestBase(object):
37 """Base class for Python-driven tests.""" 37 """Base class for Python-driven tests."""
38 38
(...skipping 29 matching lines...) Expand all
68 68
69 Args: 69 Args:
70 fname: filename for the test (e.g. foo/bar/baz/tests/FooTest.py) 70 fname: filename for the test (e.g. foo/bar/baz/tests/FooTest.py)
71 suite: name of the Java test suite (e.g. FooTest) 71 suite: name of the Java test suite (e.g. FooTest)
72 test: name of the test method to run (e.g. testFooBar) 72 test: name of the test method to run (e.g. testFooBar)
73 73
74 Returns: 74 Returns:
75 TestResults object with a single test result. 75 TestResults object with a single test result.
76 """ 76 """
77 test = self._ComposeFullTestName(fname, suite, test) 77 test = self._ComposeFullTestName(fname, suite, test)
78 apks = [apk_info.ApkInfo(self.options.test_apk_path, 78 test_pkg = test_package.TestPackage(
79 self.options.test_apk_jar_path)] 79 self.options.test_apk_path, self.options.test_apk_jar_path)
80 java_test_runner = test_runner.TestRunner(self.options, self.device_id, 80 java_test_runner = test_runner.TestRunner(self.options, self.device_id,
81 self.shard_index, False, apks, 81 self.shard_index, False,
82 test_pkg,
82 self.ports_to_forward) 83 self.ports_to_forward)
83 try: 84 try:
84 java_test_runner.SetUp() 85 java_test_runner.SetUp()
85 return java_test_runner.RunTest(test)[0] 86 return java_test_runner.RunTest(test)[0]
86 finally: 87 finally:
87 java_test_runner.TearDown() 88 java_test_runner.TearDown()
88 89
89 def _RunJavaTests(self, fname, tests): 90 def _RunJavaTests(self, fname, tests):
90 """Calls a list of tests and stops at the first test failure. 91 """Calls a list of tests and stops at the first test failure.
91 92
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 167
167 def _ComposeFullTestName(self, fname, suite, test): 168 def _ComposeFullTestName(self, fname, suite, test):
168 package_name = self._GetPackageName(fname) 169 package_name = self._GetPackageName(fname)
169 return package_name + '.' + suite + '#' + test 170 return package_name + '.' + suite + '#' + test
170 171
171 def _GetPackageName(self, fname): 172 def _GetPackageName(self, fname):
172 """Extracts the package name from the test file path.""" 173 """Extracts the package name from the test file path."""
173 dirname = os.path.dirname(fname) 174 dirname = os.path.dirname(fname)
174 package = dirname[dirname.rfind(BASE_ROOT) + len(BASE_ROOT):] 175 package = dirname[dirname.rfind(BASE_ROOT) + len(BASE_ROOT):]
175 return package.replace(os.sep, '.') 176 return package.replace(os.sep, '.')
OLDNEW
« no previous file with comments | « build/android/pylib/android_commands.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