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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 ['reviewer@example.com', 'another@example.com']) | 689 ['reviewer@example.com', 'another@example.com']) |
690 | 690 |
691 def test_gerrit_upload_squash(self): | 691 def test_gerrit_upload_squash(self): |
692 self._run_gerrit_upload_test( | 692 self._run_gerrit_upload_test( |
693 ['--squash'], | 693 ['--squash'], |
694 'desc\n\nBUG=\nChange-Id:123456789\n', | 694 'desc\n\nBUG=\nChange-Id:123456789\n', |
695 [], | 695 [], |
696 squash=True, | 696 squash=True, |
697 expected_upstream_ref='origin/master') | 697 expected_upstream_ref='origin/master') |
698 | 698 |
| 699 def test_upload_branch_deps(self): |
| 700 def mock_run_git(*args, **_kwargs): |
| 701 if args[0] == ['for-each-ref', |
| 702 '--format=%(refname:short) %(upstream:short)', |
| 703 'refs/heads']: |
| 704 # Create a local branch dependency tree that looks like this: |
| 705 # test1 -> test2 -> test3 -> test4 -> test5 |
| 706 # -> test3.1 |
| 707 # test6 -> test0 |
| 708 branch_deps = [ |
| 709 'test2 test1', # test1 -> test2 |
| 710 'test3 test2', # test2 -> test3 |
| 711 'test3.1 test2', # test2 -> test3.1 |
| 712 'test4 test3', # test3 -> test4 |
| 713 'test5 test4', # test4 -> test5 |
| 714 'test6 test0', # test0 -> test6 |
| 715 'test7', # test7 |
| 716 ] |
| 717 return '\n'.join(branch_deps) |
| 718 self.mock(git_cl, 'RunGit', mock_run_git) |
| 719 |
| 720 class RecordCalls: |
| 721 times_called = 0 |
| 722 record_calls = RecordCalls() |
| 723 def mock_CMDupload(*args, **_kwargs): |
| 724 record_calls.times_called += 1 |
| 725 return 0 |
| 726 self.mock(git_cl, 'CMDupload', mock_CMDupload) |
| 727 |
| 728 self.calls = [ |
| 729 (('[Press enter to continue or ctrl-C to quit]',), ''), |
| 730 ] |
| 731 |
| 732 class MockChangelist(): |
| 733 def __init__(self): |
| 734 pass |
| 735 def GetBranch(self): |
| 736 return 'test1' |
| 737 def GetIssue(self): |
| 738 return '123' |
| 739 def GetPatchset(self): |
| 740 return '1001' |
| 741 |
| 742 ret = git_cl.upload_branch_deps(MockChangelist(), []) |
| 743 # CMDupload should have been called 5 times because of 5 dependent branches. |
| 744 self.assertEquals(5, record_calls.times_called) |
| 745 self.assertEquals(0, ret) |
| 746 |
699 def test_config_gerrit_download_hook(self): | 747 def test_config_gerrit_download_hook(self): |
700 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) | 748 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) |
701 def ParseCodereviewSettingsContent(content): | 749 def ParseCodereviewSettingsContent(content): |
702 keyvals = {} | 750 keyvals = {} |
703 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' | 751 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' |
704 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' | 752 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' |
705 keyvals['GERRIT_PORT'] = '29418' | 753 keyvals['GERRIT_PORT'] = '29418' |
706 return keyvals | 754 return keyvals |
707 self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', | 755 self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', |
708 ParseCodereviewSettingsContent) | 756 ParseCodereviewSettingsContent) |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 self.calls += [ | 955 self.calls += [ |
908 ((['git', 'apply', '--index', '-p0', '--3way'],), '', | 956 ((['git', 'apply', '--index', '-p0', '--3way'],), '', |
909 subprocess2.CalledProcessError(1, '', '', '', '')), | 957 subprocess2.CalledProcessError(1, '', '', '', '')), |
910 ] | 958 ] |
911 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 959 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
912 | 960 |
913 if __name__ == '__main__': | 961 if __name__ == '__main__': |
914 git_cl.logging.basicConfig( | 962 git_cl.logging.basicConfig( |
915 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 963 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
916 unittest.main() | 964 unittest.main() |
OLD | NEW |