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 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 raise TestException | 76 raise TestException |
77 | 77 |
78 | 78 |
79 class TestFunctions(unittest.TestCase): | 79 class TestFunctions(unittest.TestCase): |
80 """Tests for shard._RunTestsFromQueue.""" | 80 """Tests for shard._RunTestsFromQueue.""" |
81 @staticmethod | 81 @staticmethod |
82 def _RunTests(mock_runner, tests): | 82 def _RunTests(mock_runner, tests): |
83 results = [] | 83 results = [] |
84 tests = shard._TestCollection([shard._Test(t) for t in tests]) | 84 tests = shard._TestCollection([shard._Test(t) for t in tests]) |
85 shard._RunTestsFromQueue(mock_runner, tests, results, | 85 shard._RunTestsFromQueue(mock_runner, tests, results, |
86 watchdog_timer.WatchdogTimer(None)) | 86 watchdog_timer.WatchdogTimer(None), 2) |
87 run_results = base_test_result.TestRunResults() | 87 run_results = base_test_result.TestRunResults() |
88 for r in results: | 88 for r in results: |
89 run_results.AddTestRunResults(r) | 89 run_results.AddTestRunResults(r) |
90 return run_results | 90 return run_results |
91 | 91 |
92 def testRunTestsFromQueue(self): | 92 def testRunTestsFromQueue(self): |
93 results = TestFunctions._RunTests(MockRunner(), ['a', 'b']) | 93 results = TestFunctions._RunTests(MockRunner(), ['a', 'b']) |
94 self.assertEqual(len(results.GetPass()), 2) | 94 self.assertEqual(len(results.GetPass()), 2) |
95 self.assertEqual(len(results.GetNotPass()), 0) | 95 self.assertEqual(len(results.GetNotPass()), 0) |
96 | 96 |
(...skipping 29 matching lines...) Expand all Loading... |
126 runners = shard._CreateRunners(MockRunner, ['0', '1']) | 126 runners = shard._CreateRunners(MockRunner, ['0', '1']) |
127 for runner in runners: | 127 for runner in runners: |
128 self.assertEqual(runner.setups, 1) | 128 self.assertEqual(runner.setups, 1) |
129 self.assertEqual(set([r.device for r in runners]), | 129 self.assertEqual(set([r.device for r in runners]), |
130 set(['0', '1'])) | 130 set(['0', '1'])) |
131 self.assertEqual(set([r.shard_index for r in runners]), | 131 self.assertEqual(set([r.shard_index for r in runners]), |
132 set([0, 1])) | 132 set([0, 1])) |
133 | 133 |
134 def testRun(self): | 134 def testRun(self): |
135 runners = [MockRunner('0'), MockRunner('1')] | 135 runners = [MockRunner('0'), MockRunner('1')] |
136 results = shard._RunAllTests(runners, self.tests) | 136 results = shard._RunAllTests(runners, self.tests, 0) |
137 self.assertEqual(len(results.GetPass()), len(self.tests)) | 137 self.assertEqual(len(results.GetPass()), len(self.tests)) |
138 | 138 |
139 def testTearDown(self): | 139 def testTearDown(self): |
140 runners = [MockRunner('0'), MockRunner('1')] | 140 runners = [MockRunner('0'), MockRunner('1')] |
141 shard._TearDownRunners(runners) | 141 shard._TearDownRunners(runners) |
142 for runner in runners: | 142 for runner in runners: |
143 self.assertEqual(runner.teardowns, 1) | 143 self.assertEqual(runner.teardowns, 1) |
144 | 144 |
145 def testRetry(self): | 145 def testRetry(self): |
146 runners = shard._CreateRunners(MockRunnerFail, ['0', '1']) | 146 runners = shard._CreateRunners(MockRunnerFail, ['0', '1']) |
147 results = shard._RunAllTests(runners, self.tests) | 147 results = shard._RunAllTests(runners, self.tests, 0) |
148 self.assertEqual(len(results.GetFail()), len(self.tests)) | 148 self.assertEqual(len(results.GetFail()), len(self.tests)) |
149 | 149 |
150 def testReraise(self): | 150 def testReraise(self): |
151 runners = shard._CreateRunners(MockRunnerException, ['0', '1']) | 151 runners = shard._CreateRunners(MockRunnerException, ['0', '1']) |
152 with self.assertRaises(TestException): | 152 with self.assertRaises(TestException): |
153 shard._RunAllTests(runners, self.tests) | 153 shard._RunAllTests(runners, self.tests, 0) |
154 | 154 |
155 | 155 |
156 class TestShard(unittest.TestCase): | 156 class TestShard(unittest.TestCase): |
157 """Tests for shard.Shard.""" | 157 """Tests for shard.Shard.""" |
158 @staticmethod | 158 @staticmethod |
159 def _RunShard(runner_factory): | 159 def _RunShard(runner_factory): |
160 return shard.ShardAndRunTests(runner_factory, ['0', '1'], ['a', 'b', 'c']) | 160 return shard.ShardAndRunTests(runner_factory, ['0', '1'], ['a', 'b', 'c']) |
161 | 161 |
162 def testShard(self): | 162 def testShard(self): |
163 results = TestShard._RunShard(MockRunner) | 163 results = TestShard._RunShard(MockRunner) |
164 self.assertEqual(len(results.GetPass()), 3) | 164 self.assertEqual(len(results.GetPass()), 3) |
165 | 165 |
166 def testFailing(self): | 166 def testFailing(self): |
167 results = TestShard._RunShard(MockRunnerFail) | 167 results = TestShard._RunShard(MockRunnerFail) |
168 self.assertEqual(len(results.GetPass()), 0) | 168 self.assertEqual(len(results.GetPass()), 0) |
169 self.assertEqual(len(results.GetFail()), 3) | 169 self.assertEqual(len(results.GetFail()), 3) |
170 | 170 |
| 171 def testNoTests(self): |
| 172 results = shard.ShardAndRunTests(MockRunner, ['0', '1'], []) |
| 173 self.assertEqual(len(results.GetAll()), 0) |
| 174 |
171 | 175 |
172 if __name__ == '__main__': | 176 if __name__ == '__main__': |
173 unittest.main() | 177 unittest.main() |
OLD | NEW |