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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 (('', None), 0)), | 220 (('', None), 0)), |
221 ((['git', 'rev-parse', '--show-cdup'],), ''), | 221 ((['git', 'rev-parse', '--show-cdup'],), ''), |
222 ((['git', 'svn', 'info'],), ''), | 222 ((['git', 'svn', 'info'],), ''), |
223 ((['git', 'config', 'rietveld.project'],), ''), | 223 ((['git', 'config', 'rietveld.project'],), ''), |
224 ((['git', | 224 ((['git', |
225 'config', 'branch.master.rietveldissue', '1'],), ''), | 225 'config', 'branch.master.rietveldissue', '1'],), ''), |
226 ((['git', 'config', 'branch.master.rietveldserver', | 226 ((['git', 'config', 'branch.master.rietveldserver', |
227 'https://codereview.example.com'],), ''), | 227 'https://codereview.example.com'],), ''), |
228 ((['git', | 228 ((['git', |
229 'config', 'branch.master.rietveldpatchset', '2'],), ''), | 229 'config', 'branch.master.rietveldpatchset', '2'],), ''), |
| 230 ] + cls._git_post_upload_calls() |
| 231 |
| 232 @classmethod |
| 233 def _git_post_upload_calls(cls): |
| 234 return [ |
230 ((['git', 'rev-parse', 'HEAD'],), 'hash'), | 235 ((['git', 'rev-parse', 'HEAD'],), 'hash'), |
231 ((['git', 'symbolic-ref', 'HEAD'],), 'hash'), | 236 ((['git', 'symbolic-ref', 'HEAD'],), 'hash'), |
232 ((['git', | 237 ((['git', |
233 'config', 'branch.hash.last-upload-hash', 'hash'],), ''), | 238 'config', 'branch.hash.last-upload-hash', 'hash'],), ''), |
234 ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''), | 239 ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''), |
235 ] | 240 ] |
236 | 241 |
237 @staticmethod | 242 @staticmethod |
238 def _git_sanity_checks(diff_base, working_branch): | 243 def _git_sanity_checks(diff_base, working_branch): |
239 fake_ancestor = 'fake_ancestor' | 244 fake_ancestor = 'fake_ancestor' |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 ((['git', | 572 ((['git', |
568 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), | 573 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), |
569 'foo'), | 574 'foo'), |
570 ((['git', 'config', 'user.email'],), 'me@example.com'), | 575 ((['git', 'config', 'user.email'],), 'me@example.com'), |
571 ((['git', | 576 ((['git', |
572 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 577 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
573 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), | 578 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), |
574 '+dat'), | 579 '+dat'), |
575 ] | 580 ] |
576 | 581 |
577 @staticmethod | 582 @classmethod |
578 def _gerrit_upload_calls(description, reviewers, squash, | 583 def _gerrit_upload_calls(cls, description, reviewers, squash, |
579 expected_upstream_ref='origin/refs/heads/master'): | 584 expected_upstream_ref='origin/refs/heads/master'): |
580 calls = [ | 585 calls = [ |
581 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), | 586 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), |
582 ((['git', 'log', '--pretty=format:%s\n\n%b', | 587 ((['git', 'log', '--pretty=format:%s\n\n%b', |
583 'fake_ancestor_sha..HEAD'],), | 588 'fake_ancestor_sha..HEAD'],), |
584 description) | 589 description) |
585 ] | 590 ] |
586 if git_cl.CHANGE_ID not in description: | 591 if git_cl.CHANGE_ID not in description: |
587 calls += [ | 592 calls += [ |
588 ((['git', 'log', '--pretty=format:%s\n\n%b', | 593 ((['git', 'log', '--pretty=format:%s\n\n%b', |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 ref_to_push + ':refs/for/refs/heads/master'],), | 638 ref_to_push + ':refs/for/refs/heads/master'],), |
634 '') | 639 '') |
635 ] | 640 ] |
636 if squash: | 641 if squash: |
637 calls += [ | 642 calls += [ |
638 ((['git', 'rev-parse', 'HEAD'],), 'abcdef0123456789'), | 643 ((['git', 'rev-parse', 'HEAD'],), 'abcdef0123456789'), |
639 ((['git', 'update-ref', '-m', 'Uploaded abcdef0123456789', | 644 ((['git', 'update-ref', '-m', 'Uploaded abcdef0123456789', |
640 'refs/heads/git_cl_uploads/master', 'abcdef0123456789'],), | 645 'refs/heads/git_cl_uploads/master', 'abcdef0123456789'],), |
641 '') | 646 '') |
642 ] | 647 ] |
643 | 648 calls += cls._git_post_upload_calls() |
644 return calls | 649 return calls |
645 | 650 |
646 def _run_gerrit_upload_test( | 651 def _run_gerrit_upload_test( |
647 self, | 652 self, |
648 upload_args, | 653 upload_args, |
649 description, | 654 description, |
650 reviewers, | 655 reviewers, |
651 squash=False, | 656 squash=False, |
652 expected_upstream_ref='origin/refs/heads/master'): | 657 expected_upstream_ref='origin/refs/heads/master'): |
653 """Generic gerrit upload test framework.""" | 658 """Generic gerrit upload test framework.""" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 self.calls += [ | 954 self.calls += [ |
950 ((['git', 'apply', '--index', '-p0', '--3way'],), '', | 955 ((['git', 'apply', '--index', '-p0', '--3way'],), '', |
951 subprocess2.CalledProcessError(1, '', '', '', '')), | 956 subprocess2.CalledProcessError(1, '', '', '', '')), |
952 ] | 957 ] |
953 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 958 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
954 | 959 |
955 if __name__ == '__main__': | 960 if __name__ == '__main__': |
956 git_cl.logging.basicConfig( | 961 git_cl.logging.basicConfig( |
957 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 962 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
958 unittest.main() | 963 unittest.main() |
OLD | NEW |