OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 | 6 |
7 import datetime | 7 import datetime |
8 import unittest | 8 import unittest |
9 | 9 |
10 import auto_roll | 10 import auto_roll |
| 11 import sys |
11 | 12 |
12 # auto_roll.py imports find_depot_tools. | 13 # auto_roll.py imports find_depot_tools. |
13 from testing_support.super_mox import SuperMoxTestBase | 14 from testing_support.super_mox import SuperMoxTestBase |
14 | 15 |
15 | 16 |
16 # pylint: disable=W0212 | 17 # pylint: disable=W0212 |
17 | 18 |
18 | 19 |
19 class RevisionLinkTest(SuperMoxTestBase): | 20 class RevisionLinkTest(SuperMoxTestBase): |
20 def test_blink(self): | 21 def test_blink(self): |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 'created': created_datetime or self.RECENT_ISSUE_CREATED_STR, | 133 'created': created_datetime or self.RECENT_ISSUE_CREATED_STR, |
133 'description': 'Test_Project roll %s:%s' % (self._display_rev(old_rev), | 134 'description': 'Test_Project roll %s:%s' % (self._display_rev(old_rev), |
134 self._display_rev(new_rev)), | 135 self._display_rev(new_rev)), |
135 'issue': 1234567, | 136 'issue': 1234567, |
136 'messages': [], | 137 'messages': [], |
137 'modified': created_datetime or self.RECENT_ISSUE_CREATED_STR, | 138 'modified': created_datetime or self.RECENT_ISSUE_CREATED_STR, |
138 'subject': 'Test_Project roll %s:%s' % (old_rev, new_rev), | 139 'subject': 'Test_Project roll %s:%s' % (old_rev, new_rev), |
139 } | 140 } |
140 | 141 |
141 def _get_last_revision(self): | 142 def _get_last_revision(self): |
142 auto_roll.subprocess2.check_call( | |
143 ['git', '--git-dir', './.git', 'fetch']) | |
144 auto_roll.subprocess2.check_output( | 143 auto_roll.subprocess2.check_output( |
145 ['git', '--git-dir', './.git', 'show', 'origin/master:DEPS'] | 144 ['git', '--git-dir', './.git', 'show', 'origin/master:DEPS'] |
146 ).AndReturn(self.DEPS_CONTENT) | 145 ).AndReturn(self.DEPS_CONTENT) |
147 | 146 |
148 def _get_current_revision(self): | 147 def _get_current_revision(self): |
149 auto_roll.subprocess2.check_call( | |
150 ['git', '--git-dir', './third_party/test_project/.git', 'fetch']) | |
151 if self._arb._git_mode: | 148 if self._arb._git_mode: |
152 self._parse_origin_master(returnval=self.NEW_REV) | 149 self._parse_origin_master(returnval=self.NEW_REV) |
153 else: | 150 else: |
154 auto_roll.subprocess2.check_output( | 151 auto_roll.subprocess2.check_output( |
155 ['git', '--git-dir', './third_party/test_project/.git', 'show', '-s', | 152 ['git', '--git-dir', './third_party/test_project/.git', 'show', '-s', |
156 'origin/master']).AndReturn(self.GIT_LOG_UPDATED) | 153 'origin/master']).AndReturn(self.GIT_LOG_UPDATED) |
157 | 154 |
158 def _upload_issue(self, custom_message=None): | 155 def _upload_issue(self, custom_message=None): |
| 156 auto_roll.subprocess2.check_call( |
| 157 ['git', '--git-dir', './.git', 'fetch']) |
| 158 auto_roll.subprocess2.check_call( |
| 159 ['git', '--git-dir', './third_party/test_project/.git', 'fetch']) |
| 160 |
159 self._get_last_revision() | 161 self._get_last_revision() |
160 self._get_current_revision() | 162 self._get_current_revision() |
| 163 if self._arb._git_mode: |
| 164 auto_roll.subprocess2.check_output( |
| 165 ['git', '--git-dir', './third_party/test_project/.git', 'show', '-s', |
| 166 'origin/master']).AndReturn(self.GIT_LOG_UPDATED) |
| 167 |
161 self._compare_revs(self.OLD_REV, self.NEW_REV) | 168 self._compare_revs(self.OLD_REV, self.NEW_REV) |
162 | 169 |
163 auto_roll.subprocess2.check_call(['git', 'clean', '-d', '-f'], cwd='.') | 170 auto_roll.subprocess2.check_call(['git', 'clean', '-d', '-f'], cwd='.') |
164 auto_roll.subprocess2.call(['git', 'rebase', '--abort'], cwd='.') | 171 auto_roll.subprocess2.call(['git', 'rebase', '--abort'], cwd='.') |
165 auto_roll.subprocess2.call(['git', 'branch', '-D', 'test_project_roll'], | 172 auto_roll.subprocess2.call(['git', 'branch', '-D', 'test_project_roll'], |
166 cwd='.') | 173 cwd='.') |
167 auto_roll.subprocess2.check_call(['git', 'checkout', 'origin/master', '-f'], | 174 auto_roll.subprocess2.check_call(['git', 'checkout', 'origin/master', '-f'], |
168 cwd='.') | 175 cwd='.') |
169 auto_roll.subprocess2.check_call(['git', 'checkout', | 176 auto_roll.subprocess2.check_call(['git', 'checkout', |
170 '-b', 'test_project_roll', | 177 '-b', 'test_project_roll', |
171 '-t', 'origin/master', '-f'], cwd='.') | 178 '-t', 'origin/master', '-f'], cwd='.') |
172 | 179 |
173 from_rev = self._display_rev(self.OLD_REV) | 180 from_rev = self._display_rev(self.OLD_REV) |
174 to_rev = self._display_rev(self.NEW_REV) | 181 to_rev = self._display_rev(self.NEW_REV) |
175 message = custom_message or 'Test_Project roll %s:%s' % (from_rev, to_rev) | 182 |
| 183 if custom_message: |
| 184 message = custom_message |
| 185 else: |
| 186 message = 'Test_Project roll %s:%s' % (from_rev, to_rev) |
| 187 if self._arb._git_mode: |
| 188 message += ' (svn %s:%s)' % (self.OLD_SVN_REV, self.NEW_SVN_REV) |
| 189 |
176 message += '\nTBR=' | 190 message += '\nTBR=' |
177 auto_roll.subprocess2.check_call( | 191 auto_roll.subprocess2.check_call( |
178 ['roll-dep', 'third_party/%s' % self.TEST_PROJECT, str(self.NEW_REV)], | 192 ['roll-dep', 'third_party/%s' % self.TEST_PROJECT, str(self.NEW_REV)], |
179 cwd='.') | 193 cwd='.') |
180 | 194 |
181 auto_roll.subprocess2.check_call(['git', 'add', 'DEPS'], cwd='.') | 195 auto_roll.subprocess2.check_call(['git', 'add', 'DEPS'], cwd='.') |
182 auto_roll.subprocess2.check_call(['git', 'commit', '-m', message], cwd='.') | 196 auto_roll.subprocess2.check_call(['git', 'commit', '-m', message], cwd='.') |
183 auto_roll.subprocess2.check_call(['git', 'cl', 'upload', '--bypass-hooks', | 197 auto_roll.subprocess2.check_call(['git', 'cl', 'upload', '--bypass-hooks', |
184 '--use-commit-queue', '-f', | 198 '--use-commit-queue', '-f', |
185 '-m', message], | 199 '-m', message], |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 239 |
226 def test_already_rolling(self): | 240 def test_already_rolling(self): |
227 if self.__class__.__name__ == 'AutoRollTestBase': | 241 if self.__class__.__name__ == 'AutoRollTestBase': |
228 return | 242 return |
229 issue = self._make_issue() | 243 issue = self._make_issue() |
230 search_results = [issue] | 244 search_results = [issue] |
231 self._arb._rietveld.search(owner=self.TEST_AUTHOR, | 245 self._arb._rietveld.search(owner=self.TEST_AUTHOR, |
232 closed=2).AndReturn(search_results) | 246 closed=2).AndReturn(search_results) |
233 self._arb._rietveld.get_issue_properties(issue['issue'], | 247 self._arb._rietveld.get_issue_properties(issue['issue'], |
234 messages=True).AndReturn(issue) | 248 messages=True).AndReturn(issue) |
235 auto_roll.subprocess2.check_call( | |
236 ['git', '--git-dir', './.git', 'fetch']) | |
237 auto_roll.subprocess2.check_output( | 249 auto_roll.subprocess2.check_output( |
238 ['git', '--git-dir', './.git', 'show', 'origin/master:DEPS'] | 250 ['git', '--git-dir', './.git', 'show', 'origin/master:DEPS'] |
239 ).AndReturn(self.DEPS_CONTENT) | 251 ).AndReturn(self.DEPS_CONTENT) |
240 if self._arb._git_mode: | 252 if self._arb._git_mode: |
241 self._short_rev(self.OLD_REV) | 253 self._short_rev(self.OLD_REV) |
242 self.mox.ReplayAll() | 254 self.mox.ReplayAll() |
243 self.assertEquals(self._arb.main(), 0) | 255 self.assertEquals(self._arb.main(), 0) |
244 self.checkstdout('https://codereview.chromium.org/%d/ started %s ago\n' | 256 self.checkstdout('https://codereview.chromium.org/%d/ started %s ago\n' |
245 'https://codereview.chromium.org/%d/ is still active, ' | 257 'https://codereview.chromium.org/%d/ is still active, ' |
246 'nothing to do.\n' | 258 'nothing to do.\n' |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 ['git', '--git-dir', './.git', 'fetch']) | 307 ['git', '--git-dir', './.git', 'fetch']) |
296 auto_roll.subprocess2.check_output( | 308 auto_roll.subprocess2.check_output( |
297 ['git', '--git-dir', './.git', 'show', 'origin/master:DEPS'] | 309 ['git', '--git-dir', './.git', 'show', 'origin/master:DEPS'] |
298 ).AndReturn(self.DEPS_CONTENT) | 310 ).AndReturn(self.DEPS_CONTENT) |
299 auto_roll.subprocess2.check_call( | 311 auto_roll.subprocess2.check_call( |
300 ['git', '--git-dir', './third_party/test_project/.git', 'fetch']) | 312 ['git', '--git-dir', './third_party/test_project/.git', 'fetch']) |
301 if self._arb._git_mode: | 313 if self._arb._git_mode: |
302 auto_roll.subprocess2.check_output( | 314 auto_roll.subprocess2.check_output( |
303 ['git', '--git-dir', './third_party/test_project/.git', 'rev-parse', | 315 ['git', '--git-dir', './third_party/test_project/.git', 'rev-parse', |
304 'origin/master']).AndReturn(self.OLDER_REV) | 316 'origin/master']).AndReturn(self.OLDER_REV) |
305 else: | 317 auto_roll.subprocess2.check_output( |
306 auto_roll.subprocess2.check_output( | 318 ['git', '--git-dir', './third_party/test_project/.git', 'show', '-s', |
307 ['git', '--git-dir', './third_party/test_project/.git', 'show', '-s', | 319 'origin/master']).AndReturn(self.GIT_LOG_TOO_OLD) |
308 'origin/master']).AndReturn(self.GIT_LOG_TOO_OLD) | |
309 self._compare_revs(self.OLD_REV, self.OLDER_REV) | 320 self._compare_revs(self.OLD_REV, self.OLDER_REV) |
310 | 321 |
311 self.mox.ReplayAll() | 322 self.mox.ReplayAll() |
312 try: | 323 try: |
313 self._arb.main() | 324 self._arb.main() |
314 except auto_roll.AutoRollException, e: | 325 except auto_roll.AutoRollException, e: |
315 self.assertEquals(e.args[0], ('Already at %s refusing to roll backwards ' | 326 self.assertEquals(e.args[0], ('Already at %s refusing to roll backwards ' |
316 'to %s.') % (self.OLD_REV, self.OLDER_REV)) | 327 'to %s.') % (self.OLD_REV, self.OLDER_REV)) |
317 | 328 |
318 def test_upload_issue(self): | 329 def test_upload_issue(self): |
(...skipping 18 matching lines...) Expand all Loading... |
337 return | 348 return |
338 self._get_current_revision() | 349 self._get_current_revision() |
339 self.mox.ReplayAll() | 350 self.mox.ReplayAll() |
340 self.assertEquals(type(self._arb._current_revision()), str) | 351 self.assertEquals(type(self._arb._current_revision()), str) |
341 | 352 |
342 def test_extra_trybots(self): | 353 def test_extra_trybots(self): |
343 if self.__class__.__name__ == 'AutoRollTestBase': | 354 if self.__class__.__name__ == 'AutoRollTestBase': |
344 return | 355 return |
345 self._arb._cq_extra_trybots = ['sometrybot'] | 356 self._arb._cq_extra_trybots = ['sometrybot'] |
346 self._arb._rietveld.search(owner=self.TEST_AUTHOR, closed=2).AndReturn([]) | 357 self._arb._rietveld.search(owner=self.TEST_AUTHOR, closed=2).AndReturn([]) |
347 commit_msg = ('Test_Project roll %s:%s\n\nCQ_EXTRA_TRYBOTS=sometrybot' % | 358 commit_msg = ('Test_Project roll %s:%s' % |
348 (self._display_rev(self.OLD_REV), | 359 (self._display_rev(self.OLD_REV), |
349 self._display_rev(self.NEW_REV))) | 360 self._display_rev(self.NEW_REV))) |
| 361 if self._arb._git_mode: |
| 362 commit_msg += ' (svn %s:%s)' % (self.OLD_SVN_REV, self.NEW_SVN_REV) |
| 363 commit_msg += '\n\nCQ_EXTRA_TRYBOTS=sometrybot' |
350 self._upload_issue(custom_message=commit_msg) | 364 self._upload_issue(custom_message=commit_msg) |
351 self.mox.ReplayAll() | 365 self.mox.ReplayAll() |
352 self.assertEquals(self._arb.main(), 0) | 366 self.assertEquals(self._arb.main(), 0) |
353 | 367 |
354 | 368 |
355 class AutoRollTestSVN(AutoRollTestBase): | 369 class AutoRollTestSVN(AutoRollTestBase): |
356 | 370 |
357 OLDER_REV = 1231 | 371 OLDER_REV = 1231 |
358 OLD_REV = 1234 | 372 OLD_REV = 1234 |
359 NEW_REV = 1235 | 373 NEW_REV = 1235 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 def _parse_origin_master(self, returnval): | 410 def _parse_origin_master(self, returnval): |
397 # Not required for SVN. | 411 # Not required for SVN. |
398 pass | 412 pass |
399 | 413 |
400 | 414 |
401 class AutoRollTestGit(AutoRollTestBase): | 415 class AutoRollTestGit(AutoRollTestBase): |
402 | 416 |
403 OLDER_REV = 'cfcf604fbdcf6e2d9b982a2fab3fc9f1e3f8cd65' | 417 OLDER_REV = 'cfcf604fbdcf6e2d9b982a2fab3fc9f1e3f8cd65' |
404 OLD_REV = 'b9af6489f6f2004ad11b82c6057f7007e3c35372' | 418 OLD_REV = 'b9af6489f6f2004ad11b82c6057f7007e3c35372' |
405 NEW_REV = '79539998e04afab3ee9c3016881755ca52f60a73' | 419 NEW_REV = '79539998e04afab3ee9c3016881755ca52f60a73' |
| 420 OLDER_SVN_REV = 1231 |
| 421 OLD_SVN_REV = 1234 |
| 422 NEW_SVN_REV = 1235 |
406 | 423 |
407 DEPS_CONTENT = ''' | 424 DEPS_CONTENT = ''' |
408 vars = { | 425 vars = { |
409 'test_project_revision': '%s', # Some comment. | 426 'test_project_revision': '%s', # from svn revision %s |
410 } | 427 } |
411 ''' % OLD_REV | 428 ''' % (OLD_REV, OLD_SVN_REV) |
412 | 429 |
413 _GIT_LOG = ''' | 430 _GIT_LOG = ''' |
414 commit %s | 431 commit %s |
415 Author: Test Author <test_author@example.com> | 432 Author: Test Author <test_author@example.com> |
416 Date: Wed Apr 2 14:00:14 2014 -0400 | 433 Date: Wed Apr 2 14:00:14 2014 -0400 |
417 | 434 |
418 Make some changes. | 435 Make some changes. |
| 436 |
| 437 git-svn-id: svn://svn.url/trunk@%d abcdefgh-abcd-abcd-abcd-abcdefghijkl |
419 ''' | 438 ''' |
420 GIT_LOG_UPDATED = _GIT_LOG % NEW_REV | 439 GIT_LOG_UPDATED = _GIT_LOG % (NEW_REV, NEW_SVN_REV) |
421 GIT_LOG_TOO_OLD = _GIT_LOG % OLDER_REV | 440 GIT_LOG_TOO_OLD = _GIT_LOG % (OLDER_REV, OLDER_SVN_REV) |
422 | 441 |
423 _commit_timestamps = { | 442 _commit_timestamps = { |
424 OLDER_REV: '1399573100', | 443 OLDER_REV: '1399573100', |
425 OLD_REV: '1399573342', | 444 OLD_REV: '1399573342', |
426 NEW_REV: '1399598876', | 445 NEW_REV: '1399598876', |
427 } | 446 } |
428 | 447 |
429 def setUp(self): | 448 def setUp(self): |
430 AutoRollTestBase.setUp(self) | 449 AutoRollTestBase.setUp(self) |
431 self._arb._git_mode = True | 450 self._arb._git_mode = True |
(...skipping 29 matching lines...) Expand all Loading... |
461 | 480 |
462 # pylint: disable=R0201 | 481 # pylint: disable=R0201 |
463 def _parse_origin_master(self, returnval): | 482 def _parse_origin_master(self, returnval): |
464 auto_roll.subprocess2.check_output( | 483 auto_roll.subprocess2.check_output( |
465 ['git', '--git-dir', './third_party/test_project/.git', 'rev-parse', | 484 ['git', '--git-dir', './third_party/test_project/.git', 'rev-parse', |
466 'origin/master']).AndReturn(returnval) | 485 'origin/master']).AndReturn(returnval) |
467 | 486 |
468 | 487 |
469 if __name__ == '__main__': | 488 if __name__ == '__main__': |
470 unittest.main() | 489 unittest.main() |
OLD | NEW |