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 from pylib import constants | |
frankf
2013/07/04 00:46:19
Remove this
gkanwar
2013/07/08 18:50:25
Done.
| |
7 | 8 |
8 class ResultType(object): | 9 class ResultType(object): |
9 """Class enumerating test types.""" | 10 """Class enumerating test types.""" |
10 PASS = 'PASS' | 11 PASS = 'PASS' |
11 FAIL = 'FAIL' | 12 FAIL = 'FAIL' |
12 CRASH = 'CRASH' | 13 CRASH = 'CRASH' |
13 TIMEOUT = 'TIMEOUT' | 14 TIMEOUT = 'TIMEOUT' |
14 UNKNOWN = 'UNKNOWN' | 15 UNKNOWN = 'UNKNOWN' |
15 | 16 |
16 @staticmethod | 17 @staticmethod |
17 def GetTypes(): | 18 def GetTypes(): |
18 """Get a list of all test types.""" | 19 """Get a list of all test types.""" |
19 return [ResultType.PASS, ResultType.FAIL, ResultType.CRASH, | 20 return [ResultType.PASS, ResultType.FAIL, ResultType.CRASH, |
20 ResultType.TIMEOUT, ResultType.UNKNOWN] | 21 ResultType.TIMEOUT, ResultType.UNKNOWN] |
21 | 22 |
22 | 23 |
23 class BaseTestResult(object): | 24 class BaseTestResult(object): |
24 """Base class for a single test result.""" | 25 """Base class for a single test result.""" |
26 | |
25 def __init__(self, name, test_type, log=''): | 27 def __init__(self, name, test_type, log=''): |
26 """Construct a BaseTestResult. | 28 """Construct a BaseTestResult. |
27 | 29 |
28 Args: | 30 Args: |
29 name: Name of the test which defines uniqueness. | 31 name: Name of the test which defines uniqueness. |
30 test_type: Type of the test result as defined in ResultType. | 32 test_type: Type of the test result as defined in ResultType. |
31 log: An optional string listing any errors. | 33 log: An optional string listing any errors. |
32 """ | 34 """ |
33 assert name | 35 assert name |
34 assert test_type in ResultType.GetTypes() | 36 assert test_type in ResultType.GetTypes() |
(...skipping 22 matching lines...) Expand all Loading... | |
57 """Get the test result type.""" | 59 """Get the test result type.""" |
58 return self._test_type | 60 return self._test_type |
59 | 61 |
60 def GetLog(self): | 62 def GetLog(self): |
61 """Get the test log.""" | 63 """Get the test log.""" |
62 return self._log | 64 return self._log |
63 | 65 |
64 | 66 |
65 class TestRunResults(object): | 67 class TestRunResults(object): |
66 """Set of results for a test run.""" | 68 """Set of results for a test run.""" |
69 | |
67 def __init__(self): | 70 def __init__(self): |
68 self._results = set() | 71 self._results = set() |
69 | 72 |
70 def GetLogs(self): | 73 def GetLogs(self): |
71 """Get the string representation of all test logs.""" | 74 """Get the string representation of all test logs.""" |
72 s = [] | 75 s = [] |
73 for test_type in ResultType.GetTypes(): | 76 for test_type in ResultType.GetTypes(): |
74 if test_type != ResultType.PASS: | 77 if test_type != ResultType.PASS: |
75 for t in sorted(self._GetType(test_type)): | 78 for t in sorted(self._GetType(test_type)): |
76 log = t.GetLog() | 79 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.""" | 161 """Get the set of all unknown test results.""" |
159 return self._GetType(ResultType.UNKNOWN) | 162 return self._GetType(ResultType.UNKNOWN) |
160 | 163 |
161 def GetNotPass(self): | 164 def GetNotPass(self): |
162 """Get the set of all non-passed test results.""" | 165 """Get the set of all non-passed test results.""" |
163 return self.GetAll() - self.GetPass() | 166 return self.GetAll() - self.GetPass() |
164 | 167 |
165 def DidRunPass(self): | 168 def DidRunPass(self): |
166 """Return whether the test run was successful.""" | 169 """Return whether the test run was successful.""" |
167 return not self.GetNotPass() | 170 return not self.GetNotPass() |
OLD | NEW |