| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 shard.py.""" | 5 """Unittests for shard.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.utils import watchdog_timer |
| 17 | 18 |
| 18 import base_test_result | 19 import base_test_result |
| 19 import shard | 20 import shard |
| 20 | 21 |
| 21 | 22 |
| 22 class TestException(Exception): | 23 class TestException(Exception): |
| 23 pass | 24 pass |
| 24 | 25 |
| 25 | 26 |
| 26 class MockRunner(object): | 27 class MockRunner(object): |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 def RunTest(self, test): | 75 def RunTest(self, test): |
| 75 raise TestException | 76 raise TestException |
| 76 | 77 |
| 77 | 78 |
| 78 class TestFunctions(unittest.TestCase): | 79 class TestFunctions(unittest.TestCase): |
| 79 """Tests for shard._RunTestsFromQueue.""" | 80 """Tests for shard._RunTestsFromQueue.""" |
| 80 @staticmethod | 81 @staticmethod |
| 81 def _RunTests(mock_runner, tests): | 82 def _RunTests(mock_runner, tests): |
| 82 results = [] | 83 results = [] |
| 83 tests = shard._TestCollection([shard._Test(t) for t in tests]) | 84 tests = shard._TestCollection([shard._Test(t) for t in tests]) |
| 84 shard._RunTestsFromQueue(mock_runner, tests, results) | 85 shard._RunTestsFromQueue(mock_runner, tests, results, |
| 86 watchdog_timer.WatchdogTimer(None)) |
| 85 run_results = base_test_result.TestRunResults() | 87 run_results = base_test_result.TestRunResults() |
| 86 for r in results: | 88 for r in results: |
| 87 run_results.AddTestRunResults(r) | 89 run_results.AddTestRunResults(r) |
| 88 return run_results | 90 return run_results |
| 89 | 91 |
| 90 def testRunTestsFromQueue(self): | 92 def testRunTestsFromQueue(self): |
| 91 results = TestFunctions._RunTests(MockRunner(), ['a', 'b']) | 93 results = TestFunctions._RunTests(MockRunner(), ['a', 'b']) |
| 92 self.assertEqual(len(results.GetPass()), 2) | 94 self.assertEqual(len(results.GetPass()), 2) |
| 93 self.assertEqual(len(results.GetNotPass()), 0) | 95 self.assertEqual(len(results.GetNotPass()), 0) |
| 94 | 96 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 self.assertEqual(len(results.GetPass()), 3) | 164 self.assertEqual(len(results.GetPass()), 3) |
| 163 | 165 |
| 164 def testFailing(self): | 166 def testFailing(self): |
| 165 results = TestShard._RunShard(MockRunnerFail) | 167 results = TestShard._RunShard(MockRunnerFail) |
| 166 self.assertEqual(len(results.GetPass()), 0) | 168 self.assertEqual(len(results.GetPass()), 0) |
| 167 self.assertEqual(len(results.GetFail()), 3) | 169 self.assertEqual(len(results.GetFail()), 3) |
| 168 | 170 |
| 169 | 171 |
| 170 if __name__ == '__main__': | 172 if __name__ == '__main__': |
| 171 unittest.main() | 173 unittest.main() |
| OLD | NEW |