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 import threading | 7 import threading |
8 | 8 |
9 | 9 |
10 class ResultType(object): | 10 class ResultType(object): |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 test_type: Type of the test result as defined in ResultType. | 49 test_type: Type of the test result as defined in ResultType. |
50 duration: Time it took for the test to run in milliseconds. | 50 duration: Time it took for the test to run in milliseconds. |
51 log: An optional string listing any errors. | 51 log: An optional string listing any errors. |
52 """ | 52 """ |
53 assert name | 53 assert name |
54 assert test_type in ResultType.GetTypes() | 54 assert test_type in ResultType.GetTypes() |
55 self._name = name | 55 self._name = name |
56 self._test_type = test_type | 56 self._test_type = test_type |
57 self._duration = duration | 57 self._duration = duration |
58 self._log = log | 58 self._log = log |
59 self._tombstones_url = None | 59 self._links = {} |
60 self._logcat_url = None | |
61 | 60 |
62 def __str__(self): | 61 def __str__(self): |
63 return self._name | 62 return self._name |
64 | 63 |
65 def __repr__(self): | 64 def __repr__(self): |
66 return self._name | 65 return self._name |
67 | 66 |
68 def __cmp__(self, other): | 67 def __cmp__(self, other): |
69 # pylint: disable=W0212 | 68 # pylint: disable=W0212 |
70 return cmp(self._name, other._name) | 69 return cmp(self._name, other._name) |
(...skipping 27 matching lines...) Expand all Loading... | |
98 return self._duration | 97 return self._duration |
99 | 98 |
100 def SetLog(self, log): | 99 def SetLog(self, log): |
101 """Set the test log.""" | 100 """Set the test log.""" |
102 self._log = log | 101 self._log = log |
103 | 102 |
104 def GetLog(self): | 103 def GetLog(self): |
105 """Get the test log.""" | 104 """Get the test log.""" |
106 return self._log | 105 return self._log |
107 | 106 |
108 def SetTombstonesUrl(self, tombstones_url): | 107 def AddLink(self, name, link_url): |
109 self._tombstones_url = tombstones_url | 108 """Add link with test result data.""" |
109 if name in self._links: | |
110 raise Exception('Link with name "%s" aleady exists.' % name) | |
jbudorick
2017/01/31 16:11:53
This may be better off as SetLink, with new calls
mikecase (-- gone --)
2017/01/31 23:08:25
Yeah, I like this. Done
| |
111 self._links[name] = link_url | |
110 | 112 |
111 def GetTombstonesUrl(self): | 113 def GetLinks(self): |
112 return self._tombstones_url | 114 """Get dict containing links to test result data.""" |
115 return self._links | |
113 | 116 |
114 def SetLogcatUrl(self, logcat_url): | |
115 self._logcat_url = logcat_url | |
116 | |
117 def GetLogcatUrl(self): | |
118 return self._logcat_url | |
119 | 117 |
120 class TestRunResults(object): | 118 class TestRunResults(object): |
121 """Set of results for a test run.""" | 119 """Set of results for a test run.""" |
122 | 120 |
123 def __init__(self): | 121 def __init__(self): |
122 self._links = {} | |
124 self._results = set() | 123 self._results = set() |
125 self._results_lock = threading.RLock() | 124 self._results_lock = threading.RLock() |
126 | 125 |
126 def AddLink(self, name, link_url): | |
127 """Add link with test run results data.""" | |
jbudorick
2017/01/31 16:11:53
Same.
mikecase (-- gone --)
2017/01/31 23:08:25
Done
| |
128 if name in self._links: | |
129 raise Exception('Link with name "%s" aleady exists.' % name) | |
130 self._links[name] = link_url | |
131 | |
132 def GetLinks(self): | |
133 """Get dict containing links to test run result data.""" | |
134 return self._links | |
135 | |
127 def GetLogs(self): | 136 def GetLogs(self): |
128 """Get the string representation of all test logs.""" | 137 """Get the string representation of all test logs.""" |
129 with self._results_lock: | 138 with self._results_lock: |
130 s = [] | 139 s = [] |
131 for test_type in ResultType.GetTypes(): | 140 for test_type in ResultType.GetTypes(): |
132 if test_type != ResultType.PASS: | 141 if test_type != ResultType.PASS: |
133 for t in sorted(self._GetType(test_type)): | 142 for t in sorted(self._GetType(test_type)): |
134 log = t.GetLog() | 143 log = t.GetLog() |
135 if log: | 144 if log: |
136 s.append('[%s] %s:' % (test_type, t)) | 145 s.append('[%s] %s:' % (test_type, t)) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 return self._GetType(ResultType.UNKNOWN) | 258 return self._GetType(ResultType.UNKNOWN) |
250 | 259 |
251 def GetNotPass(self): | 260 def GetNotPass(self): |
252 """Get the set of all non-passed test results.""" | 261 """Get the set of all non-passed test results.""" |
253 return self.GetAll() - self.GetPass() | 262 return self.GetAll() - self.GetPass() |
254 | 263 |
255 def DidRunPass(self): | 264 def DidRunPass(self): |
256 """Return whether the test run was successful.""" | 265 """Return whether the test run was successful.""" |
257 return not self.GetNotPass() - self.GetSkip() | 266 return not self.GetNotPass() - self.GetSkip() |
258 | 267 |
OLD | NEW |