| 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 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 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'), | 
|  | 1032       ('foo\n\nR=one\n\nChange-Id: Ixx', 'TBR=two', | 
|  | 1033        'foo\n\nR=one\nTBR=two\n\nChange-Id: Ixx'), | 
|  | 1034       ('foo\n\nR=one\n\nChange-Id: Ixx', 'Foo-Bar: baz', | 
|  | 1035        'foo\n\nR=one\n\nChange-Id: Ixx\nFoo-Bar: baz'), | 
|  | 1036       ('foo\n\nChange-Id: Ixx', 'Foo-Bak: baz', | 
|  | 1037        'foo\n\nChange-Id: Ixx\nFoo-Bak: baz'), | 
|  | 1038       ('foo', 'Change-Id: Ixx', 'foo\n\nChange-Id: Ixx'), | 
|  | 1039     ]: | 
|  | 1040       desc = git_cl.ChangeDescription(init_desc) | 
|  | 1041       desc.append_footer(footer_line) | 
|  | 1042       self.assertEqual(desc.description, expected_desc) | 
|  | 1043 | 
| 1025   def test_update_reviewers(self): | 1044   def test_update_reviewers(self): | 
| 1026     data = [ | 1045     data = [ | 
| 1027       ('foo', [], 'foo'), | 1046       ('foo', [], 'foo'), | 
| 1028       ('foo\nR=xx', [], 'foo\nR=xx'), | 1047       ('foo\nR=xx', [], 'foo\nR=xx'), | 
| 1029       ('foo\nTBR=xx', [], 'foo\nTBR=xx'), | 1048       ('foo\nTBR=xx', [], 'foo\nTBR=xx'), | 
| 1030       ('foo', ['a@c'], 'foo\n\nR=a@c'), | 1049       ('foo', ['a@c'], 'foo\n\nR=a@c'), | 
| 1031       ('foo\nR=xx', ['a@c'], 'foo\n\nR=a@c, xx'), | 1050       ('foo\nR=xx', ['a@c'], 'foo\n\nR=a@c, xx'), | 
| 1032       ('foo\nTBR=xx', ['a@c'], 'foo\n\nR=a@c\nTBR=xx'), | 1051       ('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'), | 1052       ('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'), | 1053       ('foo\nBUG=', ['a@c'], 'foo\nBUG=\nR=a@c'), | 
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1437     out = StringIO.StringIO() | 1456     out = StringIO.StringIO() | 
| 1438     self.mock(git_cl.sys, 'stdout', out) | 1457     self.mock(git_cl.sys, 'stdout', out) | 
| 1439 | 1458 | 
| 1440     self.mock(git_cl, 'Changelist', ChangelistMock) | 1459     self.mock(git_cl, 'Changelist', ChangelistMock) | 
| 1441     self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hihi')) | 1460     self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hihi')) | 
| 1442 | 1461 | 
| 1443     self.assertEqual(0, git_cl.main(['description', '-n', 'hihi'])) | 1462     self.assertEqual(0, git_cl.main(['description', '-n', 'hihi'])) | 
| 1444     self.assertEqual('hihi', ChangelistMock.desc) | 1463     self.assertEqual('hihi', ChangelistMock.desc) | 
| 1445 | 1464 | 
| 1446   def test_description_appends_bug_line(self): | 1465   def test_description_appends_bug_line(self): | 
| 1447     current_desc = 'Some\n\nChange-Id: xxx' | 1466     current_desc = 'Some.\n\nChange-Id: xxx' | 
| 1448 | 1467 | 
| 1449     def RunEditor(desc, _, **kwargs): | 1468     def RunEditor(desc, _, **kwargs): | 
| 1450       self.assertEquals( | 1469       self.assertEquals( | 
| 1451           '# Enter a description of the change.\n' | 1470           '# Enter a description of the change.\n' | 
| 1452           '# This will be displayed on the codereview site.\n' | 1471           '# This will be displayed on the codereview site.\n' | 
| 1453           '# The first line will also be used as the subject of the review.\n' | 1472           '# The first line will also be used as the subject of the review.\n' | 
| 1454           '#--------------------This line is 72 characters long' | 1473           '#--------------------This line is 72 characters long' | 
| 1455           '--------------------\n' + | 1474           '--------------------\n' | 
| 1456           # TODO(tandrii): fix this http://crbug.com/614587. | 1475           'Some.\n\nBUG=\n\nChange-Id: xxx', | 
| 1457           current_desc + '\n\nBUG=', |  | 
| 1458           desc) | 1476           desc) | 
| 1459       return current_desc + '\n\nBUG=' | 1477       # Simulate user changing something. | 
|  | 1478       return 'Some.\n\nBUG=123\n\nChange-Id: xxx' | 
| 1460 | 1479 | 
| 1461     def UpdateDescriptionRemote(_, desc): | 1480     def UpdateDescriptionRemote(_, desc): | 
| 1462       # TODO(tandrii): fix this http://crbug.com/614587. | 1481       self.assertEquals(desc, 'Some.\n\nBUG=123\n\nChange-Id: xxx') | 
| 1463       self.assertEquals(desc, current_desc + '\n\nBUG=') |  | 
| 1464 | 1482 | 
| 1465     self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | 1483     self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | 
| 1466     self.mock(git_cl.Changelist, 'GetDescription', | 1484     self.mock(git_cl.Changelist, 'GetDescription', | 
| 1467               lambda *args: current_desc) | 1485               lambda *args: current_desc) | 
| 1468     self.mock(git_cl._GerritChangelistImpl, 'UpdateDescriptionRemote', | 1486     self.mock(git_cl._GerritChangelistImpl, 'UpdateDescriptionRemote', | 
| 1469               UpdateDescriptionRemote) | 1487               UpdateDescriptionRemote) | 
| 1470     self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) | 1488     self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) | 
| 1471 | 1489 | 
| 1472     self.calls = [ | 1490     self.calls = [ | 
| 1473         ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), | 1491         ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 1504         ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],), | 1522         ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],), | 
| 1505          ''), | 1523          ''), | 
| 1506     ] | 1524     ] | 
| 1507     self.assertEqual(0, git_cl.main(['issue', '0'])) | 1525     self.assertEqual(0, git_cl.main(['issue', '0'])) | 
| 1508 | 1526 | 
| 1509 | 1527 | 
| 1510 if __name__ == '__main__': | 1528 if __name__ == '__main__': | 
| 1511   git_cl.logging.basicConfig( | 1529   git_cl.logging.basicConfig( | 
| 1512       level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 1530       level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 
| 1513   unittest.main() | 1531   unittest.main() | 
| OLD | NEW | 
|---|