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

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

Issue 723343002: Update from https://crrev.com/304121 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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/test_dispatcher.py ('k') | build/android/pylib/base/test_server.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 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
11 import unittest 11 import unittest
12 12
13 sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), 13 sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),
14 os.pardir, os.pardir)) 14 os.pardir, os.pardir))
15 15
16 # Mock out android_commands.GetAttachedDevices(). 16 # Mock out android_commands.GetAttachedDevices().
17 from pylib import android_commands 17 from pylib import android_commands
18 android_commands.GetAttachedDevices = lambda: ['0', '1'] 18 android_commands.GetAttachedDevices = lambda: ['0', '1']
19 from pylib import constants 19 from pylib import constants
20 from pylib.base import base_test_result 20 from pylib.base import base_test_result
21 from pylib.base import test_collection
21 from pylib.base import test_dispatcher 22 from pylib.base import test_dispatcher
22 from pylib.utils import watchdog_timer 23 from pylib.utils import watchdog_timer
23 24
24 25
25 class TestException(Exception): 26 class TestException(Exception):
26 pass 27 pass
27 28
28 29
29 class MockRunner(object): 30 class MockRunner(object):
30 """A mock TestRunner.""" 31 """A mock TestRunner."""
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 class MockRunnerException(MockRunner): 77 class MockRunnerException(MockRunner):
77 def RunTest(self, test): 78 def RunTest(self, test):
78 raise TestException 79 raise TestException
79 80
80 81
81 class TestFunctions(unittest.TestCase): 82 class TestFunctions(unittest.TestCase):
82 """Tests test_dispatcher._RunTestsFromQueue.""" 83 """Tests test_dispatcher._RunTestsFromQueue."""
83 @staticmethod 84 @staticmethod
84 def _RunTests(mock_runner, tests): 85 def _RunTests(mock_runner, tests):
85 results = [] 86 results = []
86 tests = test_dispatcher._TestCollection( 87 tests = test_collection.TestCollection(
87 [test_dispatcher._Test(t) for t in tests]) 88 [test_dispatcher._Test(t) for t in tests])
88 test_dispatcher._RunTestsFromQueue(mock_runner, tests, results, 89 test_dispatcher._RunTestsFromQueue(mock_runner, tests, results,
89 watchdog_timer.WatchdogTimer(None), 2) 90 watchdog_timer.WatchdogTimer(None), 2)
90 run_results = base_test_result.TestRunResults() 91 run_results = base_test_result.TestRunResults()
91 for r in results: 92 for r in results:
92 run_results.AddTestRunResults(r) 93 run_results.AddTestRunResults(r)
93 return run_results 94 return run_results
94 95
95 def testRunTestsFromQueue(self): 96 def testRunTestsFromQueue(self):
96 results = TestFunctions._RunTests(MockRunner(), ['a', 'b']) 97 results = TestFunctions._RunTests(MockRunner(), ['a', 'b'])
(...skipping 25 matching lines...) Expand all
122 def testApplyMaxPerRun(self): 123 def testApplyMaxPerRun(self):
123 self.assertEqual( 124 self.assertEqual(
124 ['A:B', 'C:D', 'E', 'F:G', 'H:I'], 125 ['A:B', 'C:D', 'E', 'F:G', 'H:I'],
125 test_dispatcher.ApplyMaxPerRun(['A:B', 'C:D:E', 'F:G:H:I'], 2)) 126 test_dispatcher.ApplyMaxPerRun(['A:B', 'C:D:E', 'F:G:H:I'], 2))
126 127
127 128
128 class TestThreadGroupFunctions(unittest.TestCase): 129 class TestThreadGroupFunctions(unittest.TestCase):
129 """Tests test_dispatcher._RunAllTests and test_dispatcher._CreateRunners.""" 130 """Tests test_dispatcher._RunAllTests and test_dispatcher._CreateRunners."""
130 def setUp(self): 131 def setUp(self):
131 self.tests = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] 132 self.tests = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
132 shared_test_collection = test_dispatcher._TestCollection( 133 shared_test_collection = test_collection.TestCollection(
133 [test_dispatcher._Test(t) for t in self.tests]) 134 [test_dispatcher._Test(t) for t in self.tests])
134 self.test_collection_factory = lambda: shared_test_collection 135 self.test_collection_factory = lambda: shared_test_collection
135 136
136 def testCreate(self): 137 def testCreate(self):
137 runners = test_dispatcher._CreateRunners(MockRunner, ['0', '1']) 138 runners = test_dispatcher._CreateRunners(MockRunner, ['0', '1'])
138 for runner in runners: 139 for runner in runners:
139 self.assertEqual(runner.setups, 1) 140 self.assertEqual(runner.setups, 1)
140 self.assertEqual(set([r.device_serial for r in runners]), 141 self.assertEqual(set([r.device_serial for r in runners]),
141 set(['0', '1'])) 142 set(['0', '1']))
142 self.assertEqual(set([r.shard_index for r in runners]), 143 self.assertEqual(set([r.shard_index for r in runners]),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 215
215 def testNoTests(self): 216 def testNoTests(self):
216 results, exit_code = test_dispatcher.RunTests( 217 results, exit_code = test_dispatcher.RunTests(
217 [], MockRunner, ['0', '1'], shard=False) 218 [], MockRunner, ['0', '1'], shard=False)
218 self.assertEqual(len(results.GetAll()), 0) 219 self.assertEqual(len(results.GetAll()), 0)
219 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) 220 self.assertEqual(exit_code, constants.ERROR_EXIT_CODE)
220 221
221 222
222 if __name__ == '__main__': 223 if __name__ == '__main__':
223 unittest.main() 224 unittest.main()
OLDNEW
« no previous file with comments | « build/android/pylib/base/test_dispatcher.py ('k') | build/android/pylib/base/test_server.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698