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

Side by Side Diff: tests/git_cl_test.py

Issue 11236013: Add gerrit Change-Id to commit messages if they do not have one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Test for the new functionality is also in Created 8 years, 2 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 | Annotate | Revision Log
« git_cl.py ('K') | « 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 re
9 import StringIO 10 import StringIO
10 import stat 11 import stat
11 import sys 12 import sys
12 import unittest 13 import unittest
13 14
14 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 15 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
15 16
16 from testing_support.auto_stub import TestCase 17 from testing_support.auto_stub import TestCase
17 18
18 import git_cl 19 import git_cl
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 ((['git', 'config', 'user.email'],), 'me@example.com'), 387 ((['git', 'config', 'user.email'],), 'me@example.com'),
387 ((['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', 388 ((['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
388 '-C50', '-l100000', 'master...'],), 389 '-C50', '-l100000', 'master...'],),
389 '+dat'), 390 '+dat'),
390 ] 391 ]
391 392
392 @staticmethod 393 @staticmethod
393 def _gerrit_upload_calls(description, reviewers): 394 def _gerrit_upload_calls(description, reviewers):
394 calls = [ 395 calls = [
395 ((['git', 'log', '--pretty=format:%s\n\n%b', 'master..'],), 396 ((['git', 'log', '--pretty=format:%s\n\n%b', 'master..'],),
396 description), 397 description)
398 ]
399 if not re.search(git_cl.CHANGE_ID_STR, description):
400 calls += [
401 ((['git', 'commit', '-a', '--amend', '-m %s' % description],),
402 '')
403 ]
404 calls += [
397 ((['git', 'config', 'rietveld.cc'],), '') 405 ((['git', 'config', 'rietveld.cc'],), '')
398 ] 406 ]
399 receive_pack = '--receive-pack=git receive-pack ' 407 receive_pack = '--receive-pack=git receive-pack '
400 receive_pack += '--cc=joe@example.com' # from watch list 408 receive_pack += '--cc=joe@example.com' # from watch list
401 if reviewers: 409 if reviewers:
402 receive_pack += ' ' 410 receive_pack += ' '
403 receive_pack += ' '.join(['--reviewer=' + email for email in reviewers]) 411 receive_pack += ' '.join(['--reviewer=' + email for email in reviewers])
404 receive_pack += '' 412 receive_pack += ''
405 calls += [ 413 calls += [
406 ((['git', 'push', receive_pack, 'origin', 'HEAD:refs/for/master'],), 414 ((['git', 'push', receive_pack, 'origin', 'HEAD:refs/for/master'],),
407 '') 415 '')
408 ] 416 ]
409 return calls 417 return calls
410 418
411 def _run_gerrit_reviewer_test( 419 def _run_gerrit_upload_test(
412 self, 420 self,
413 upload_args, 421 upload_args,
414 description, 422 description,
415 reviewers): 423 reviewers):
416 """Generic gerrit reviewer test framework.""" 424 """Generic gerrit upload test framework."""
417 self.calls = self._gerrit_base_calls() 425 self.calls = self._gerrit_base_calls()
418 self.calls += self._gerrit_upload_calls(description, reviewers) 426 self.calls += self._gerrit_upload_calls(description, reviewers)
419 git_cl.main(['upload'] + upload_args) 427 git_cl.main(['upload'] + upload_args)
420 428
421 def test_gerrit_no_reviewer(self): 429 def test_gerrit_upload_without_change_id(self):
422 self._run_gerrit_reviewer_test( 430 self._run_gerrit_upload_test(
423 [], 431 [],
424 'desc\n\nBUG=\n', 432 'desc\n\nBUG=\n',
425 []) 433 [])
426 434
435 def test_gerrit_no_reviewer(self):
436 self._run_gerrit_upload_test(
437 [],
438 'desc\n\nBUG=\nChange-Id:123456789\n',
439 [])
440
427 def test_gerrit_reviewers_cmd_line(self): 441 def test_gerrit_reviewers_cmd_line(self):
428 self._run_gerrit_reviewer_test( 442 self._run_gerrit_upload_test(
429 ['-r', 'foo@example.com'], 443 ['-r', 'foo@example.com'],
430 'desc\n\nBUG=\n', 444 'desc\n\nBUG=\nChange-Id:123456789',
431 ['foo@example.com']) 445 ['foo@example.com'])
432 446
433 def test_gerrit_reviewer_multiple(self): 447 def test_gerrit_reviewer_multiple(self):
434 self._run_gerrit_reviewer_test( 448 self._run_gerrit_upload_test(
435 [], 449 [],
436 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n', 450 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n'
451 'Change-Id:123456789\n',
437 ['reviewer@example.com', 'another@example.com']) 452 ['reviewer@example.com', 'another@example.com'])
438 453
439 454
440 def test_config_gerrit_download_hook(self): 455 def test_config_gerrit_download_hook(self):
441 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) 456 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock)
442 def ParseCodereviewSettingsContent(content): 457 def ParseCodereviewSettingsContent(content):
443 keyvals = {} 458 keyvals = {}
444 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' 459 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org'
445 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' 460 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org'
446 keyvals['GERRIT_PORT'] = '29418' 461 keyvals['GERRIT_PORT'] = '29418'
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 ((['git', 'config', 'rietveld.viewvc-url'],), ''), 504 ((['git', 'config', 'rietveld.viewvc-url'],), ''),
490 (('ViewVC URL:',), ''), 505 (('ViewVC URL:',), ''),
491 # DownloadHooks(True) 506 # DownloadHooks(True)
492 ((commit_msg_path, os.X_OK,), True), 507 ((commit_msg_path, os.X_OK,), True),
493 ] 508 ]
494 git_cl.main(['config']) 509 git_cl.main(['config'])
495 510
496 511
497 if __name__ == '__main__': 512 if __name__ == '__main__':
498 unittest.main() 513 unittest.main()
OLDNEW
« git_cl.py ('K') | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698