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

Side by Side Diff: tests/git_cl_test.py

Issue 2038673002: git cl description: avoid appending BUG= after Change-Id. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@bug-footer-fix
Patch Set: 80chars Created 4 years, 6 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
« 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 StringIO 9 import StringIO
10 import stat 10 import stat
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 ((['git', 'var', 'GIT_AUTHOR_IDENT'], ), 1015 ((['git', 'var', 'GIT_AUTHOR_IDENT'], ),
1016 'A B <a@b.org> 1456848326 +0100'), 1016 'A B <a@b.org> 1456848326 +0100'),
1017 ((['git', 'var', 'GIT_COMMITTER_IDENT'], ), 1017 ((['git', 'var', 'GIT_COMMITTER_IDENT'], ),
1018 'C D <c@d.org> 1456858326 +0100'), 1018 'C D <c@d.org> 1456858326 +0100'),
1019 ((['git', 'hash-object', '-t', 'commit', '--stdin'], ), 1019 ((['git', 'hash-object', '-t', 'commit', '--stdin'], ),
1020 'hashchange'), 1020 'hashchange'),
1021 ] 1021 ]
1022 change_id = git_cl.GenerateGerritChangeId('line1\nline2\n') 1022 change_id = git_cl.GenerateGerritChangeId('line1\nline2\n')
1023 self.assertEqual(change_id, 'Ihashchange') 1023 self.assertEqual(change_id, 'Ihashchange')
1024 1024
1025 def test_desecription_append_footer(self):
1026 for init_desc, footer_line, expected_desc in [
1027 # Use unique desc first lines for easy test failure identification.
1028 ('foo', 'R=one', 'foo\n\nR=one'),
1029 ('foo\n\nR=one', 'BUG=', 'foo\n\nR=one\nBUG='),
1030 ('foo\n\nR=one', 'Change-Id: Ixx', 'foo\n\nR=one\n\nChange-Id: Ixx'),
1031 ('foo\n\nChange-Id: Ixx', 'R=one', 'foo\n\nR=one\n\nChange-Id: Ixx'),
Sergiy Byelozyorov 2016/06/02 22:59:53 Also test adding a new footer to an existing one (
tandrii(chromium) 2016/06/03 09:34:59 Done.
1032 ]:
1033 desc = git_cl.ChangeDescription(init_desc)
1034 desc.append_footer(footer_line)
1035 self.assertEqual(desc.description, expected_desc)
1036
1025 def test_update_reviewers(self): 1037 def test_update_reviewers(self):
1026 data = [ 1038 data = [
1027 ('foo', [], 'foo'), 1039 ('foo', [], 'foo'),
1028 ('foo\nR=xx', [], 'foo\nR=xx'), 1040 ('foo\nR=xx', [], 'foo\nR=xx'),
1029 ('foo\nTBR=xx', [], 'foo\nTBR=xx'), 1041 ('foo\nTBR=xx', [], 'foo\nTBR=xx'),
1030 ('foo', ['a@c'], 'foo\n\nR=a@c'), 1042 ('foo', ['a@c'], 'foo\n\nR=a@c'),
1031 ('foo\nR=xx', ['a@c'], 'foo\n\nR=a@c, xx'), 1043 ('foo\nR=xx', ['a@c'], 'foo\n\nR=a@c, xx'),
1032 ('foo\nTBR=xx', ['a@c'], 'foo\n\nR=a@c\nTBR=xx'), 1044 ('foo\nTBR=xx', ['a@c'], 'foo\n\nR=a@c\nTBR=xx'),
1033 ('foo\nTBR=xx\nR=yy', ['a@c'], 'foo\n\nR=a@c, yy\nTBR=xx'), 1045 ('foo\nTBR=xx\nR=yy', ['a@c'], 'foo\n\nR=a@c, yy\nTBR=xx'),
1034 ('foo\nBUG=', ['a@c'], 'foo\nBUG=\nR=a@c'), 1046 ('foo\nBUG=', ['a@c'], 'foo\nBUG=\nR=a@c'),
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 out = StringIO.StringIO() 1449 out = StringIO.StringIO()
1438 self.mock(git_cl.sys, 'stdout', out) 1450 self.mock(git_cl.sys, 'stdout', out)
1439 1451
1440 self.mock(git_cl, 'Changelist', ChangelistMock) 1452 self.mock(git_cl, 'Changelist', ChangelistMock)
1441 self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hihi')) 1453 self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hihi'))
1442 1454
1443 self.assertEqual(0, git_cl.main(['description', '-n', 'hihi'])) 1455 self.assertEqual(0, git_cl.main(['description', '-n', 'hihi']))
1444 self.assertEqual('hihi', ChangelistMock.desc) 1456 self.assertEqual('hihi', ChangelistMock.desc)
1445 1457
1446 def test_description_appends_bug_line(self): 1458 def test_description_appends_bug_line(self):
1447 current_desc = 'Some\n\nChange-Id: xxx' 1459 current_desc = 'Some.\n\nChange-Id: xxx'
1448 1460
1449 def RunEditor(desc, _, **kwargs): 1461 def RunEditor(desc, _, **kwargs):
1450 self.assertEquals( 1462 self.assertEquals(
1451 '# Enter a description of the change.\n' 1463 '# Enter a description of the change.\n'
1452 '# This will be displayed on the codereview site.\n' 1464 '# This will be displayed on the codereview site.\n'
1453 '# The first line will also be used as the subject of the review.\n' 1465 '# The first line will also be used as the subject of the review.\n'
1454 '#--------------------This line is 72 characters long' 1466 '#--------------------This line is 72 characters long'
1455 '--------------------\n' + 1467 '--------------------\n'
1456 # TODO(tandrii): fix this http://crbug.com/614587. 1468 'Some.\n\nBUG=\n\nChange-Id: xxx',
1457 current_desc + '\n\nBUG=',
1458 desc) 1469 desc)
1459 return current_desc + '\n\nBUG=' 1470 # Simulate user changing something.
1471 return 'Some.\n\nBUG=123\n\nChange-Id: xxx'
1460 1472
1461 def UpdateDescriptionRemote(_, desc): 1473 def UpdateDescriptionRemote(_, desc):
1462 # TODO(tandrii): fix this http://crbug.com/614587. 1474 self.assertEquals(desc, 'Some.\n\nBUG=123\n\nChange-Id: xxx')
1463 self.assertEquals(desc, current_desc + '\n\nBUG=')
1464 1475
1465 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 1476 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1466 self.mock(git_cl.Changelist, 'GetDescription', 1477 self.mock(git_cl.Changelist, 'GetDescription',
1467 lambda *args: current_desc) 1478 lambda *args: current_desc)
1468 self.mock(git_cl._GerritChangelistImpl, 'UpdateDescriptionRemote', 1479 self.mock(git_cl._GerritChangelistImpl, 'UpdateDescriptionRemote',
1469 UpdateDescriptionRemote) 1480 UpdateDescriptionRemote)
1470 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) 1481 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
1471 1482
1472 self.calls = [ 1483 self.calls = [
1473 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), 1484 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
(...skipping 30 matching lines...) Expand all
1504 ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],), 1515 ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],),
1505 ''), 1516 ''),
1506 ] 1517 ]
1507 self.assertEqual(0, git_cl.main(['issue', '0'])) 1518 self.assertEqual(0, git_cl.main(['issue', '0']))
1508 1519
1509 1520
1510 if __name__ == '__main__': 1521 if __name__ == '__main__':
1511 git_cl.logging.basicConfig( 1522 git_cl.logging.basicConfig(
1512 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 1523 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
1513 unittest.main() 1524 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