| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 from collections import namedtuple | 5 from collections import namedtuple |
| 6 | 6 |
| 7 # TODO(http://crbug.com/659346): We do call this code from various | 7 |
| 8 # unittests, just not from culprit_test.py; so we need to add some extra | |
| 9 # unittests there. | |
| 10 class Culprit(namedtuple('Culprit', | 8 class Culprit(namedtuple('Culprit', |
| 11 ['project', 'components', 'cls', 'regression_range', 'algorithm'] | 9 ['project', 'components', 'cls', 'regression_range', 'algorithm'])): |
| 12 )): # pragma: no cover | |
| 13 """The result of successfully identifying the culprit of a crash report. | 10 """The result of successfully identifying the culprit of a crash report. |
| 14 | 11 |
| 15 Args: | 12 Args: |
| 16 project (str): the most-suspected project | 13 project (str): the most-suspected project |
| 17 components (list of str): the suspected crbug components. | 14 components (list of str): the suspected crbug components. |
| 18 cls (list of ??): the suspected CLs. | 15 cls (list of ??): the suspected CLs. |
| 19 regression_range (tuple): a pair of the last-good and first-bad versions. | 16 regression_range (tuple): a pair of the last-good and first-bad versions. |
| 20 algorithm (str): What algorithm was used to produce this object. | 17 algorithm (str): What algorithm was used to produce this object. |
| 21 """ | 18 """ |
| 22 __slots__ = () | 19 __slots__ = () |
| 23 | 20 |
| 24 @property | 21 @property |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 """ | 91 """ |
| 95 # TODO(wrengr): will this auto-dropping of unnecessary fields cause | 92 # TODO(wrengr): will this auto-dropping of unnecessary fields cause |
| 96 # any issues for JSON serialization? | 93 # any issues for JSON serialization? |
| 97 result = {} | 94 result = {} |
| 98 result['found'] = ( | 95 result['found'] = ( |
| 99 bool(self.project) or | 96 bool(self.project) or |
| 100 bool(self.components) or | 97 bool(self.components) or |
| 101 bool(self.cls) or | 98 bool(self.cls) or |
| 102 bool(self.regression_range)) | 99 bool(self.regression_range)) |
| 103 if self.regression_range: | 100 if self.regression_range: |
| 101 assert isinstance(self.regression_range, list) |
| 104 result['regression_range'] = self.regression_range | 102 result['regression_range'] = self.regression_range |
| 105 if self.project is not None: | 103 if self.project: |
| 106 result['suspected_project'] = self.project | 104 result['suspected_project'] = self.project |
| 107 if self.components is not None: | 105 if self.components: |
| 108 result['suspected_components'] = self.components | 106 result['suspected_components'] = self.components |
| 109 if self.cls is not None: | 107 if self.cls: |
| 110 result['suspected_cls'] = [cl.ToDict() for cl in self.cls] | 108 result['suspected_cls'] = [cl.ToDict() for cl in self.cls] |
| 111 | 109 |
| 112 tags = { | 110 tags = { |
| 113 'found_suspects': bool(self.cls), | 111 'found_suspects': bool(self.cls), |
| 114 'has_regression_range': bool(self.regression_range), | 112 'has_regression_range': bool(self.regression_range), |
| 115 'found_project': bool(self.project), | 113 'found_project': bool(self.project), |
| 116 'found_components': bool(self.components), | 114 'found_components': bool(self.components), |
| 117 'solution': self.algorithm, | 115 'solution': self.algorithm, |
| 118 } | 116 } |
| 119 | 117 |
| 120 return result, tags | 118 return result, tags |
| OLD | NEW |