Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: tests/git_cl_test.py

Issue 1091283004: Don't clean up after conflict in "git cl patch" (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: address sbc's comments and fix long lines Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « git_cl.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 def tearDown(self): 103 def tearDown(self):
104 if not self.has_failed(): 104 if not self.has_failed():
105 self.assertEquals([], self.calls) 105 self.assertEquals([], self.calls)
106 super(TestGitCl, self).tearDown() 106 super(TestGitCl, self).tearDown()
107 107
108 def _mocked_call(self, *args, **_kwargs): 108 def _mocked_call(self, *args, **_kwargs):
109 self.assertTrue( 109 self.assertTrue(
110 self.calls, 110 self.calls,
111 '@%d Expected: <Missing> Actual: %r' % (self._calls_done, args)) 111 '@%d Expected: <Missing> Actual: %r' % (self._calls_done, args))
112 expected_args, result = self.calls.pop(0) 112 top = self.calls.pop(0)
113 if len(top) > 2 and top[2]:
114 raise top[2]
115 expected_args, result = top
116
113 # Also logs otherwise it could get caught in a try/finally and be hard to 117 # Also logs otherwise it could get caught in a try/finally and be hard to
114 # diagnose. 118 # diagnose.
115 if expected_args != args: 119 if expected_args != args:
116 msg = '@%d Expected: %r Actual: %r' % ( 120 msg = '@%d Expected: %r Actual: %r' % (
117 self._calls_done, expected_args, args) 121 self._calls_done, expected_args, args)
118 git_cl.logging.error(msg) 122 git_cl.logging.error(msg)
119 self.fail(msg) 123 self.fail(msg)
120 self._calls_done += 1 124 self._calls_done += 1
121 return result 125 return result
122 126
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 self.assertEqual('refs/heads/master', 850 self.assertEqual('refs/heads/master',
847 git_cl.GetTargetRef('origin', 851 git_cl.GetTargetRef('origin',
848 'refs/remotes/branch-heads/123', 852 'refs/remotes/branch-heads/123',
849 branch, None)) 853 branch, None))
850 854
851 # Check target refs for pending prefix. 855 # Check target refs for pending prefix.
852 self.assertEqual('prefix/heads/master', 856 self.assertEqual('prefix/heads/master',
853 git_cl.GetTargetRef('origin', 'refs/remotes/origin/master', 857 git_cl.GetTargetRef('origin', 'refs/remotes/origin/master',
854 None, 'prefix/')) 858 None, 'prefix/'))
855 859
860 def test_patch_when_dirty(self):
861 # Patch when local tree is dirty
862 self.mock(git_common, 'is_dirty_git_tree', lambda x: True)
863 self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
864
865 def test_diff_when_dirty(self):
866 # Do 'git cl diff' when local tree is dirty
867 self.mock(git_common, 'is_dirty_git_tree', lambda x: True)
868 self.assertNotEqual(git_cl.main(['diff']), 0)
869
870 def _patch_common(self):
871 self.mock(git_cl.Changelist, 'GetMostRecentPatchset', lambda x: '60001')
872 self.mock(git_cl.Changelist, 'GetPatchSetDiff', lambda *args: None)
873 self.mock(git_cl.Changelist, 'SetIssue', lambda *args: None)
874 self.mock(git_cl.Changelist, 'SetPatchset', lambda *args: None)
875 self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True)
876
877 self.calls = [
878 ((['git', 'config', 'rietveld.autoupdate'],), ''),
879 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'),
880 ((['git', 'rev-parse', '--show-cdup'],), ''),
881 ((['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'],), ''),
882 ]
883
884 def test_patch_successful(self):
885 self._patch_common()
886 self.calls += [
887 ((['git', 'apply', '--index', '-p0', '--3way'],), ''),
888 ((['git', 'commit', '-m',
889 'patch from issue 123456 at patchset 60001 ' +
890 '(http://crrev.com/123456#ps60001)'],), ''),
891 ]
892 self.assertEqual(git_cl.main(['patch', '123456']), 0)
893
894 def test_patch_conflict(self):
895 self._patch_common()
896 self.calls += [
897 ((['git', 'apply', '--index', '-p0', '--3way'],), '',
898 subprocess2.CalledProcessError(1, '', '', '', '')),
899 ]
900 self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
856 901
857 if __name__ == '__main__': 902 if __name__ == '__main__':
858 git_cl.logging.basicConfig( 903 git_cl.logging.basicConfig(
859 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 904 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
860 unittest.main() 905 unittest.main()
OLDNEW
« no previous file with comments | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698