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