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

Side by Side Diff: appengine/findit/waterfall/test/build_failure_analysis_test.py

Issue 2344443005: [Findit] Factoring the gitiles (etc) stuff out into its own directory (Closed)
Patch Set: reverted unintended change to an __init__ file Created 4 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 datetime import datetime 5 from datetime import datetime
6 6
7 from common.blame import Blame 7 from lib.gitiles.blame import Blame
8 from common.blame import Region 8 from lib.gitiles.blame import Region
9 from common.change_log import FileChangeInfo 9 from lib.gitiles.change_log import FileChangeInfo
10 from common.diff import ChangeType 10 from lib.gitiles.diff import ChangeType
11 from common.git_repository import GitRepository 11 from lib.gitiles.gitiles_repository import GitilesRepository
stgao 2016/10/28 18:21:00 order of import
wrengr 2016/10/28 19:24:49 Done.
12 from common.waterfall import failure_type 12 from common.waterfall import failure_type
13 from waterfall import build_failure_analysis 13 from waterfall import build_failure_analysis
14 from waterfall.failure_signal import FailureSignal 14 from waterfall.failure_signal import FailureSignal
15 from waterfall.test import wf_testcase 15 from waterfall.test import wf_testcase
16 16
17 17
18 class BuildFailureAnalysisTest(wf_testcase.WaterfallTestCase): 18 class BuildFailureAnalysisTest(wf_testcase.WaterfallTestCase):
19 19
20 def _MockGetChangeLog(self, revision): 20 def _MockGetChangeLog(self, revision):
21 21
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 deps_info = {} 255 deps_info = {}
256 256
257 justification = build_failure_analysis._CheckFiles( 257 justification = build_failure_analysis._CheckFiles(
258 FailureSignal.FromDict(failure_signal_json), 258 FailureSignal.FromDict(failure_signal_json),
259 change_log_json, deps_info) 259 change_log_json, deps_info)
260 self.assertIsNone(justification) 260 self.assertIsNone(justification)
261 261
262 def _testCheckFileInDependencyRoll( 262 def _testCheckFileInDependencyRoll(
263 self, file_path_in_log, rolls, expected_score, line_numbers, 263 self, file_path_in_log, rolls, expected_score, line_numbers,
264 expected_hints=None): 264 expected_hints=None):
265 self.mock(GitRepository, 'GetChangeLog', self._MockGetChangeLog) 265 self.mock(GitilesRepository, 'GetChangeLog', self._MockGetChangeLog)
266 self.mock(GitRepository, 'GetBlame', self._MockGetBlame) 266 self.mock(GitilesRepository, 'GetBlame', self._MockGetBlame)
267 self.mock(GitRepository, 'GetCommitsBetweenRevisions', 267 self.mock(GitilesRepository, 'GetCommitsBetweenRevisions',
268 self._MockGetCommitsBetweenRevisions) 268 self._MockGetCommitsBetweenRevisions)
269 justification = build_failure_analysis._Justification() 269 justification = build_failure_analysis._Justification()
270 build_failure_analysis._CheckFileInDependencyRolls( 270 build_failure_analysis._CheckFileInDependencyRolls(
271 file_path_in_log, rolls, justification, line_numbers) 271 file_path_in_log, rolls, justification, line_numbers)
272 self.assertEqual(expected_score, justification.score) 272 self.assertEqual(expected_score, justification.score)
273 if expected_hints: 273 if expected_hints:
274 self.assertEqual(expected_hints, justification._hints) 274 self.assertEqual(expected_hints, justification._hints)
275 275
276 def testCheckFileInDependencyRollWhenUnrelatedDependencyIsRolled(self): 276 def testCheckFileInDependencyRollWhenUnrelatedDependencyIsRolled(self):
277 file_path_in_log = 'third_party/dep/f.cc' 277 file_path_in_log = 'third_party/dep/f.cc'
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 'rev': [ 517 'rev': [
518 { 518 {
519 'path': 'src/third_party/dep1/', 519 'path': 'src/third_party/dep1/',
520 'repo_url': 'https://url_dep1', 520 'repo_url': 'https://url_dep1',
521 'old_revision': '7', 521 'old_revision': '7',
522 'new_revision': '9', 522 'new_revision': '9',
523 }, 523 },
524 ] 524 ]
525 } 525 }
526 } 526 }
527 self.mock(GitRepository, 'GetChangeLog', self._MockGetChangeLog) 527 self.mock(GitilesRepository, 'GetChangeLog', self._MockGetChangeLog)
528 self.mock(GitRepository, 'GetCommitsBetweenRevisions', 528 self.mock(GitilesRepository, 'GetCommitsBetweenRevisions',
529 self._MockGetCommitsBetweenRevisions) 529 self._MockGetCommitsBetweenRevisions)
530 self.mock(GitRepository, 'GetBlame', self._MockGetBlame) 530 self.mock(GitilesRepository, 'GetBlame', self._MockGetBlame)
531 justification = build_failure_analysis._CheckFiles( 531 justification = build_failure_analysis._CheckFiles(
532 FailureSignal.FromDict(failure_signal_json), 532 FailureSignal.FromDict(failure_signal_json),
533 change_log_json, deps_info) 533 change_log_json, deps_info)
534 self.assertIsNotNone(justification) 534 self.assertIsNotNone(justification)
535 # The score is 1 because: 535 # The score is 1 because:
536 # +1 rolled third_party/dep1/ and src/third_party/dep1/f.cc was in log. 536 # +1 rolled third_party/dep1/ and src/third_party/dep1/f.cc was in log.
537 self.assertEqual(1, justification['score']) 537 self.assertEqual(1, justification['score'])
538 538
539 def testAnalyzeSuccessfulBuild(self): 539 def testAnalyzeSuccessfulBuild(self):
540 failure_info = { 540 failure_info = {
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 failure_info, change_logs, deps_info, failure_signals_json) 1096 failure_info, change_logs, deps_info, failure_signals_json)
1097 self.assertEqual(expected_analysis_result, analysis_result) 1097 self.assertEqual(expected_analysis_result, analysis_result)
1098 self.assertEqual([], suspected_cls) 1098 self.assertEqual([], suspected_cls)
1099 1099
1100 def testGetGitBlame(self): 1100 def testGetGitBlame(self):
1101 repo_info = { 1101 repo_info = {
1102 'repo_url': 'https://chromium.googlesource.com/chromium/src.git', 1102 'repo_url': 'https://chromium.googlesource.com/chromium/src.git',
1103 'revision': '8' 1103 'revision': '8'
1104 } 1104 }
1105 file_path = 'a/b/c.cc' 1105 file_path = 'a/b/c.cc'
1106 self.mock(GitRepository, 'GetBlame', self._MockGetBlame) 1106 self.mock(GitilesRepository, 'GetBlame', self._MockGetBlame)
1107 blame = build_failure_analysis._GetGitBlame(repo_info, file_path) 1107 blame = build_failure_analysis._GetGitBlame(repo_info, file_path)
1108 self.assertIsNotNone(blame) 1108 self.assertIsNotNone(blame)
1109 1109
1110 def testGetGitBlameEmpty(self): 1110 def testGetGitBlameEmpty(self):
1111 repo_info = {} 1111 repo_info = {}
1112 file_path = 'a/b/c.cc' 1112 file_path = 'a/b/c.cc'
1113 self.mock(GitRepository, 'GetBlame', self._MockGetBlame) 1113 self.mock(GitilesRepository, 'GetBlame', self._MockGetBlame)
1114 blame = build_failure_analysis._GetGitBlame(repo_info, file_path) 1114 blame = build_failure_analysis._GetGitBlame(repo_info, file_path)
1115 self.assertIsNone(blame) 1115 self.assertIsNone(blame)
1116 1116
1117 def testGetChangedLinesTrue(self): 1117 def testGetChangedLinesTrue(self):
1118 repo_info = { 1118 repo_info = {
1119 'repo_url': 'https://chromium.googlesource.com/chromium/src.git', 1119 'repo_url': 'https://chromium.googlesource.com/chromium/src.git',
1120 'revision': '8' 1120 'revision': '8'
1121 } 1121 }
1122 touched_file = { 1122 touched_file = {
1123 'change_type': ChangeType.MODIFY, 1123 'change_type': ChangeType.MODIFY,
1124 'old_path': 'a/b/c.cc', 1124 'old_path': 'a/b/c.cc',
1125 'new_path': 'a/b/c.cc' 1125 'new_path': 'a/b/c.cc'
1126 } 1126 }
1127 line_numbers = [2, 7, 8] 1127 line_numbers = [2, 7, 8]
1128 commit_revision = '7' 1128 commit_revision = '7'
1129 self.mock(GitRepository, 'GetBlame', self._MockGetBlame) 1129 self.mock(GitilesRepository, 'GetBlame', self._MockGetBlame)
1130 changed_line_numbers = ( 1130 changed_line_numbers = (
1131 build_failure_analysis._GetChangedLinesForChromiumRepo( 1131 build_failure_analysis._GetChangedLinesForChromiumRepo(
1132 repo_info, touched_file, line_numbers, commit_revision)) 1132 repo_info, touched_file, line_numbers, commit_revision))
1133 1133
1134 self.assertEqual([2, 8], changed_line_numbers) 1134 self.assertEqual([2, 8], changed_line_numbers)
1135 1135
1136 def testGetChangedLinesDifferentRevision(self): 1136 def testGetChangedLinesDifferentRevision(self):
1137 repo_info = { 1137 repo_info = {
1138 'repo_url': 'https://chromium.googlesource.com/chromium/src.git', 1138 'repo_url': 'https://chromium.googlesource.com/chromium/src.git',
1139 'revision': '9' 1139 'revision': '9'
1140 } 1140 }
1141 touched_file = { 1141 touched_file = {
1142 'change_type': ChangeType.MODIFY, 1142 'change_type': ChangeType.MODIFY,
1143 'old_path': 'a/b/c.cc', 1143 'old_path': 'a/b/c.cc',
1144 'new_path': 'a/b/c.cc' 1144 'new_path': 'a/b/c.cc'
1145 } 1145 }
1146 line_numbers = [2, 7, 8] 1146 line_numbers = [2, 7, 8]
1147 commit_revision = '9' 1147 commit_revision = '9'
1148 self.mock(GitRepository, 'GetBlame', self._MockGetBlame) 1148 self.mock(GitilesRepository, 'GetBlame', self._MockGetBlame)
1149 changed_line_numbers = ( 1149 changed_line_numbers = (
1150 build_failure_analysis._GetChangedLinesForChromiumRepo( 1150 build_failure_analysis._GetChangedLinesForChromiumRepo(
1151 repo_info, touched_file, line_numbers, commit_revision)) 1151 repo_info, touched_file, line_numbers, commit_revision))
1152 1152
1153 self.assertEqual([], changed_line_numbers) 1153 self.assertEqual([], changed_line_numbers)
1154 1154
1155 def testGetChangedLinesDifferentLine(self): 1155 def testGetChangedLinesDifferentLine(self):
1156 repo_info = { 1156 repo_info = {
1157 'repo_url': 'https://chromium.googlesource.com/chromium/src.git', 1157 'repo_url': 'https://chromium.googlesource.com/chromium/src.git',
1158 'revision': '8' 1158 'revision': '8'
1159 } 1159 }
1160 touched_file = { 1160 touched_file = {
1161 'change_type': ChangeType.MODIFY, 1161 'change_type': ChangeType.MODIFY,
1162 'old_path': 'a/b/c.cc', 1162 'old_path': 'a/b/c.cc',
1163 'new_path': 'a/b/c.cc' 1163 'new_path': 'a/b/c.cc'
1164 } 1164 }
1165 line_numbers = [15] 1165 line_numbers = [15]
1166 commit_revision = '7' 1166 commit_revision = '7'
1167 self.mock(GitRepository, 'GetBlame', self._MockGetBlame) 1167 self.mock(GitilesRepository, 'GetBlame', self._MockGetBlame)
1168 changed_line_numbers = ( 1168 changed_line_numbers = (
1169 build_failure_analysis._GetChangedLinesForChromiumRepo( 1169 build_failure_analysis._GetChangedLinesForChromiumRepo(
1170 repo_info, touched_file, line_numbers, commit_revision)) 1170 repo_info, touched_file, line_numbers, commit_revision))
1171 1171
1172 self.assertEqual([], changed_line_numbers) 1172 self.assertEqual([], changed_line_numbers)
1173 1173
1174 def testGetChangedLinesNoneBlame(self): 1174 def testGetChangedLinesNoneBlame(self):
1175 repo_info = { 1175 repo_info = {
1176 'repo_url': 'https://chromium.googlesource.com/chromium/src.git', 1176 'repo_url': 'https://chromium.googlesource.com/chromium/src.git',
1177 'revision': '10' 1177 'revision': '10'
1178 } 1178 }
1179 touched_file = { 1179 touched_file = {
1180 'change_type': ChangeType.MODIFY, 1180 'change_type': ChangeType.MODIFY,
1181 'old_path': 'a/b/c.cc', 1181 'old_path': 'a/b/c.cc',
1182 'new_path': 'a/b/c.cc' 1182 'new_path': 'a/b/c.cc'
1183 } 1183 }
1184 line_numbers = [2, 7, 8] 1184 line_numbers = [2, 7, 8]
1185 commit_revision = '7' 1185 commit_revision = '7'
1186 self.mock(GitRepository, 'GetBlame', self._MockGetBlame) 1186 self.mock(GitilesRepository, 'GetBlame', self._MockGetBlame)
1187 changed_line_numbers = ( 1187 changed_line_numbers = (
1188 build_failure_analysis._GetChangedLinesForChromiumRepo( 1188 build_failure_analysis._GetChangedLinesForChromiumRepo(
1189 repo_info, touched_file, line_numbers, commit_revision)) 1189 repo_info, touched_file, line_numbers, commit_revision))
1190 1190
1191 self.assertEqual([], changed_line_numbers) 1191 self.assertEqual([], changed_line_numbers)
1192 1192
1193 def testCheckFileSameLineChanged(self): 1193 def testCheckFileSameLineChanged(self):
1194 def MockGetChangedLines(*_): 1194 def MockGetChangedLines(*_):
1195 return [1, 3] 1195 return [1, 3]
1196 self.mock(build_failure_analysis, '_GetChangedLinesForChromiumRepo', 1196 self.mock(build_failure_analysis, '_GetChangedLinesForChromiumRepo',
(...skipping 16 matching lines...) Expand all
1213 touched_file, file_path_in_log, justification, file_name_occurrences, 1213 touched_file, file_path_in_log, justification, file_name_occurrences,
1214 line_numbers, repo_info, commit_revision) 1214 line_numbers, repo_info, commit_revision)
1215 1215
1216 expected_justification = { 1216 expected_justification = {
1217 'score': 4, 1217 'score': 4,
1218 'hints': { 1218 'hints': {
1219 'modified c.cc[1, 3] (and it was in log)': 4 1219 'modified c.cc[1, 3] (and it was in log)': 4
1220 } 1220 }
1221 } 1221 }
1222 self.assertEqual(expected_justification, justification.ToDict()) 1222 self.assertEqual(expected_justification, justification.ToDict())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698