Chromium Code Reviews| Index: build/android/pylib/base/test_dispatcher_unittest.py |
| diff --git a/build/android/pylib/base/shard_unittest.py b/build/android/pylib/base/test_dispatcher_unittest.py |
| similarity index 64% |
| rename from build/android/pylib/base/shard_unittest.py |
| rename to build/android/pylib/base/test_dispatcher_unittest.py |
| index 5f8b9908965d16e54f2db8db4a340a8c407387eb..fb40893199654f767e9a4b57566eedfe127eda07 100644 |
| --- a/build/android/pylib/base/shard_unittest.py |
| +++ b/build/android/pylib/base/test_dispatcher_unittest.py |
| @@ -2,7 +2,7 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| -"""Unittests for shard.py.""" |
| +"""Unittests for test_dispatcher.py.""" |
| import os |
| import sys |
| @@ -18,7 +18,7 @@ from pylib import constants |
| from pylib.utils import watchdog_timer |
| import base_test_result |
| -import shard |
| +import test_dispatcher |
| class TestException(Exception): |
| @@ -78,13 +78,14 @@ class MockRunnerException(MockRunner): |
| class TestFunctions(unittest.TestCase): |
| - """Tests for shard._RunTestsFromQueue.""" |
| + """Tests for test_dispatcher._RunTestsFromQueue.""" |
| @staticmethod |
| def _RunTests(mock_runner, tests): |
| results = [] |
| - tests = shard._TestCollection([shard._Test(t) for t in tests]) |
| - shard._RunTestsFromQueue(mock_runner, tests, results, |
| - watchdog_timer.WatchdogTimer(None), 2) |
| + tests = test_dispatcher._TestCollection( |
| + [test_dispatcher._Test(t) for t in tests]) |
| + test_dispatcher._RunTestsFromQueue(mock_runner, tests, results, |
| + watchdog_timer.WatchdogTimer(None), 2) |
| run_results = base_test_result.TestRunResults() |
| for r in results: |
| run_results.AddTestRunResults(r) |
| @@ -107,24 +108,27 @@ class TestFunctions(unittest.TestCase): |
| def testSetUp(self): |
| runners = [] |
| - counter = shard._ThreadSafeCounter() |
| - shard._SetUp(MockRunner, '0', runners, counter) |
| + counter = test_dispatcher._ThreadSafeCounter() |
| + test_dispatcher._SetUp(MockRunner, '0', runners, counter) |
| self.assertEqual(len(runners), 1) |
| self.assertEqual(runners[0].setups, 1) |
| def testThreadSafeCounter(self): |
| - counter = shard._ThreadSafeCounter() |
| + counter = test_dispatcher._ThreadSafeCounter() |
| for i in xrange(5): |
| self.assertEqual(counter.GetAndIncrement(), i) |
| class TestThreadGroupFunctions(unittest.TestCase): |
| - """Tests for shard._RunAllTests and shard._CreateRunners.""" |
| + """Tests for _RunAllTests and _CreateRunners.""" |
|
frankf
2013/07/17 04:07:20
Be consistant with including the module name
gkanwar
2013/07/17 20:31:26
Done.
|
| def setUp(self): |
| self.tests = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] |
| + shared_test_collection = test_dispatcher._TestCollection( |
| + [test_dispatcher._Test(t) for t in self.tests]) |
| + self.test_collection_factory = lambda: shared_test_collection |
| def testCreate(self): |
| - runners = shard._CreateRunners(MockRunner, ['0', '1']) |
| + runners = test_dispatcher._CreateRunners(MockRunner, ['0', '1']) |
| for runner in runners: |
| self.assertEqual(runner.setups, 1) |
| self.assertEqual(set([r.device for r in runners]), |
| @@ -134,33 +138,36 @@ class TestThreadGroupFunctions(unittest.TestCase): |
| def testRun(self): |
| runners = [MockRunner('0'), MockRunner('1')] |
| - results, exit_code = shard._RunAllTests(runners, self.tests, 0) |
| + results, exit_code = test_dispatcher._RunAllTests( |
| + runners, self.test_collection_factory, 0) |
| self.assertEqual(len(results.GetPass()), len(self.tests)) |
| self.assertEqual(exit_code, 0) |
| def testTearDown(self): |
| runners = [MockRunner('0'), MockRunner('1')] |
| - shard._TearDownRunners(runners) |
| + test_dispatcher._TearDownRunners(runners) |
| for runner in runners: |
| self.assertEqual(runner.teardowns, 1) |
| def testRetry(self): |
| - runners = shard._CreateRunners(MockRunnerFail, ['0', '1']) |
| - results, exit_code = shard._RunAllTests(runners, self.tests, 0) |
| + runners = test_dispatcher._CreateRunners(MockRunnerFail, ['0', '1']) |
| + results, exit_code = test_dispatcher._RunAllTests( |
| + runners, self.test_collection_factory, 0) |
| self.assertEqual(len(results.GetFail()), len(self.tests)) |
| self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
| def testReraise(self): |
| - runners = shard._CreateRunners(MockRunnerException, ['0', '1']) |
| + runners = test_dispatcher._CreateRunners(MockRunnerException, ['0', '1']) |
| with self.assertRaises(TestException): |
| - shard._RunAllTests(runners, self.tests, 0) |
| + test_dispatcher._RunAllTests(runners, self.test_collection_factory, 0) |
| class TestShard(unittest.TestCase): |
| - """Tests for shard.Shard.""" |
| + """Tests for test_dispatcher.ShardAndRunTests.""" |
|
frankf
2013/07/17 04:07:20
Update comment
gkanwar
2013/07/17 20:31:26
Done.
|
| @staticmethod |
| def _RunShard(runner_factory): |
| - return shard.ShardAndRunTests(runner_factory, ['0', '1'], ['a', 'b', 'c']) |
| + return test_dispatcher.RunTests( |
| + ['a', 'b', 'c'], runner_factory, False, None, True) |
| def testShard(self): |
| results, exit_code = TestShard._RunShard(MockRunner) |
| @@ -171,10 +178,37 @@ class TestShard(unittest.TestCase): |
| results, exit_code = TestShard._RunShard(MockRunnerFail) |
| self.assertEqual(len(results.GetPass()), 0) |
| self.assertEqual(len(results.GetFail()), 3) |
| + self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
| + |
| + def testNoTests(self): |
| + results, exit_code = test_dispatcher.RunTests( |
| + [], MockRunner, False, None, True) |
| + self.assertEqual(len(results.GetAll()), 0) |
| + self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
| + |
| + |
| +class TestReplicate(unittest.TestCase): |
| + """Tests for test_dispatcher.ReplicateAndRunTests.""" |
|
frankf
2013/07/17 04:07:20
Same here
gkanwar
2013/07/17 20:31:26
Done.
|
| + @staticmethod |
| + def _RunReplicate(runner_factory): |
| + return test_dispatcher.RunTests( |
| + ['a', 'b', 'c'], runner_factory, False, None, False) |
| + |
| + def testReplicate(self): |
| + results, exit_code = TestReplicate._RunReplicate(MockRunner) |
| + # We expect 6 results since each test should have been run on every device |
| + self.assertEqual(len(results.GetPass()), 6) |
| self.assertEqual(exit_code, 0) |
| + def testFailing(self): |
| + results, exit_code = TestReplicate._RunReplicate(MockRunnerFail) |
| + self.assertEqual(len(results.GetPass()), 0) |
| + self.assertEqual(len(results.GetFail()), 6) |
| + self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |
| + |
| def testNoTests(self): |
| - results, exit_code = shard.ShardAndRunTests(MockRunner, ['0', '1'], []) |
| + results, exit_code = test_dispatcher.RunTests( |
| + [], MockRunner, False, None, False) |
| self.assertEqual(len(results.GetAll()), 0) |
| self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) |