OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """Unittests for test_dispatcher.py.""" | 5 """Unittests for test_dispatcher.py.""" |
6 | 6 |
7 import os | 7 import os |
8 import sys | 8 import sys |
9 import unittest | 9 import unittest |
10 | 10 |
11 sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), | 11 sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), |
12 os.pardir, os.pardir)) | 12 os.pardir, os.pardir)) |
13 | 13 |
14 # Mock out android_commands.GetAttachedDevices(). | 14 # Mock out android_commands.GetAttachedDevices(). |
15 from pylib import android_commands | 15 from pylib import android_commands |
16 android_commands.GetAttachedDevices = lambda: ['0', '1'] | 16 android_commands.GetAttachedDevices = lambda: ['0', '1'] |
17 from pylib import constants | 17 from pylib import constants |
| 18 from pylib.base import base_test_result |
| 19 from pylib.base import test_dispatcher |
18 from pylib.utils import watchdog_timer | 20 from pylib.utils import watchdog_timer |
19 | 21 |
20 import base_test_result | |
21 import test_dispatcher | |
22 | |
23 | 22 |
24 class TestException(Exception): | 23 class TestException(Exception): |
25 pass | 24 pass |
26 | 25 |
27 | 26 |
28 class MockRunner(object): | 27 class MockRunner(object): |
29 """A mock TestRunner.""" | 28 """A mock TestRunner.""" |
30 def __init__(self, device='0', shard_index=0): | 29 def __init__(self, device='0', shard_index=0): |
31 self.device = device | 30 self.device = device |
32 self.shard_index = shard_index | 31 self.shard_index = shard_index |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 results, exit_code = test_dispatcher.RunTests( | 183 results, exit_code = test_dispatcher.RunTests( |
185 [], MockRunner, ['0', '1'], shard=True) | 184 [], MockRunner, ['0', '1'], shard=True) |
186 self.assertEqual(len(results.GetAll()), 0) | 185 self.assertEqual(len(results.GetAll()), 0) |
187 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) | 186 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
188 | 187 |
189 def testTestsRemainWithAllDevicesOffline(self): | 188 def testTestsRemainWithAllDevicesOffline(self): |
190 attached_devices = android_commands.GetAttachedDevices | 189 attached_devices = android_commands.GetAttachedDevices |
191 android_commands.GetAttachedDevices = lambda: [] | 190 android_commands.GetAttachedDevices = lambda: [] |
192 try: | 191 try: |
193 with self.assertRaises(AssertionError): | 192 with self.assertRaises(AssertionError): |
194 results, exit_code = TestShard._RunShard(MockRunner) | 193 _results, _exit_code = TestShard._RunShard(MockRunner) |
195 finally: | 194 finally: |
196 android_commands.GetAttachedDevices = attached_devices | 195 android_commands.GetAttachedDevices = attached_devices |
197 | 196 |
198 | 197 |
199 class TestReplicate(unittest.TestCase): | 198 class TestReplicate(unittest.TestCase): |
200 """Tests test_dispatcher.RunTests with replication.""" | 199 """Tests test_dispatcher.RunTests with replication.""" |
201 @staticmethod | 200 @staticmethod |
202 def _RunReplicate(runner_factory): | 201 def _RunReplicate(runner_factory): |
203 return test_dispatcher.RunTests( | 202 return test_dispatcher.RunTests( |
204 ['a', 'b', 'c'], runner_factory, ['0', '1'], shard=False) | 203 ['a', 'b', 'c'], runner_factory, ['0', '1'], shard=False) |
(...skipping 12 matching lines...) Expand all Loading... |
217 | 216 |
218 def testNoTests(self): | 217 def testNoTests(self): |
219 results, exit_code = test_dispatcher.RunTests( | 218 results, exit_code = test_dispatcher.RunTests( |
220 [], MockRunner, ['0', '1'], shard=False) | 219 [], MockRunner, ['0', '1'], shard=False) |
221 self.assertEqual(len(results.GetAll()), 0) | 220 self.assertEqual(len(results.GetAll()), 0) |
222 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) | 221 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
223 | 222 |
224 | 223 |
225 if __name__ == '__main__': | 224 if __name__ == '__main__': |
226 unittest.main() | 225 unittest.main() |
OLD | NEW |