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

Unified Diff: build/android/pylib/base/shard_unittest.py

Issue 12278020: [Android] Re-write the gtest TestRunner and introduce a new generic sharder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more frank nits Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/base/shard.py ('k') | build/android/pylib/gtest/dispatch.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/base/shard_unittest.py
diff --git a/build/android/pylib/base/shard_unittest.py b/build/android/pylib/base/shard_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..4813e7e556dc891c2d5d51856f52b974f7f64afb
--- /dev/null
+++ b/build/android/pylib/base/shard_unittest.py
@@ -0,0 +1,116 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Unittests for shard.py."""
+
+import os
+import sys
+import unittest
+
+sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),
+ os.pardir, os.pardir))
+from pylib import android_commands
+
+import shard
+import test_result
+
+
+class TestException(Exception):
+ pass
+
+
+class MockRunner(object):
+ """A mock TestRunner."""
+ def __init__(self, device='0'):
+ self.device = device
+
+ def Run(self, test):
+ return (test_result.TestResults.FromRun(
+ ok=[test_result.BaseTestResult(test, '')]),
+ None)
+
+
+class MockRunnerRetry(MockRunner):
+ def Run(self, test):
+ return (test_result.TestResults.FromRun(
+ failed=[test_result.BaseTestResult(test, '')]),
+ test)
+
+
+class MockRunnerException(MockRunner):
+ def Run(self, test):
+ raise TestException
+
+
+class TestWorker(unittest.TestCase):
+ """Tests for shard._Worker."""
+ @staticmethod
+ def _RunRunner(mock_runner, tests):
+ results = []
+ retry = []
+ worker = shard._Worker(mock_runner, tests, results, retry)
+ worker.start()
+ worker.join()
+ worker.Reraise()
+ return (results, retry)
+
+ def testRun(self):
+ results, retry = TestWorker._RunRunner(MockRunner(), ['a', 'b'])
+ self.assertEqual(len(results), 2)
+ self.assertEqual(len(retry), 0)
+
+ def testRetry(self):
+ results, retry = TestWorker._RunRunner(MockRunnerRetry(), ['a', 'b'])
+ self.assertEqual(len(results), 2)
+ self.assertEqual(len(retry), 2)
+
+ def testReraise(self):
+ with self.assertRaises(TestException):
+ TestWorker._RunRunner(MockRunnerException(), ['a', 'b'])
+
+
+class TestRunAllTests(unittest.TestCase):
+ """Tests for shard._RunAllTests and shard._CreateRunners."""
+ def setUp(self):
+ self.tests = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
+
+ def testRun(self):
+ runners = shard._CreateRunners(MockRunner, ['0', '1'])
+ results, retry = shard._RunAllTests(runners, self.tests)
+ self.assertEqual(len(results), len(self.tests))
+ self.assertEqual(len(retry), 0)
+
+ def testRetry(self):
+ runners = shard._CreateRunners(MockRunnerRetry, ['0', '1'])
+ results, retry = shard._RunAllTests(runners, self.tests)
+ self.assertEqual(len(results), len(self.tests))
+ self.assertEqual(len(retry), len(self.tests))
+
+ def testReraise(self):
+ runners = shard._CreateRunners(MockRunnerException, ['0', '1'])
+ with self.assertRaises(TestException):
+ shard._RunAllTests(runners, self.tests)
+
+
+class TestShard(unittest.TestCase):
+ """Tests for shard.Shard."""
+ @staticmethod
+ def _RunShard(runner_factory):
+ devices = ['0', '1']
+ # Mock out android_commands.GetAttachedDevices().
+ android_commands.GetAttachedDevices = lambda: devices
+ return shard.ShardAndRunTests(runner_factory, devices, ['a', 'b', 'c'])
+
+ def testShard(self):
+ results = TestShard._RunShard(MockRunner)
+ self.assertEqual(len(results.ok), 3)
+
+ def testFailing(self):
+ results = TestShard._RunShard(MockRunnerRetry)
+ self.assertEqual(len(results.ok), 0)
+ self.assertEqual(len(results.failed), 3)
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « build/android/pylib/base/shard.py ('k') | build/android/pylib/gtest/dispatch.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698