Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: build/android/pylib/base/shard_unittest.py

Issue 18323020: Updates the test runner script exit codes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes Python dispatch issues in test_runner.py Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/pylib/base/shard.py ('k') | build/android/pylib/browsertests/dispatch.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import constants
17 from pylib.utils import watchdog_timer 18 from pylib.utils import watchdog_timer
18 19
19 import base_test_result 20 import base_test_result
20 import shard 21 import shard
21 22
22 23
23 class TestException(Exception): 24 class TestException(Exception):
24 pass 25 pass
25 26
26 27
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 runners = shard._CreateRunners(MockRunner, ['0', '1']) 127 runners = shard._CreateRunners(MockRunner, ['0', '1'])
127 for runner in runners: 128 for runner in runners:
128 self.assertEqual(runner.setups, 1) 129 self.assertEqual(runner.setups, 1)
129 self.assertEqual(set([r.device for r in runners]), 130 self.assertEqual(set([r.device for r in runners]),
130 set(['0', '1'])) 131 set(['0', '1']))
131 self.assertEqual(set([r.shard_index for r in runners]), 132 self.assertEqual(set([r.shard_index for r in runners]),
132 set([0, 1])) 133 set([0, 1]))
133 134
134 def testRun(self): 135 def testRun(self):
135 runners = [MockRunner('0'), MockRunner('1')] 136 runners = [MockRunner('0'), MockRunner('1')]
136 results = shard._RunAllTests(runners, self.tests, 0) 137 results, exit_code = shard._RunAllTests(runners, self.tests, 0)
137 self.assertEqual(len(results.GetPass()), len(self.tests)) 138 self.assertEqual(len(results.GetPass()), len(self.tests))
139 self.assertEqual(exit_code, 0)
138 140
139 def testTearDown(self): 141 def testTearDown(self):
140 runners = [MockRunner('0'), MockRunner('1')] 142 runners = [MockRunner('0'), MockRunner('1')]
141 shard._TearDownRunners(runners) 143 shard._TearDownRunners(runners)
142 for runner in runners: 144 for runner in runners:
143 self.assertEqual(runner.teardowns, 1) 145 self.assertEqual(runner.teardowns, 1)
144 146
145 def testRetry(self): 147 def testRetry(self):
146 runners = shard._CreateRunners(MockRunnerFail, ['0', '1']) 148 runners = shard._CreateRunners(MockRunnerFail, ['0', '1'])
147 results = shard._RunAllTests(runners, self.tests, 0) 149 results, exit_code = shard._RunAllTests(runners, self.tests, 0)
148 self.assertEqual(len(results.GetFail()), len(self.tests)) 150 self.assertEqual(len(results.GetFail()), len(self.tests))
151 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE)
149 152
150 def testReraise(self): 153 def testReraise(self):
151 runners = shard._CreateRunners(MockRunnerException, ['0', '1']) 154 runners = shard._CreateRunners(MockRunnerException, ['0', '1'])
152 with self.assertRaises(TestException): 155 with self.assertRaises(TestException):
153 shard._RunAllTests(runners, self.tests, 0) 156 shard._RunAllTests(runners, self.tests, 0)
154 157
155 158
156 class TestShard(unittest.TestCase): 159 class TestShard(unittest.TestCase):
157 """Tests for shard.Shard.""" 160 """Tests for shard.Shard."""
158 @staticmethod 161 @staticmethod
159 def _RunShard(runner_factory): 162 def _RunShard(runner_factory):
160 return shard.ShardAndRunTests(runner_factory, ['0', '1'], ['a', 'b', 'c']) 163 return shard.ShardAndRunTests(runner_factory, ['0', '1'], ['a', 'b', 'c'])
161 164
162 def testShard(self): 165 def testShard(self):
163 results = TestShard._RunShard(MockRunner) 166 results, exit_code = TestShard._RunShard(MockRunner)
164 self.assertEqual(len(results.GetPass()), 3) 167 self.assertEqual(len(results.GetPass()), 3)
168 self.assertEqual(exit_code, 0)
165 169
166 def testFailing(self): 170 def testFailing(self):
167 results = TestShard._RunShard(MockRunnerFail) 171 results, exit_code = TestShard._RunShard(MockRunnerFail)
168 self.assertEqual(len(results.GetPass()), 0) 172 self.assertEqual(len(results.GetPass()), 0)
169 self.assertEqual(len(results.GetFail()), 3) 173 self.assertEqual(len(results.GetFail()), 3)
174 self.assertEqual(exit_code, 0)
170 175
171 def testNoTests(self): 176 def testNoTests(self):
172 results = shard.ShardAndRunTests(MockRunner, ['0', '1'], []) 177 results, exit_code = shard.ShardAndRunTests(MockRunner, ['0', '1'], [])
173 self.assertEqual(len(results.GetAll()), 0) 178 self.assertEqual(len(results.GetAll()), 0)
179 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE)
174 180
175 181
176 if __name__ == '__main__': 182 if __name__ == '__main__':
177 unittest.main() 183 unittest.main()
OLDNEW
« no previous file with comments | « build/android/pylib/base/shard.py ('k') | build/android/pylib/browsertests/dispatch.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698