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

Side by Side Diff: tests/git_cl_test.py

Issue 2055003003: Mock stdout to avoid pollutting test runner stdout. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: 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
« no previous file with comments | « no previous file | 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 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 out = StringIO.StringIO() 1500 out = StringIO.StringIO()
1501 self.mock(git_cl.sys, 'stdout', out) 1501 self.mock(git_cl.sys, 'stdout', out)
1502 1502
1503 self.mock(git_cl, 'Changelist', ChangelistMock) 1503 self.mock(git_cl, 'Changelist', ChangelistMock)
1504 self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hi \r\n\t there\n\nman')) 1504 self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hi \r\n\t there\n\nman'))
1505 1505
1506 self.assertEqual(0, git_cl.main(['description', '-n', '-'])) 1506 self.assertEqual(0, git_cl.main(['description', '-n', '-']))
1507 self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc) 1507 self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc)
1508 1508
1509 def test_archive(self): 1509 def test_archive(self):
1510 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1511
1510 self.calls = \ 1512 self.calls = \
1511 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],), 1513 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],),
1512 'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'), 1514 'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'),
1513 ((['git', 'config', 'branch.master.rietveldissue'],), '1'), 1515 ((['git', 'config', 'branch.master.rietveldissue'],), '1'),
1514 ((['git', 'config', 'rietveld.autoupdate'],), ''), 1516 ((['git', 'config', 'rietveld.autoupdate'],), ''),
1515 ((['git', 'config', 'rietveld.server'],), ''), 1517 ((['git', 'config', 'rietveld.server'],), ''),
1516 ((['git', 'config', 'rietveld.server'],), ''), 1518 ((['git', 'config', 'rietveld.server'],), ''),
1517 ((['git', 'config', 'branch.foo.rietveldissue'],), '456'), 1519 ((['git', 'config', 'branch.foo.rietveldissue'],), '456'),
1518 ((['git', 'config', 'rietveld.server'],), ''), 1520 ((['git', 'config', 'rietveld.server'],), ''),
1519 ((['git', 'config', 'rietveld.server'],), ''), 1521 ((['git', 'config', 'rietveld.server'],), ''),
(...skipping 14 matching lines...) Expand all
1534 1536
1535 self.mock(git_cl, 'get_cl_statuses', 1537 self.mock(git_cl, 'get_cl_statuses',
1536 lambda branches, fine_grained, max_processes: 1538 lambda branches, fine_grained, max_processes:
1537 [(MockChangelist('master', 1), 'open'), 1539 [(MockChangelist('master', 1), 'open'),
1538 (MockChangelist('foo', 456), 'closed'), 1540 (MockChangelist('foo', 456), 'closed'),
1539 (MockChangelist('bar', 789), 'open')]) 1541 (MockChangelist('bar', 789), 'open')])
1540 1542
1541 self.assertEqual(0, git_cl.main(['archive', '-f'])) 1543 self.assertEqual(0, git_cl.main(['archive', '-f']))
1542 1544
1543 def test_archive_current_branch_fails(self): 1545 def test_archive_current_branch_fails(self):
1546 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1544 self.calls = \ 1547 self.calls = \
1545 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],), 1548 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],),
1546 'refs/heads/master'), 1549 'refs/heads/master'),
1547 ((['git', 'config', 'branch.master.rietveldissue'],), '1'), 1550 ((['git', 'config', 'branch.master.rietveldissue'],), '1'),
1548 ((['git', 'config', 'rietveld.autoupdate'],), ''), 1551 ((['git', 'config', 'rietveld.autoupdate'],), ''),
1549 ((['git', 'config', 'rietveld.server'],), ''), 1552 ((['git', 'config', 'rietveld.server'],), ''),
1550 ((['git', 'config', 'rietveld.server'],), ''), 1553 ((['git', 'config', 'rietveld.server'],), ''),
1551 ((['git', 'symbolic-ref', 'HEAD'],), 'master')] 1554 ((['git', 'symbolic-ref', 'HEAD'],), 'master')]
1552 1555
1553 class MockChangelist(): 1556 class MockChangelist():
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],), 1628 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],),
1626 ''), 1629 ''),
1627 ] 1630 ]
1628 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) 1631 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True)
1629 1632
1630 1633
1631 if __name__ == '__main__': 1634 if __name__ == '__main__':
1632 git_cl.logging.basicConfig( 1635 git_cl.logging.basicConfig(
1633 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 1636 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
1634 unittest.main() 1637 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698