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 """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 import android_commands | 26 import android_commands |
| 27 import apk_info |
27 from run_java_tests import TestRunner | 28 from run_java_tests import TestRunner |
28 from test_result import SingleTestResult, TestResults | 29 from test_result import SingleTestResult, TestResults |
29 from utils import apk_and_jar_info | |
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 |
39 def __init__(self, test_name): | 39 def __init__(self, test_name): |
(...skipping 28 matching lines...) Expand all Loading... |
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_and_jar_info.ApkAndJarInfo(self.options.test_apk_path, | 78 apks = [apk_info.ApkInfo(self.options.test_apk_path, |
79 self.options.test_apk_jar_path)] | 79 self.options.test_apk_jar_path)] |
80 java_test_runner = TestRunner(self.options, self.device_id, [test], False, | 80 java_test_runner = TestRunner(self.options, self.device_id, [test], False, |
81 self.shard_index, | 81 self.shard_index, |
82 apks, | 82 apks, |
83 self.ports_to_forward) | 83 self.ports_to_forward) |
84 return java_test_runner.Run() | 84 return java_test_runner.Run() |
85 | 85 |
86 def _RunJavaTests(self, fname, tests): | 86 def _RunJavaTests(self, fname, tests): |
87 """Calls a list of tests and stops at the first test failure. | 87 """Calls a list of tests and stops at the first test failure. |
88 | 88 |
89 This method iterates until either it encounters a non-passing test or it | 89 This method iterates until either it encounters a non-passing test or it |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 def _ComposeFullTestName(self, fname, suite, test): | 164 def _ComposeFullTestName(self, fname, suite, test): |
165 package_name = self._GetPackageName(fname) | 165 package_name = self._GetPackageName(fname) |
166 return package_name + '.' + suite + '#' + test | 166 return package_name + '.' + suite + '#' + test |
167 | 167 |
168 def _GetPackageName(self, fname): | 168 def _GetPackageName(self, fname): |
169 """Extracts the package name from the test file path.""" | 169 """Extracts the package name from the test file path.""" |
170 dirname = os.path.dirname(fname) | 170 dirname = os.path.dirname(fname) |
171 package = dirname[dirname.rfind(BASE_ROOT) + len(BASE_ROOT):] | 171 package = dirname[dirname.rfind(BASE_ROOT) + len(BASE_ROOT):] |
172 return package.replace(os.sep, '.') | 172 return package.replace(os.sep, '.') |
OLD | NEW |