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

Side by Side Diff: tests/git_cl_test.py

Issue 2245263007: Add --issue to set-commit and set-close too. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 4 years, 4 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
« 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 return { 55 return {
56 'reviewers': ['joe@chromium.org', 'john@chromium.org'], 56 'reviewers': ['joe@chromium.org', 'john@chromium.org'],
57 'messages': [ 57 'messages': [
58 { 58 {
59 'approval': True, 59 'approval': True,
60 'sender': 'john@chromium.org', 60 'sender': 'john@chromium.org',
61 }, 61 },
62 ], 62 ],
63 } 63 }
64 64
65 @staticmethod
66 def close_issue(_issue):
67 return 'Closed'
68
65 69
66 class WatchlistsMock(object): 70 class WatchlistsMock(object):
67 def __init__(self, _): 71 def __init__(self, _):
68 pass 72 pass
69 @staticmethod 73 @staticmethod
70 def GetWatchersForPaths(_): 74 def GetWatchersForPaths(_):
71 return ['joe@example.com'] 75 return ['joe@example.com']
72 76
73 77
74 class CodereviewSettingsFileMock(object): 78 class CodereviewSettingsFileMock(object):
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 self.assertEqual('foobar\n', out.getvalue()) 1537 self.assertEqual('foobar\n', out.getvalue())
1534 1538
1535 def test_StatusFieldOverrideIssueMissingArgs(self): 1539 def test_StatusFieldOverrideIssueMissingArgs(self):
1536 out = StringIO.StringIO() 1540 out = StringIO.StringIO()
1537 self.mock(git_cl.sys, 'stderr', out) 1541 self.mock(git_cl.sys, 'stderr', out)
1538 1542
1539 try: 1543 try:
1540 self.assertEqual(git_cl.main(['status', '--issue', '1']), 0) 1544 self.assertEqual(git_cl.main(['status', '--issue', '1']), 0)
1541 except SystemExit as ex: 1545 except SystemExit as ex:
1542 self.assertEqual(ex.code, 2) 1546 self.assertEqual(ex.code, 2)
1543 self.assertRegexpMatches(out.getvalue(), r'--issue may only be specified') 1547 self.assertRegexpMatches(out.getvalue(), r'--issue must be specified')
1544 1548
1545 out = StringIO.StringIO() 1549 out = StringIO.StringIO()
1546 self.mock(git_cl.sys, 'stderr', out) 1550 self.mock(git_cl.sys, 'stderr', out)
1547 1551
1548 try: 1552 try:
1549 self.assertEqual(git_cl.main(['status', '--issue', '1', '--rietveld']), 0) 1553 self.assertEqual(git_cl.main(['status', '--issue', '1', '--rietveld']), 0)
1550 except SystemExit as ex: 1554 except SystemExit as ex:
1551 self.assertEqual(ex.code, 2) 1555 self.assertEqual(ex.code, 2)
1552 self.assertRegexpMatches(out.getvalue(), r'--issue may only be specified') 1556 self.assertRegexpMatches(out.getvalue(), r'--field must be specified')
1553 1557
1554 def test_StatusFieldOverrideIssue(self): 1558 def test_StatusFieldOverrideIssue(self):
1555 out = StringIO.StringIO() 1559 out = StringIO.StringIO()
1556 self.mock(git_cl.sys, 'stdout', out) 1560 self.mock(git_cl.sys, 'stdout', out)
1557 1561
1558 def assertIssue(cl_self, *_args): 1562 def assertIssue(cl_self, *_args):
1559 self.assertEquals(cl_self.issue, 1) 1563 self.assertEquals(cl_self.issue, 1)
1560 return 'foobar' 1564 return 'foobar'
1561 1565
1562 self.mock(git_cl.Changelist, 'GetDescription', assertIssue) 1566 self.mock(git_cl.Changelist, 'GetDescription', assertIssue)
1563 self.calls = [ 1567 self.calls = [
1564 ((['git', 'config', 'rietveld.autoupdate'],), ''), 1568 ((['git', 'config', 'rietveld.autoupdate'],), ''),
1565 ((['git', 'config', 'rietveld.server'],), ''), 1569 ((['git', 'config', 'rietveld.server'],), ''),
1566 ((['git', 'config', 'rietveld.server'],), ''), 1570 ((['git', 'config', 'rietveld.server'],), ''),
1567 ] 1571 ]
1568 git_cl.main(['status', '--issue', '1', '--rietveld', '--field', 'desc']) 1572 self.assertEqual(
1573 git_cl.main(['status', '--issue', '1', '--rietveld', '--field', 'desc']),
1574 0)
1569 self.assertEqual(out.getvalue(), 'foobar\n') 1575 self.assertEqual(out.getvalue(), 'foobar\n')
1570 1576
1577 def test_SetCloseOverrideIssue(self):
1578 def assertIssue(cl_self, *_args):
1579 self.assertEquals(cl_self.issue, 1)
1580 return 'foobar'
1581
1582 self.mock(git_cl.Changelist, 'GetDescription', assertIssue)
1583 self.mock(git_cl.Changelist, 'CloseIssue', lambda *_: None)
1584 self.calls = [
1585 ((['git', 'config', 'rietveld.autoupdate'],), ''),
1586 ((['git', 'config', 'rietveld.server'],), ''),
1587 ((['git', 'config', 'rietveld.server'],), ''),
1588 ]
1589 self.assertEqual(
1590 git_cl.main(['set-close', '--issue', '1', '--rietveld']), 0)
1591
1592 def test_SetCommitOverrideIssue(self):
tandrii(chromium) 2016/08/17 21:05:31 and with this, commit-queue tool in depot_tools ca
iannucci 2016/08/17 21:37:08 :)
1593 def assertIssue(cl_self, *_args):
1594 self.assertEquals(cl_self.issue, 1)
1595 return 'foobar'
1596
1597 self.mock(git_cl.Changelist, 'GetDescription', assertIssue)
1598 self.mock(git_cl.Changelist, 'SetCQState', lambda *_: None)
1599 self.calls = [
1600 ((['git', 'config', 'rietveld.autoupdate'],), ''),
1601 ((['git', 'config', 'rietveld.server'],), ''),
1602 ((['git', 'config', 'rietveld.server'],), ''),
1603 ((['git', 'symbolic-ref', 'HEAD'],), ''),
1604 ((['git', 'config', 'rietveld.server'],), ''),
1605 ((['git', 'config', 'rietveld.server'],), ''),
1606 ]
1607 self.assertEqual(
1608 git_cl.main(['set-close', '--issue', '1', '--rietveld']), 0)
1609
1571 def test_description_gerrit(self): 1610 def test_description_gerrit(self):
1572 out = StringIO.StringIO() 1611 out = StringIO.StringIO()
1573 self.mock(git_cl.sys, 'stdout', out) 1612 self.mock(git_cl.sys, 'stdout', out)
1574 self.mock(git_cl.Changelist, 'GetDescription', lambda *args: 'foobar') 1613 self.mock(git_cl.Changelist, 'GetDescription', lambda *args: 'foobar')
1575 1614
1576 self.assertEqual(0, git_cl.main([ 1615 self.assertEqual(0, git_cl.main([
1577 'description', 'https://code.review.org/123123', '-d', '--gerrit'])) 1616 'description', 'https://code.review.org/123123', '-d', '--gerrit']))
1578 self.assertEqual('foobar\n', out.getvalue()) 1617 self.assertEqual('foobar\n', out.getvalue())
1579 1618
1580 def test_description_set_raw(self): 1619 def test_description_set_raw(self):
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],), 1830 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],),
1792 ''), 1831 ''),
1793 ] 1832 ]
1794 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) 1833 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True)
1795 1834
1796 1835
1797 if __name__ == '__main__': 1836 if __name__ == '__main__':
1798 git_cl.logging.basicConfig( 1837 git_cl.logging.basicConfig(
1799 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 1838 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
1800 unittest.main() 1839 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