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