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

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

Issue 12544033: [Android] Rewrite base test result classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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
Index: build/android/pylib/base/base_test_result.py
diff --git a/build/android/pylib/base/base_test_result.py b/build/android/pylib/base/base_test_result.py
new file mode 100644
index 0000000000000000000000000000000000000000..056fd98e353d7f03ed3d2d61657c4b7a41d87475
--- /dev/null
+++ b/build/android/pylib/base/base_test_result.py
@@ -0,0 +1,167 @@
+# Copyright (c) 2013 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.
+
+"""Module containing base test results classes."""
+
+class TestType(object):
craigdh 2013/03/23 00:41:39 doc string
frankf 2013/03/23 01:32:59 Done.
+ PASS = 'PASS'
+ FAIL = 'FAIL'
+ CRASH = 'CRASH'
+ TIMEOUT = 'TIMEOUT'
+ UNKNOWN = 'UNKNOWN'
+
+ @staticmethod
+ def GetTypes():
+ """Get a list of all test types."""
+ return [TestType.PASS, TestType.FAIL, TestType.CRASH, TestType.TIMEOUT,
+ TestType.UNKNOWN]
+
+
+class BaseTestResult(object):
+ """Base class for a single test result."""
+
craigdh 2013/03/23 00:41:39 no blank line
frankf 2013/03/23 01:32:59 Done, but pylint complains. On 2013/03/23 00:41:3
+ def __init__(self, name, test_type, log=''):
+ """Construct a BaseTestResult.
+
+ Args:
+ name: Name of the test which defines uniqueness.
+ test_type: Type of the test result as defined in TestType.
+ log: An optional string listing any errors.
+ """
+ assert name
+ assert test_type in TestType.GetTypes()
+ self._name = name
+ self._test_type = test_type
+ self._log = log
+
+ def __str__(self):
+ return self._name
+
+ def __repr__(self):
+ return self._name
+
+ def __cmp__(self, other):
+ # pylint: disable=W0212
+ return cmp(self._name, other._name)
+
+ def __hash__(self):
+ return hash(self._name)
+
+ def GetName(self):
+ """Get the test name."""
+ return self._name
+
+ def GetType(self):
+ """Get the test result type."""
+ return self._test_type
+
+ def GetLog(self):
+ """Get the test log."""
+ return self._log
+
+
+class TestRunResults(object):
+ """Set of results for a test run."""
+
craigdh 2013/03/23 00:41:39 ditto
frankf 2013/03/23 01:32:59 Done.
+ def __init__(self):
+ self._results = set()
+
+ def GetLogs(self):
+ """Get the string representation of all test logs."""
+ s = []
+ for test_type in TestType.GetTypes():
+ if test_type != TestType.PASS:
+ tests = sorted(self._GetType(test_type))
craigdh 2013/03/23 00:41:39 no need for intermediate variable tests
frankf 2013/03/23 01:32:59 Done.
+ for t in tests:
+ s.append('[%s] %s:' % (test_type, t))
+ s.append(t.GetLog())
+ return '\n'.join(s)
+
+ def GetLongForm(self):
+ """Get the long string representation of this object."""
+ s = []
+ s.append('ALL (%d tests)' % len(self._results))
+ for test_type in TestType.GetTypes():
+ tests = sorted(self._GetType(test_type))
+ if test_type == TestType.PASS:
+ s.append('%s (%d tests)' % (test_type, len(tests)))
+ else:
+ s.append('%s (%d tests): %s' % (test_type, len(tests), tests))
+ return '\n'.join(s)
+
+ def GetShortForm(self):
+ """Get the short string representation of this object."""
+ s = []
+ s.append('ALL: %d' % len(self._results))
+ for test_type in TestType.GetTypes():
+ s.append('%s: %d' % (test_type, len(self._GetType(test_type))))
+ return ', '.join(s)
+
+ def __str__(self):
+ return self.GetLongForm()
+
+ def AddResult(self, result):
+ """Add |result| to the set.
+
+ Args:
+ result: An object derived from BaseTestResult.
craigdh 2013/03/23 00:41:39 I think "An instance of BaseTestResult." is better
frankf 2013/03/23 01:32:59 Done.
frankf 2013/03/23 01:32:59 Done.
+ """
+
craigdh 2013/03/23 00:41:39 no blank line
frankf 2013/03/23 01:32:59 Done.
frankf 2013/03/23 01:32:59 Done.
+ assert isinstance(result, BaseTestResult)
+ self._results.add(result)
+
+ def AddResults(self, results):
+ """Add a set of results to this set.
craigdh 2013/03/23 00:41:39 doesn't have to be a set, can be any iterable
frankf 2013/03/23 01:32:59 Done.
frankf 2013/03/23 01:32:59 Done.
+
+ Args:
+ results: A set of objects derived from BaseTestResult.
craigdh 2013/03/23 00:41:39 ditto
frankf 2013/03/23 01:32:59 Done.
frankf 2013/03/23 01:32:59 Done.
+ """
+ for t in results:
+ self.AddResult(t)
+
+ def AddTestRunResults(self, results):
+ """Add the set of test results from |results|.
+
+ Args:
+ results: An instance of TestRunResults.
+ """
+ assert isinstance(results, TestRunResults)
+ # pylint: disable=W0212
+ self._results.update(results._results)
+
+ def GetAll(self):
+ """Get the set of all test results."""
+ return self._results.copy()
+
+ def _GetType(self, test_type):
+ """Get the set of test results with the given test type."""
+ return set([t for t in self._results if t.GetType() == test_type])
craigdh 2013/03/23 00:41:39 nit: generator expressions are more scaleable than
frankf 2013/03/23 01:32:59 I want the return type to be a set though. On 201
craigdh 2013/03/25 18:06:43 It still will be, there just won't be a (possibly
+
+ def GetPass(self):
+ """Get the set of all passed test results."""
+ return self._GetType(TestType.PASS)
+
+ def GetFail(self):
+ """Get the set of all failed test results."""
+ return self._GetType(TestType.FAIL)
+
+ def GetCrash(self):
+ """Get the set of all crashed test results."""
+ return self._GetType(TestType.CRASH)
+
+ def GetTimeout(self):
+ """Get the set of all timed out test results."""
+ return self._GetType(TestType.TIMEOUT)
+
+ def GetUnknown(self):
+ """Get the set of all unknown test results."""
+ return self._GetType(TestType.UNKNOWN)
+
+ def GetNotPass(self):
+ """Get the set of all non-passed test results."""
+ return self.GetAll() - self.GetPass()
+
+ def DidRunPass(self):
+ """Return whether the test run was succesfull"""
+ return not self.GetNotPass()

Powered by Google App Engine
This is Rietveld 408576698