Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: appengine/findit/crash/test/results_test.py

Issue 1914113002: [Findit] Enable project classifier and component classifier (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Address comments. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 common.blame import Region, Blame 5 from common.blame import Region, Blame
6 from common.change_log import ChangeLog 6 from common.change_log import ChangeLog
7 from crash.callstack import StackFrame 7 from crash.callstack import StackFrame
8 from crash.results import Result, MatchResult, MatchResults 8 from crash.results import Result, MatchResult, MatchResults
9 from crash.test.crash_test_suite import CrashTestSuite 9 from crash.test.crash_test_suite import CrashTestSuite
10 10
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 DUMMY_BLAME.AddRegion( 71 DUMMY_BLAME.AddRegion(
72 Region(1, 5, '2', 'r', 'r@chromium.org', 'Thu Mar 25 21:24:43 2016')) 72 Region(1, 5, '2', 'r', 'r@chromium.org', 'Thu Mar 25 21:24:43 2016'))
73 DUMMY_BLAME.AddRegion( 73 DUMMY_BLAME.AddRegion(
74 Region(6, 3, '1', 'e', 'e@chromium.org', 'Thu Mar 31 21:24:43 2016')) 74 Region(6, 3, '1', 'e', 'e@chromium.org', 'Thu Mar 31 21:24:43 2016'))
75 75
76 76
77 class ResultsTest(CrashTestSuite): 77 class ResultsTest(CrashTestSuite):
78 78
79 def testResultToDict(self): 79 def testResultToDict(self):
80 80
81 result = Result(DUMMY_CHANGELOG1, 'src/', '', 81 result = Result(DUMMY_CHANGELOG1, 'src/',
82 confidence=1, reason='some reason') 82 confidence=1, reason='some reason')
83 83
84 expected_result_json = { 84 expected_result_json = {
85 'url': DUMMY_CHANGELOG1.commit_url, 85 'url': DUMMY_CHANGELOG1.commit_url,
86 'revision': DUMMY_CHANGELOG1.revision, 86 'revision': DUMMY_CHANGELOG1.revision,
87 'dep_path': 'src/', 87 'dep_path': 'src/',
88 'component': '',
89 'author': DUMMY_CHANGELOG1.author_email, 88 'author': DUMMY_CHANGELOG1.author_email,
90 'time': str(DUMMY_CHANGELOG1.author_time), 89 'time': str(DUMMY_CHANGELOG1.author_time),
91 'reason': 'some reason', 90 'reason': 'some reason',
92 'confidence': 1, 91 'confidence': 1,
93 } 92 }
94 93
95 self.assertEqual(result.ToDict(), expected_result_json) 94 self.assertEqual(result.ToDict(), expected_result_json)
96 95
97 def testResultToString(self): 96 def testResultToString(self):
98 97
99 result = Result(DUMMY_CHANGELOG1, 'src/', '', 98 result = Result(DUMMY_CHANGELOG1, 'src/',
100 confidence=1, reason='some reason') 99 confidence=1, reason='some reason')
101 100
102 expected_result_str = '' 101 expected_result_str = ''
103 self.assertEqual(result.ToString(), expected_result_str) 102 self.assertEqual(result.ToString(), expected_result_str)
104 103
105 result.file_to_stack_infos = { 104 result.file_to_stack_infos = {
106 'a.cc': [(StackFrame(0, 'src/', '', 'func', 'a.cc', []), 0)] 105 'a.cc': [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', []), 0)]
107 } 106 }
108 expected_result_str = 'Changed file a.cc crashed in func (#0)' 107 expected_result_str = 'Changed file a.cc crashed in func (#0)'
109 108
110 self.assertEqual(str(result), expected_result_str) 109 self.assertEqual(str(result), expected_result_str)
111 110
112 def testMatchResultUpdate(self): 111 def testMatchResultUpdate(self):
113 # Touched lines have intersection with crashed lines. 112 # Touched lines have intersection with crashed lines.
114 result = MatchResult(DUMMY_CHANGELOG1, 'src/', '', 113 result = MatchResult(DUMMY_CHANGELOG1, 'src/',
115 confidence=1, reason='some reason') 114 confidence=1, reason='some reason')
116 stack_infos = [(StackFrame(0, 'src/', '', 'func', 'a.cc', [7]), 0)] 115 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), 0)]
117 116
118 result.Update('a.cc', stack_infos, DUMMY_BLAME) 117 result.Update('a.cc', stack_infos, DUMMY_BLAME)
119 self.assertEqual(result.min_distance, 0) 118 self.assertEqual(result.min_distance, 0)
120 119
121 # Touched lines are before crashed lines. 120 # Touched lines are before crashed lines.
122 result = MatchResult(DUMMY_CHANGELOG1, 'src/', '', 121 result = MatchResult(DUMMY_CHANGELOG1, 'src/',
123 confidence=1, reason='some reason') 122 confidence=1, reason='some reason')
124 123
125 stack_infos = [(StackFrame(0, 'src/', '', 'func', 'a.cc', [3]), 0)] 124 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [3]), 0)]
126 125
127 result.Update('a.cc', stack_infos, DUMMY_BLAME) 126 result.Update('a.cc', stack_infos, DUMMY_BLAME)
128 self.assertEqual(result.min_distance, 3) 127 self.assertEqual(result.min_distance, 3)
129 128
130 # Touched lines are after crashed lines. 129 # Touched lines are after crashed lines.
131 result = MatchResult(DUMMY_CHANGELOG1, 'src/', '', 130 result = MatchResult(DUMMY_CHANGELOG1, 'src/',
132 confidence=1, reason='some reason') 131 confidence=1, reason='some reason')
133 132
134 stack_infos = [(StackFrame(0, 'src/', '', 'func', 'a.cc', [10]), 0)] 133 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [10]), 0)]
135 134
136 result.Update('a.cc', stack_infos, DUMMY_BLAME) 135 result.Update('a.cc', stack_infos, DUMMY_BLAME)
137 self.assertEqual(result.min_distance, 2) 136 self.assertEqual(result.min_distance, 2)
138 137
139 def testMatchResultsGenerateMatchResults(self): 138 def testMatchResultsGenerateMatchResults(self):
140 match_results = MatchResults(ignore_cls=set(['2'])) 139 match_results = MatchResults(ignore_cls=set(['2']))
141 stack_infos1 = [(StackFrame(0, 'src/', '', 'func', 'a.cc', [7]), 0)] 140 stack_infos1 = [(StackFrame(
142 stack_infos2 = [(StackFrame(1, 'src/', '', 'func', 'b.cc', [11]), 0)] 141 0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), 0)]
142 stack_infos2 = [(StackFrame(
143 1, 'src/', 'func', 'b.cc', 'src/b.cc', [11]), 0)]
143 match_results.GenerateMatchResults('a.cc', 'src/', stack_infos1, 144 match_results.GenerateMatchResults('a.cc', 'src/', stack_infos1,
144 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2], 145 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2],
145 DUMMY_BLAME) 146 DUMMY_BLAME)
146 147
147 match_results.GenerateMatchResults('b.cc', 'src/', stack_infos2, 148 match_results.GenerateMatchResults('b.cc', 'src/', stack_infos2,
148 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2], 149 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2],
149 DUMMY_BLAME2) 150 DUMMY_BLAME2)
150 151
151 expected_match_result = MatchResult(DUMMY_CHANGELOG1, 'src/', '') 152 expected_match_result = MatchResult(DUMMY_CHANGELOG1, 'src/')
152 expected_match_result.file_to_stack_infos = { 153 expected_match_result.file_to_stack_infos = {
153 'a.cc': stack_infos1, 154 'a.cc': stack_infos1,
154 'b.cc': stack_infos2 155 'b.cc': stack_infos2
155 } 156 }
156 expected_match_result.min_distance = 0 157 expected_match_result.min_distance = 0
157 158
158 expected_match_results = MatchResults(ignore_cls=set(['2'])) 159 expected_match_results = MatchResults(ignore_cls=set(['2']))
159 expected_match_results['1'] = expected_match_result 160 expected_match_results['1'] = expected_match_result
160 161
161 self._VerifyTwoMatchResultsEqual(match_results, expected_match_results) 162 self._VerifyTwoMatchResultsEqual(match_results, expected_match_results)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698