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