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 class ResultType(object): | 7 class ResultType(object): |
8 """Class enumerating test types.""" | 8 """Class enumerating test types.""" |
9 PASS = 'PASS' | 9 PASS = 'PASS' |
10 FAIL = 'FAIL' | 10 FAIL = 'FAIL' |
11 CRASH = 'CRASH' | 11 CRASH = 'CRASH' |
12 TIMEOUT = 'TIMEOUT' | 12 TIMEOUT = 'TIMEOUT' |
13 UNKNOWN = 'UNKNOWN' | 13 UNKNOWN = 'UNKNOWN' |
14 | 14 |
15 @staticmethod | 15 @staticmethod |
16 def GetTypes(): | 16 def GetTypes(): |
17 """Get a list of all test types.""" | 17 """Get a list of all test types.""" |
18 return [ResultType.PASS, ResultType.FAIL, ResultType.CRASH, | 18 return [ResultType.PASS, ResultType.FAIL, ResultType.CRASH, |
19 ResultType.TIMEOUT, ResultType.UNKNOWN] | 19 ResultType.TIMEOUT, ResultType.UNKNOWN] |
20 | 20 |
21 | 21 |
22 class BaseTestResult(object): | 22 class BaseTestResult(object): |
23 """Base class for a single test result.""" | 23 """Base class for a single test result.""" |
24 | 24 |
25 def __init__(self, name, test_type, tag='', 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() |
35 self._name = name | 35 self._name = name |
36 self._test_type = test_type | 36 self._test_type = test_type |
37 self._tag = tag | |
38 self._log = log | 37 self._log = log |
39 | 38 |
40 def __str__(self): | 39 def __str__(self): |
41 return self.GetTaggedName() | 40 return self._name |
42 | 41 |
43 def __repr__(self): | 42 def __repr__(self): |
44 return self.GetTaggedName() | 43 return self._name |
45 | 44 |
46 def __cmp__(self, other): | 45 def __cmp__(self, other): |
47 # pylint: disable=W0212 | 46 # pylint: disable=W0212 |
48 return cmp(self.GetTaggedName(), other.GetTaggedName()) | 47 return cmp(self._name, other._name) |
49 | 48 |
50 def __hash__(self): | 49 def __hash__(self): |
51 return hash(self.GetTaggedName()) | 50 return hash(self._name) |
52 | 51 |
53 def GetTaggedName(self): | 52 def SetName(self, name): |
54 """Get the test name with tag.""" | 53 """Set the test name. |
55 if self._tag: | 54 |
56 return '%s_%s' % (self._tag, self._name) | 55 Because we're putting this into a set, this should only be used if moving |
57 else: | 56 this test result into another set. |
58 return self._name | 57 """ |
| 58 self._name = name |
59 | 59 |
60 def GetName(self): | 60 def GetName(self): |
61 """Get the test name.""" | 61 """Get the test name.""" |
62 return self._name | 62 return self._name |
63 | 63 |
64 def GetType(self): | 64 def GetType(self): |
65 """Get the test result type.""" | 65 """Get the test result type.""" |
66 return self._test_type | 66 return self._test_type |
67 | 67 |
68 def GetTag(self): | |
69 """Get the test tag.""" | |
70 return self._tag | |
71 | |
72 def GetLog(self): | 68 def GetLog(self): |
73 """Get the test log.""" | 69 """Get the test log.""" |
74 return self._log | 70 return self._log |
75 | 71 |
76 def SetTag(self, tag): | |
77 """Set the test tag.""" | |
78 self._tag = tag | |
79 | |
80 | 72 |
81 class TestRunResults(object): | 73 class TestRunResults(object): |
82 """Set of results for a test run.""" | 74 """Set of results for a test run.""" |
83 | 75 |
84 def __init__(self): | 76 def __init__(self): |
85 self._results = set() | 77 self._results = set() |
86 | 78 |
87 def GetLogs(self): | 79 def GetLogs(self): |
88 """Get the string representation of all test logs.""" | 80 """Get the string representation of all test logs.""" |
89 s = [] | 81 s = [] |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 """Get the set of all unknown test results.""" | 167 """Get the set of all unknown test results.""" |
176 return self._GetType(ResultType.UNKNOWN) | 168 return self._GetType(ResultType.UNKNOWN) |
177 | 169 |
178 def GetNotPass(self): | 170 def GetNotPass(self): |
179 """Get the set of all non-passed test results.""" | 171 """Get the set of all non-passed test results.""" |
180 return self.GetAll() - self.GetPass() | 172 return self.GetAll() - self.GetPass() |
181 | 173 |
182 def DidRunPass(self): | 174 def DidRunPass(self): |
183 """Return whether the test run was successful.""" | 175 """Return whether the test run was successful.""" |
184 return not self.GetNotPass() | 176 return not self.GetNotPass() |
OLD | NEW |