| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Unit tests for git_cl.py.""" | 6 """Unit tests for git_cl.py.""" |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import StringIO | 9 import StringIO |
| 10 import stat | 10 import stat |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 139 |
| 140 if find_copies: | 140 if find_copies: |
| 141 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', | 141 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', |
| 142 '--find-copies-harder', '-l100000', '-C'+similarity, | 142 '--find-copies-harder', '-l100000', '-C'+similarity, |
| 143 'fake_ancestor_sha', 'HEAD'],), '+dat') | 143 'fake_ancestor_sha', 'HEAD'],), '+dat') |
| 144 else: | 144 else: |
| 145 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', | 145 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', |
| 146 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') | 146 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') |
| 147 | 147 |
| 148 return [ | 148 return [ |
| 149 ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 149 ((['git', 'config', 'rietveld.server'],), | 150 ((['git', 'config', 'rietveld.server'],), |
| 150 'codereview.example.com'), | 151 'codereview.example.com'), |
| 151 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 152 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 152 similarity_call, | 153 similarity_call, |
| 153 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 154 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 154 find_copies_call, | 155 find_copies_call, |
| 155 ((['git', 'update-index', '--refresh', '-q'],), ''), | 156 ((['git', 'update-index', '--refresh', '-q'],), ''), |
| 156 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), | 157 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), |
| 157 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 158 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 158 ((['git', 'config', 'branch.master.merge'],), 'master'), | 159 ((['git', 'config', 'branch.master.merge'],), 'master'), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 244 |
| 244 @classmethod | 245 @classmethod |
| 245 def _dcommit_calls_1(cls): | 246 def _dcommit_calls_1(cls): |
| 246 return [ | 247 return [ |
| 247 ((['git', | 248 ((['git', |
| 248 'config', '--local', '--get-regexp', '^svn-remote\\.'],), | 249 'config', '--local', '--get-regexp', '^svn-remote\\.'],), |
| 249 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' | 250 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' |
| 250 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), | 251 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), |
| 251 None), | 252 None), |
| 252 0)), | 253 0)), |
| 254 ((['git', 'config', 'rietveld.autoupdate'],), |
| 255 ''), |
| 253 ((['git', | 256 ((['git', |
| 254 'config', 'rietveld.server'],), 'codereview.example.com'), | 257 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 255 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 258 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 256 ((['git', 'config', '--int', '--get', | 259 ((['git', 'config', '--int', '--get', |
| 257 'branch.working.git-cl-similarity'],), ''), | 260 'branch.working.git-cl-similarity'],), ''), |
| 258 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 261 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 259 ((['git', 'config', '--int', '--get', | 262 ((['git', 'config', '--int', '--get', |
| 260 'branch.working.git-find-copies'],), ''), | 263 'branch.working.git-find-copies'],), ''), |
| 261 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 264 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 262 ((['git', | 265 ((['git', |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 if '--find-copies' in upload_args: | 378 if '--find-copies' in upload_args: |
| 376 find_copies = True | 379 find_copies = True |
| 377 elif '--no-find-copies' in upload_args: | 380 elif '--no-find-copies' in upload_args: |
| 378 find_copies = False | 381 find_copies = False |
| 379 else: | 382 else: |
| 380 find_copies = None | 383 find_copies = None |
| 381 | 384 |
| 382 private = '--private' in upload_args | 385 private = '--private' in upload_args |
| 383 | 386 |
| 384 self.calls = self._upload_calls(similarity, find_copies, private) | 387 self.calls = self._upload_calls(similarity, find_copies, private) |
| 388 |
| 385 def RunEditor(desc, _, **kwargs): | 389 def RunEditor(desc, _, **kwargs): |
| 386 self.assertEquals( | 390 self.assertEquals( |
| 387 '# Enter a description of the change.\n' | 391 '# Enter a description of the change.\n' |
| 388 '# This will be displayed on the codereview site.\n' | 392 '# This will be displayed on the codereview site.\n' |
| 389 '# The first line will also be used as the subject of the review.\n' | 393 '# The first line will also be used as the subject of the review.\n' |
| 390 '#--------------------This line is 72 characters long' | 394 '#--------------------This line is 72 characters long' |
| 391 '--------------------\n' + | 395 '--------------------\n' + |
| 392 expected_description, | 396 expected_description, |
| 393 desc) | 397 desc) |
| 394 return returned_description | 398 return returned_description |
| 395 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) | 399 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) |
| 400 |
| 396 def check_upload(args): | 401 def check_upload(args): |
| 397 cmd_line = self._cmd_line(final_description, reviewers, similarity, | 402 cmd_line = self._cmd_line(final_description, reviewers, similarity, |
| 398 find_copies, private) | 403 find_copies, private) |
| 399 self.assertEquals(cmd_line, args) | 404 self.assertEquals(cmd_line, args) |
| 400 return 1, 2 | 405 return 1, 2 |
| 401 self.mock(git_cl.upload, 'RealMain', check_upload) | 406 self.mock(git_cl.upload, 'RealMain', check_upload) |
| 407 |
| 402 git_cl.main(['upload'] + upload_args) | 408 git_cl.main(['upload'] + upload_args) |
| 403 | 409 |
| 404 def test_no_reviewer(self): | 410 def test_no_reviewer(self): |
| 405 self._run_reviewer_test( | 411 self._run_reviewer_test( |
| 406 [], | 412 [], |
| 407 'desc\n\nBUG=', | 413 'desc\n\nBUG=', |
| 408 '# Blah blah comment.\ndesc\n\nBUG=', | 414 '# Blah blah comment.\ndesc\n\nBUG=', |
| 409 'desc\n\nBUG=', | 415 'desc\n\nBUG=', |
| 410 []) | 416 []) |
| 411 | 417 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 self.calls = ( | 514 self.calls = ( |
| 509 self._dcommit_calls_1() + | 515 self._dcommit_calls_1() + |
| 510 self._dcommit_calls_bypassed() + | 516 self._dcommit_calls_bypassed() + |
| 511 self._dcommit_calls_3()) | 517 self._dcommit_calls_3()) |
| 512 git_cl.main(['dcommit', '--bypass-hooks']) | 518 git_cl.main(['dcommit', '--bypass-hooks']) |
| 513 | 519 |
| 514 | 520 |
| 515 @classmethod | 521 @classmethod |
| 516 def _gerrit_base_calls(cls): | 522 def _gerrit_base_calls(cls): |
| 517 return [ | 523 return [ |
| 524 ((['git', 'config', 'rietveld.autoupdate'],), |
| 525 ''), |
| 518 ((['git', | 526 ((['git', |
| 519 'config', 'rietveld.server'],), 'codereview.example.com'), | 527 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 520 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 528 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 521 ((['git', 'config', '--int', '--get', | 529 ((['git', 'config', '--int', '--get', |
| 522 'branch.master.git-cl-similarity'],), ''), | 530 'branch.master.git-cl-similarity'],), ''), |
| 523 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 531 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 524 ((['git', 'config', '--int', '--get', | 532 ((['git', 'config', '--int', '--get', |
| 525 'branch.master.git-find-copies'],), ''), | 533 'branch.master.git-find-copies'],), ''), |
| 526 ((['git', 'update-index', '--refresh', '-q'],), ''), | 534 ((['git', 'update-index', '--refresh', '-q'],), ''), |
| 527 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), | 535 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg') | 652 commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg') |
| 645 def Exists(path): | 653 def Exists(path): |
| 646 if path == commit_msg_path: | 654 if path == commit_msg_path: |
| 647 return False | 655 return False |
| 648 # others paths, such as /usr/share/locale/.... | 656 # others paths, such as /usr/share/locale/.... |
| 649 return True | 657 return True |
| 650 self.mock(git_cl.os.path, 'exists', Exists) | 658 self.mock(git_cl.os.path, 'exists', Exists) |
| 651 self.mock(git_cl, 'urlretrieve', self._mocked_call) | 659 self.mock(git_cl, 'urlretrieve', self._mocked_call) |
| 652 self.mock(git_cl, 'hasSheBang', self._mocked_call) | 660 self.mock(git_cl, 'hasSheBang', self._mocked_call) |
| 653 self.calls = [ | 661 self.calls = [ |
| 662 ((['git', 'config', 'rietveld.autoupdate'],), |
| 663 ''), |
| 654 ((['git', 'config', 'rietveld.server', | 664 ((['git', 'config', 'rietveld.server', |
| 655 'gerrit.chromium.org'],), ''), | 665 'gerrit.chromium.org'],), ''), |
| 656 ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''), | 666 ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''), |
| 657 ((['git', 'config', '--unset-all', | 667 ((['git', 'config', '--unset-all', |
| 658 'rietveld.private'],), ''), | 668 'rietveld.private'],), ''), |
| 659 ((['git', 'config', '--unset-all', | 669 ((['git', 'config', '--unset-all', |
| 660 'rietveld.tree-status-url'],), ''), | 670 'rietveld.tree-status-url'],), ''), |
| 661 ((['git', 'config', '--unset-all', | 671 ((['git', 'config', '--unset-all', |
| 662 'rietveld.viewvc-url'],), ''), | 672 'rietveld.viewvc-url'],), ''), |
| 663 ((['git', 'config', 'gerrit.host', | 673 ((['git', 'config', 'gerrit.host', |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 obj = git_cl.ChangeDescription(orig) | 727 obj = git_cl.ChangeDescription(orig) |
| 718 obj.update_reviewers(reviewers) | 728 obj.update_reviewers(reviewers) |
| 719 actual.append(obj.description) | 729 actual.append(obj.description) |
| 720 self.assertEqual(expected, actual) | 730 self.assertEqual(expected, actual) |
| 721 | 731 |
| 722 | 732 |
| 723 if __name__ == '__main__': | 733 if __name__ == '__main__': |
| 724 git_cl.logging.basicConfig( | 734 git_cl.logging.basicConfig( |
| 725 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 735 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
| 726 unittest.main() | 736 unittest.main() |
| OLD | NEW |