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 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 864 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
865 | 865 |
866 def test_diff_when_dirty(self): | 866 def test_diff_when_dirty(self): |
867 # Do 'git cl diff' when local tree is dirty | 867 # Do 'git cl diff' when local tree is dirty |
868 self.mock(git_common, 'is_dirty_git_tree', lambda x: True) | 868 self.mock(git_common, 'is_dirty_git_tree', lambda x: True) |
869 self.assertNotEqual(git_cl.main(['diff']), 0) | 869 self.assertNotEqual(git_cl.main(['diff']), 0) |
870 | 870 |
871 def _patch_common(self): | 871 def _patch_common(self): |
872 self.mock(git_cl.Changelist, 'GetMostRecentPatchset', lambda x: '60001') | 872 self.mock(git_cl.Changelist, 'GetMostRecentPatchset', lambda x: '60001') |
873 self.mock(git_cl.Changelist, 'GetPatchSetDiff', lambda *args: None) | 873 self.mock(git_cl.Changelist, 'GetPatchSetDiff', lambda *args: None) |
| 874 self.mock(git_cl.Changelist, 'GetDescription', lambda *args: 'Description') |
874 self.mock(git_cl.Changelist, 'SetIssue', lambda *args: None) | 875 self.mock(git_cl.Changelist, 'SetIssue', lambda *args: None) |
875 self.mock(git_cl.Changelist, 'SetPatchset', lambda *args: None) | 876 self.mock(git_cl.Changelist, 'SetPatchset', lambda *args: None) |
876 self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True) | 877 self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True) |
877 | 878 |
878 self.calls = [ | 879 self.calls = [ |
879 ((['git', 'config', 'rietveld.autoupdate'],), ''), | 880 ((['git', 'config', 'rietveld.autoupdate'],), ''), |
880 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), | 881 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), |
881 ((['git', 'rev-parse', '--show-cdup'],), ''), | 882 ((['git', 'rev-parse', '--show-cdup'],), ''), |
882 ((['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'],), ''), | 883 ((['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'],), ''), |
883 ] | 884 ] |
884 | 885 |
885 def test_patch_successful(self): | 886 def test_patch_successful(self): |
886 self._patch_common() | 887 self._patch_common() |
887 self.calls += [ | 888 self.calls += [ |
888 ((['git', 'apply', '--index', '-p0', '--3way'],), ''), | 889 ((['git', 'apply', '--index', '-p0', '--3way'],), ''), |
889 ((['git', 'commit', '-m', | 890 ((['git', 'commit', '-m', |
| 891 'Description\n\n' + |
890 'patch from issue 123456 at patchset 60001 ' + | 892 'patch from issue 123456 at patchset 60001 ' + |
891 '(http://crrev.com/123456#ps60001)'],), ''), | 893 '(http://crrev.com/123456#ps60001)'],), ''), |
892 ] | 894 ] |
893 self.assertEqual(git_cl.main(['patch', '123456']), 0) | 895 self.assertEqual(git_cl.main(['patch', '123456']), 0) |
894 | 896 |
895 def test_patch_conflict(self): | 897 def test_patch_conflict(self): |
896 self._patch_common() | 898 self._patch_common() |
897 self.calls += [ | 899 self.calls += [ |
898 ((['git', 'apply', '--index', '-p0', '--3way'],), '', | 900 ((['git', 'apply', '--index', '-p0', '--3way'],), '', |
899 subprocess2.CalledProcessError(1, '', '', '', '')), | 901 subprocess2.CalledProcessError(1, '', '', '', '')), |
900 ] | 902 ] |
901 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 903 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
902 | 904 |
903 if __name__ == '__main__': | 905 if __name__ == '__main__': |
904 git_cl.logging.basicConfig( | 906 git_cl.logging.basicConfig( |
905 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 907 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
906 unittest.main() | 908 unittest.main() |
OLD | NEW |