Chromium Code Reviews| 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 | |
| 189 | 197 |
|
craigdh
2013/08/27 19:28:57
need an extra line here
| |
| 190 class TestReplicate(unittest.TestCase): | 198 class TestReplicate(unittest.TestCase): |
| 191 """Tests test_dispatcher.RunTests with replication.""" | 199 """Tests test_dispatcher.RunTests with replication.""" |
| 192 @staticmethod | 200 @staticmethod |
| 193 def _RunReplicate(runner_factory): | 201 def _RunReplicate(runner_factory): |
| 194 return test_dispatcher.RunTests( | 202 return test_dispatcher.RunTests( |
| 195 ['a', 'b', 'c'], runner_factory, ['0', '1'], shard=False) | 203 ['a', 'b', 'c'], runner_factory, ['0', '1'], shard=False) |
| 196 | 204 |
| 197 def testReplicate(self): | 205 def testReplicate(self): |
| 198 results, exit_code = TestReplicate._RunReplicate(MockRunner) | 206 results, exit_code = TestReplicate._RunReplicate(MockRunner) |
| 199 # We expect 6 results since each test should have been run on every device | 207 # We expect 6 results since each test should have been run on every device |
| 200 self.assertEqual(len(results.GetPass()), 6) | 208 self.assertEqual(len(results.GetPass()), 6) |
| 201 self.assertEqual(exit_code, 0) | 209 self.assertEqual(exit_code, 0) |
| 202 | 210 |
| 203 def testFailing(self): | 211 def testFailing(self): |
| 204 results, exit_code = TestReplicate._RunReplicate(MockRunnerFail) | 212 results, exit_code = TestReplicate._RunReplicate(MockRunnerFail) |
| 205 self.assertEqual(len(results.GetPass()), 0) | 213 self.assertEqual(len(results.GetPass()), 0) |
| 206 self.assertEqual(len(results.GetFail()), 6) | 214 self.assertEqual(len(results.GetFail()), 6) |
| 207 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) | 215 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
| 208 | 216 |
| 209 def testNoTests(self): | 217 def testNoTests(self): |
| 210 results, exit_code = test_dispatcher.RunTests( | 218 results, exit_code = test_dispatcher.RunTests( |
| 211 [], MockRunner, ['0', '1'], shard=False) | 219 [], MockRunner, ['0', '1'], shard=False) |
| 212 self.assertEqual(len(results.GetAll()), 0) | 220 self.assertEqual(len(results.GetAll()), 0) |
| 213 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) | 221 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
| 214 | 222 |
| 215 | 223 |
| 216 if __name__ == '__main__': | 224 if __name__ == '__main__': |
| 217 unittest.main() | 225 unittest.main() |
| OLD | NEW |