| OLD | NEW |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 """Module containing base test results classes.""" | 5 """Module containing base test results classes.""" |
| 6 | 6 |
| 7 | |
| 8 class ResultType(object): | 7 class ResultType(object): |
| 9 """Class enumerating test types.""" | 8 """Class enumerating test types.""" |
| 10 PASS = 'PASS' | 9 PASS = 'PASS' |
| 11 FAIL = 'FAIL' | 10 FAIL = 'FAIL' |
| 12 CRASH = 'CRASH' | 11 CRASH = 'CRASH' |
| 13 TIMEOUT = 'TIMEOUT' | 12 TIMEOUT = 'TIMEOUT' |
| 14 UNKNOWN = 'UNKNOWN' | 13 UNKNOWN = 'UNKNOWN' |
| 15 | 14 |
| 16 @staticmethod | 15 @staticmethod |
| 17 def GetTypes(): | 16 def GetTypes(): |
| 18 """Get a list of all test types.""" | 17 """Get a list of all test types.""" |
| 19 return [ResultType.PASS, ResultType.FAIL, ResultType.CRASH, | 18 return [ResultType.PASS, ResultType.FAIL, ResultType.CRASH, |
| 20 ResultType.TIMEOUT, ResultType.UNKNOWN] | 19 ResultType.TIMEOUT, ResultType.UNKNOWN] |
| 21 | 20 |
| 22 | 21 |
| 23 class BaseTestResult(object): | 22 class BaseTestResult(object): |
| 24 """Base class for a single test result.""" | 23 """Base class for a single test result.""" |
| 24 |
| 25 def __init__(self, name, test_type, log=''): | 25 def __init__(self, name, test_type, log=''): |
| 26 """Construct a BaseTestResult. | 26 """Construct a BaseTestResult. |
| 27 | 27 |
| 28 Args: | 28 Args: |
| 29 name: Name of the test which defines uniqueness. | 29 name: Name of the test which defines uniqueness. |
| 30 test_type: Type of the test result as defined in ResultType. | 30 test_type: Type of the test result as defined in ResultType. |
| 31 log: An optional string listing any errors. | 31 log: An optional string listing any errors. |
| 32 """ | 32 """ |
| 33 assert name | 33 assert name |
| 34 assert test_type in ResultType.GetTypes() | 34 assert test_type in ResultType.GetTypes() |
| (...skipping 22 matching lines...) Expand all Loading... |
| 57 """Get the test result type.""" | 57 """Get the test result type.""" |
| 58 return self._test_type | 58 return self._test_type |
| 59 | 59 |
| 60 def GetLog(self): | 60 def GetLog(self): |
| 61 """Get the test log.""" | 61 """Get the test log.""" |
| 62 return self._log | 62 return self._log |
| 63 | 63 |
| 64 | 64 |
| 65 class TestRunResults(object): | 65 class TestRunResults(object): |
| 66 """Set of results for a test run.""" | 66 """Set of results for a test run.""" |
| 67 |
| 67 def __init__(self): | 68 def __init__(self): |
| 68 self._results = set() | 69 self._results = set() |
| 69 | 70 |
| 70 def GetLogs(self): | 71 def GetLogs(self): |
| 71 """Get the string representation of all test logs.""" | 72 """Get the string representation of all test logs.""" |
| 72 s = [] | 73 s = [] |
| 73 for test_type in ResultType.GetTypes(): | 74 for test_type in ResultType.GetTypes(): |
| 74 if test_type != ResultType.PASS: | 75 if test_type != ResultType.PASS: |
| 75 for t in sorted(self._GetType(test_type)): | 76 for t in sorted(self._GetType(test_type)): |
| 76 log = t.GetLog() | 77 log = t.GetLog() |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 """Get the set of all unknown test results.""" | 159 """Get the set of all unknown test results.""" |
| 159 return self._GetType(ResultType.UNKNOWN) | 160 return self._GetType(ResultType.UNKNOWN) |
| 160 | 161 |
| 161 def GetNotPass(self): | 162 def GetNotPass(self): |
| 162 """Get the set of all non-passed test results.""" | 163 """Get the set of all non-passed test results.""" |
| 163 return self.GetAll() - self.GetPass() | 164 return self.GetAll() - self.GetPass() |
| 164 | 165 |
| 165 def DidRunPass(self): | 166 def DidRunPass(self): |
| 166 """Return whether the test run was successful.""" | 167 """Return whether the test run was successful.""" |
| 167 return not self.GetNotPass() | 168 return not self.GetNotPass() |
| OLD | NEW |