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 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 self.assertEqual(len(results.GetPass()), 0) | 179 self.assertEqual(len(results.GetPass()), 0) |
180 self.assertEqual(len(results.GetFail()), 3) | 180 self.assertEqual(len(results.GetFail()), 3) |
181 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) | 181 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
182 | 182 |
183 def testNoTests(self): | 183 def testNoTests(self): |
184 results, exit_code = test_dispatcher.RunTests( | 184 results, exit_code = test_dispatcher.RunTests( |
185 [], MockRunner, ['0', '1'], shard=True) | 185 [], MockRunner, ['0', '1'], shard=True) |
186 self.assertEqual(len(results.GetAll()), 0) | 186 self.assertEqual(len(results.GetAll()), 0) |
187 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) | 187 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
188 | 188 |
| 189 def testTestsRemainWithAllDevicesOffline(self): |
| 190 attached_devices = android_commands.GetAttachedDevices |
| 191 android_commands.GetAttachedDevices = lambda: [] |
| 192 try: |
| 193 with self.assertRaises(AssertionError): |
| 194 results, exit_code = TestShard._RunShard(MockRunner) |
| 195 finally: |
| 196 android_commands.GetAttachedDevices = attached_devices |
| 197 |
189 | 198 |
190 class TestReplicate(unittest.TestCase): | 199 class TestReplicate(unittest.TestCase): |
191 """Tests test_dispatcher.RunTests with replication.""" | 200 """Tests test_dispatcher.RunTests with replication.""" |
192 @staticmethod | 201 @staticmethod |
193 def _RunReplicate(runner_factory): | 202 def _RunReplicate(runner_factory): |
194 return test_dispatcher.RunTests( | 203 return test_dispatcher.RunTests( |
195 ['a', 'b', 'c'], runner_factory, ['0', '1'], shard=False) | 204 ['a', 'b', 'c'], runner_factory, ['0', '1'], shard=False) |
196 | 205 |
197 def testReplicate(self): | 206 def testReplicate(self): |
198 results, exit_code = TestReplicate._RunReplicate(MockRunner) | 207 results, exit_code = TestReplicate._RunReplicate(MockRunner) |
199 # We expect 6 results since each test should have been run on every device | 208 # We expect 6 results since each test should have been run on every device |
200 self.assertEqual(len(results.GetPass()), 6) | 209 self.assertEqual(len(results.GetPass()), 6) |
201 self.assertEqual(exit_code, 0) | 210 self.assertEqual(exit_code, 0) |
202 | 211 |
203 def testFailing(self): | 212 def testFailing(self): |
204 results, exit_code = TestReplicate._RunReplicate(MockRunnerFail) | 213 results, exit_code = TestReplicate._RunReplicate(MockRunnerFail) |
205 self.assertEqual(len(results.GetPass()), 0) | 214 self.assertEqual(len(results.GetPass()), 0) |
206 self.assertEqual(len(results.GetFail()), 6) | 215 self.assertEqual(len(results.GetFail()), 6) |
207 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) | 216 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
208 | 217 |
209 def testNoTests(self): | 218 def testNoTests(self): |
210 results, exit_code = test_dispatcher.RunTests( | 219 results, exit_code = test_dispatcher.RunTests( |
211 [], MockRunner, ['0', '1'], shard=False) | 220 [], MockRunner, ['0', '1'], shard=False) |
212 self.assertEqual(len(results.GetAll()), 0) | 221 self.assertEqual(len(results.GetAll()), 0) |
213 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) | 222 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
214 | 223 |
215 | 224 |
216 if __name__ == '__main__': | 225 if __name__ == '__main__': |
217 unittest.main() | 226 unittest.main() |
OLD | NEW |