| 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 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 'test3 test2', # test2 -> test3 | 777 'test3 test2', # test2 -> test3 |
| 778 'test3.1 test2', # test2 -> test3.1 | 778 'test3.1 test2', # test2 -> test3.1 |
| 779 'test4 test3', # test3 -> test4 | 779 'test4 test3', # test3 -> test4 |
| 780 'test5 test4', # test4 -> test5 | 780 'test5 test4', # test4 -> test5 |
| 781 'test6 test0', # test0 -> test6 | 781 'test6 test0', # test0 -> test6 |
| 782 'test7', # test7 | 782 'test7', # test7 |
| 783 ] | 783 ] |
| 784 return '\n'.join(branch_deps) | 784 return '\n'.join(branch_deps) |
| 785 self.mock(git_cl, 'RunGit', mock_run_git) | 785 self.mock(git_cl, 'RunGit', mock_run_git) |
| 786 | 786 |
| 787 git_cl.settings = git_cl.Settings() | |
| 788 self.mock(git_cl.settings, 'GetIsGerrit', lambda: False) | |
| 789 | |
| 790 class RecordCalls: | 787 class RecordCalls: |
| 791 times_called = 0 | 788 times_called = 0 |
| 792 record_calls = RecordCalls() | 789 record_calls = RecordCalls() |
| 793 def mock_CMDupload(*args, **_kwargs): | 790 def mock_CMDupload(*args, **_kwargs): |
| 794 record_calls.times_called += 1 | 791 record_calls.times_called += 1 |
| 795 return 0 | 792 return 0 |
| 796 self.mock(git_cl, 'CMDupload', mock_CMDupload) | 793 self.mock(git_cl, 'CMDupload', mock_CMDupload) |
| 797 | 794 |
| 798 self.calls = [ | 795 self.calls = [ |
| 799 (('[Press enter to continue or ctrl-C to quit]',), ''), | 796 (('[Press enter to continue or ctrl-C to quit]',), ''), |
| 800 ] | 797 ] |
| 801 | 798 |
| 802 class MockChangelist(): | 799 class MockChangelist(): |
| 803 def __init__(self): | 800 def __init__(self): |
| 804 pass | 801 pass |
| 805 def GetBranch(self): | 802 def GetBranch(self): |
| 806 return 'test1' | 803 return 'test1' |
| 807 def GetIssue(self): | 804 def GetIssue(self): |
| 808 return '123' | 805 return '123' |
| 809 def GetPatchset(self): | 806 def GetPatchset(self): |
| 810 return '1001' | 807 return '1001' |
| 808 def IsGerrit(self): |
| 809 return False |
| 811 | 810 |
| 812 ret = git_cl.upload_branch_deps(MockChangelist(), []) | 811 ret = git_cl.upload_branch_deps(MockChangelist(), []) |
| 813 # CMDupload should have been called 5 times because of 5 dependent branches. | 812 # CMDupload should have been called 5 times because of 5 dependent branches. |
| 814 self.assertEquals(5, record_calls.times_called) | 813 self.assertEquals(5, record_calls.times_called) |
| 815 self.assertEquals(0, ret) | 814 self.assertEquals(0, ret) |
| 816 | 815 |
| 817 def test_gerrit_change_id(self): | 816 def test_gerrit_change_id(self): |
| 818 self.calls = [ | 817 self.calls = [ |
| 819 ((['git', 'write-tree'], ), | 818 ((['git', 'write-tree'], ), |
| 820 'hashtree'), | 819 'hashtree'), |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 self.calls += [ | 959 self.calls += [ |
| 961 ((['git', 'apply', '--index', '-p0', '--3way'],), '', | 960 ((['git', 'apply', '--index', '-p0', '--3way'],), '', |
| 962 subprocess2.CalledProcessError(1, '', '', '', '')), | 961 subprocess2.CalledProcessError(1, '', '', '', '')), |
| 963 ] | 962 ] |
| 964 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 963 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
| 965 | 964 |
| 966 if __name__ == '__main__': | 965 if __name__ == '__main__': |
| 967 git_cl.logging.basicConfig( | 966 git_cl.logging.basicConfig( |
| 968 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 967 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
| 969 unittest.main() | 968 unittest.main() |
| OLD | NEW |