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 | 6 # pylint: disable=R0201 |
7 # pylint: disable=W0212 | 7 # pylint: disable=W0212 |
8 | 8 |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 | 24 |
25 | 25 |
26 class TestException(Exception): | 26 class TestException(Exception): |
27 pass | 27 pass |
28 | 28 |
29 | 29 |
30 class MockRunner(object): | 30 class MockRunner(object): |
31 """A mock TestRunner.""" | 31 """A mock TestRunner.""" |
32 def __init__(self, device='0', shard_index=0): | 32 def __init__(self, device='0', shard_index=0): |
33 self.device = device | 33 self.device_serial = device |
34 self.shard_index = shard_index | 34 self.shard_index = shard_index |
35 self.setups = 0 | 35 self.setups = 0 |
36 self.teardowns = 0 | 36 self.teardowns = 0 |
37 | 37 |
38 def RunTest(self, test): | 38 def RunTest(self, test): |
39 results = base_test_result.TestRunResults() | 39 results = base_test_result.TestRunResults() |
40 results.AddResult( | 40 results.AddResult( |
41 base_test_result.BaseTestResult(test, base_test_result.ResultType.PASS)) | 41 base_test_result.BaseTestResult(test, base_test_result.ResultType.PASS)) |
42 return (results, None) | 42 return (results, None) |
43 | 43 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 def setUp(self): | 126 def setUp(self): |
127 self.tests = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] | 127 self.tests = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] |
128 shared_test_collection = test_dispatcher._TestCollection( | 128 shared_test_collection = test_dispatcher._TestCollection( |
129 [test_dispatcher._Test(t) for t in self.tests]) | 129 [test_dispatcher._Test(t) for t in self.tests]) |
130 self.test_collection_factory = lambda: shared_test_collection | 130 self.test_collection_factory = lambda: shared_test_collection |
131 | 131 |
132 def testCreate(self): | 132 def testCreate(self): |
133 runners = test_dispatcher._CreateRunners(MockRunner, ['0', '1']) | 133 runners = test_dispatcher._CreateRunners(MockRunner, ['0', '1']) |
134 for runner in runners: | 134 for runner in runners: |
135 self.assertEqual(runner.setups, 1) | 135 self.assertEqual(runner.setups, 1) |
136 self.assertEqual(set([r.device for r in runners]), | 136 self.assertEqual(set([r.device_serial for r in runners]), |
137 set(['0', '1'])) | 137 set(['0', '1'])) |
138 self.assertEqual(set([r.shard_index for r in runners]), | 138 self.assertEqual(set([r.shard_index for r in runners]), |
139 set([0, 1])) | 139 set([0, 1])) |
140 | 140 |
141 def testRun(self): | 141 def testRun(self): |
142 runners = [MockRunner('0'), MockRunner('1')] | 142 runners = [MockRunner('0'), MockRunner('1')] |
143 results, exit_code = test_dispatcher._RunAllTests( | 143 results, exit_code = test_dispatcher._RunAllTests( |
144 runners, self.test_collection_factory, 0) | 144 runners, self.test_collection_factory, 0) |
145 self.assertEqual(len(results.GetPass()), len(self.tests)) | 145 self.assertEqual(len(results.GetPass()), len(self.tests)) |
146 self.assertEqual(exit_code, 0) | 146 self.assertEqual(exit_code, 0) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 219 |
220 def testNoTests(self): | 220 def testNoTests(self): |
221 results, exit_code = test_dispatcher.RunTests( | 221 results, exit_code = test_dispatcher.RunTests( |
222 [], MockRunner, ['0', '1'], shard=False) | 222 [], MockRunner, ['0', '1'], shard=False) |
223 self.assertEqual(len(results.GetAll()), 0) | 223 self.assertEqual(len(results.GetAll()), 0) |
224 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) | 224 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
225 | 225 |
226 | 226 |
227 if __name__ == '__main__': | 227 if __name__ == '__main__': |
228 unittest.main() | 228 unittest.main() |
OLD | NEW |