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

Side by Side Diff: tests/git_cl_test.py

Issue 14854003: Make git-cl more accurately imitate git's editor selection process, and respect $VISUAL. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Make tests use $GIT_EDITOR instead of $EDITOR (previously they failed for me, as $EDITOR was overriā€¦ Created 7 years, 7 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 | « tests/basic.sh ('k') | tests/owners.sh » ('j') | 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 self.fail(msg) 107 self.fail(msg)
108 self._calls_done += 1 108 self._calls_done += 1
109 return result 109 return result
110 110
111 @classmethod 111 @classmethod
112 def _upload_calls(cls, similarity, find_copies): 112 def _upload_calls(cls, similarity, find_copies):
113 return (cls._git_base_calls(similarity, find_copies) + 113 return (cls._git_base_calls(similarity, find_copies) +
114 cls._git_upload_calls()) 114 cls._git_upload_calls())
115 115
116 @classmethod 116 @classmethod
117 def _upload_no_rev_calls(cls, similarity, find_copies):
118 return (cls._git_base_calls(similarity, find_copies) +
119 cls._git_upload_no_rev_calls())
120
121 @classmethod
117 def _git_base_calls(cls, similarity, find_copies): 122 def _git_base_calls(cls, similarity, find_copies):
118 if similarity is None: 123 if similarity is None:
119 similarity = '50' 124 similarity = '50'
120 similarity_call = ((['git', '--no-pager', 'config', '--int', '--get', 125 similarity_call = ((['git', '--no-pager', 'config', '--int', '--get',
121 'branch.master.git-cl-similarity'],), '') 126 'branch.master.git-cl-similarity'],), '')
122 else: 127 else:
123 similarity_call = ((['git', '--no-pager', 'config', '--int', 128 similarity_call = ((['git', '--no-pager', 'config', '--int',
124 'branch.master.git-cl-similarity', similarity],), '') 129 'branch.master.git-cl-similarity', similarity],), '')
125 130
126 if find_copies is None: 131 if find_copies is None:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 'foo'), 173 'foo'),
169 ((['git', '--no-pager', 'config', 'user.email'],), 'me@example.com'), 174 ((['git', '--no-pager', 'config', 'user.email'],), 'me@example.com'),
170 stat_call, 175 stat_call,
171 ((['git', '--no-pager', 'config', 'gerrit.host'],), ''), 176 ((['git', '--no-pager', 'config', 'gerrit.host'],), ''),
172 ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b', 177 ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b',
173 'fake_ancestor_sha..HEAD'],), 178 'fake_ancestor_sha..HEAD'],),
174 'desc\n'), 179 'desc\n'),
175 ] 180 ]
176 181
177 @classmethod 182 @classmethod
183 def _git_upload_no_rev_calls(cls):
184 return [
185 ((['git', '--no-pager', 'config', 'core.editor'],), ''),
186 ]
187
188 @classmethod
178 def _git_upload_calls(cls): 189 def _git_upload_calls(cls):
179 return [ 190 return [
191 ((['git', '--no-pager', 'config', 'core.editor'],), ''),
180 ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''), 192 ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''),
181 ((['git', '--no-pager', 'config', 'branch.master.base-url'],), ''), 193 ((['git', '--no-pager', 'config', 'branch.master.base-url'],), ''),
182 ((['git', '--no-pager', 194 ((['git', '--no-pager',
183 'config', '--local', '--get-regexp', '^svn-remote\\.'],), 195 'config', '--local', '--get-regexp', '^svn-remote\\.'],),
184 (('', None), 0)), 196 (('', None), 0)),
185 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), 197 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
186 ((['git', '--no-pager', 'svn', 'info'],), ''), 198 ((['git', '--no-pager', 'svn', 'info'],), ''),
187 ((['git', '--no-pager', 199 ((['git', '--no-pager',
188 'config', 'branch.master.rietveldissue', '1'],), ''), 200 'config', 'branch.master.rietveldissue', '1'],), ''),
189 ((['git', '--no-pager', 'config', 'branch.master.rietveldserver', 201 ((['git', '--no-pager', 'config', 'branch.master.rietveldserver',
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 similarity = None 363 similarity = None
352 364
353 if '--find-copies' in upload_args: 365 if '--find-copies' in upload_args:
354 find_copies = True 366 find_copies = True
355 elif '--no-find-copies' in upload_args: 367 elif '--no-find-copies' in upload_args:
356 find_copies = False 368 find_copies = False
357 else: 369 else:
358 find_copies = None 370 find_copies = None
359 371
360 self.calls = self._upload_calls(similarity, find_copies) 372 self.calls = self._upload_calls(similarity, find_copies)
361 def RunEditor(desc, _): 373 def RunEditor(desc, _, **kwargs):
362 self.assertEquals( 374 self.assertEquals(
363 '# Enter a description of the change.\n' 375 '# Enter a description of the change.\n'
364 '# This will be displayed on the codereview site.\n' 376 '# This will be displayed on the codereview site.\n'
365 '# The first line will also be used as the subject of the review.\n' + 377 '# The first line will also be used as the subject of the review.\n' +
366 expected_description, 378 expected_description,
367 desc) 379 desc)
368 return returned_description 380 return returned_description
369 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) 381 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
370 def check_upload(args): 382 def check_upload(args):
371 cmd_line = self._cmd_line(final_description, reviewers, similarity, 383 cmd_line = self._cmd_line(final_description, reviewers, similarity,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 455
444 def test_reviewer_send_mail_no_rev(self): 456 def test_reviewer_send_mail_no_rev(self):
445 # Fails without a reviewer. 457 # Fails without a reviewer.
446 class FileMock(object): 458 class FileMock(object):
447 buf = StringIO.StringIO() 459 buf = StringIO.StringIO()
448 def write(self, content): 460 def write(self, content):
449 self.buf.write(content) 461 self.buf.write(content)
450 462
451 mock = FileMock() 463 mock = FileMock()
452 try: 464 try:
453 self.calls = self._git_base_calls(None, None) 465 self.calls = self._upload_no_rev_calls(None, None)
454 def RunEditor(desc, _): 466 def RunEditor(desc, _, **kwargs):
455 return desc 467 return desc
456 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) 468 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
457 self.mock(sys, 'stderr', mock) 469 self.mock(sys, 'stderr', mock)
458 git_cl.main(['upload', '--send-mail']) 470 git_cl.main(['upload', '--send-mail'])
459 self.fail() 471 self.fail()
460 except SystemExit: 472 except SystemExit:
461 self.assertEquals( 473 self.assertEquals(
462 'Must specify reviewers to send email.\n', mock.buf.getvalue()) 474 'Must specify reviewers to send email.\n', mock.buf.getvalue())
463 475
464 def test_dcommit(self): 476 def test_dcommit(self):
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 obj = git_cl.ChangeDescription(orig) 685 obj = git_cl.ChangeDescription(orig)
674 obj.update_reviewers(reviewers) 686 obj.update_reviewers(reviewers)
675 actual.append(obj.description) 687 actual.append(obj.description)
676 self.assertEqual(expected, actual) 688 self.assertEqual(expected, actual)
677 689
678 690
679 if __name__ == '__main__': 691 if __name__ == '__main__':
680 git_cl.logging.basicConfig( 692 git_cl.logging.basicConfig(
681 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 693 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
682 unittest.main() 694 unittest.main()
OLDNEW
« no previous file with comments | « tests/basic.sh ('k') | tests/owners.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698