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

Side by Side Diff: tests/git_cl_test.py

Issue 1991563005: Add "archive" command to git_cl.py. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: rebase 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 | « 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 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 def test_description_set_stdin(self): 1497 def test_description_set_stdin(self):
1498 out = StringIO.StringIO() 1498 out = StringIO.StringIO()
1499 self.mock(git_cl.sys, 'stdout', out) 1499 self.mock(git_cl.sys, 'stdout', out)
1500 1500
1501 self.mock(git_cl, 'Changelist', ChangelistMock) 1501 self.mock(git_cl, 'Changelist', ChangelistMock)
1502 self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hi \r\n\t there\n\nman')) 1502 self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hi \r\n\t there\n\nman'))
1503 1503
1504 self.assertEqual(0, git_cl.main(['description', '-n', '-'])) 1504 self.assertEqual(0, git_cl.main(['description', '-n', '-']))
1505 self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc) 1505 self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc)
1506 1506
1507 def test_archive(self):
1508 self.calls = \
1509 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],),
1510 'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'),
1511 ((['git', 'config', 'branch.master.rietveldissue'],), '1'),
1512 ((['git', 'config', 'rietveld.autoupdate'],), ''),
1513 ((['git', 'config', 'rietveld.server'],), ''),
1514 ((['git', 'config', 'rietveld.server'],), ''),
1515 ((['git', 'config', 'branch.foo.rietveldissue'],), '456'),
1516 ((['git', 'config', 'rietveld.server'],), ''),
1517 ((['git', 'config', 'rietveld.server'],), ''),
1518 ((['git', 'config', 'branch.bar.rietveldissue'],), ''),
1519 ((['git', 'config', 'branch.bar.gerritissue'],), '789'),
1520 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
1521 ((['git', 'tag', 'git-cl-archived-456-foo', 'foo'],), ''),
1522 ((['git', 'branch', '-D', 'foo'],), '')]
1523
1524 class MockChangelist():
1525 def __init__(self, branch, issue):
1526 self.branch = branch
1527 self.issue = issue
1528 def GetBranch(self):
1529 return self.branch
1530 def GetIssue(self):
1531 return self.issue
1532
1533 self.mock(git_cl, 'get_cl_statuses',
1534 lambda branches, fine_grained, max_processes:
1535 [(MockChangelist('master', 1), 'open'),
1536 (MockChangelist('foo', 456), 'closed'),
1537 (MockChangelist('bar', 789), 'open')])
1538
1539 self.assertEqual(0, git_cl.main(['archive', '-f']))
1540
1541 def test_archive_current_branch_fails(self):
1542 self.calls = \
1543 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],),
1544 'refs/heads/master'),
1545 ((['git', 'config', 'branch.master.rietveldissue'],), '1'),
1546 ((['git', 'config', 'rietveld.autoupdate'],), ''),
1547 ((['git', 'config', 'rietveld.server'],), ''),
1548 ((['git', 'config', 'rietveld.server'],), ''),
1549 ((['git', 'symbolic-ref', 'HEAD'],), 'master')]
1550
1551 class MockChangelist():
1552 def __init__(self, branch, issue):
1553 self.branch = branch
1554 self.issue = issue
1555 def GetBranch(self):
1556 return self.branch
1557 def GetIssue(self):
1558 return self.issue
1559
1560 self.mock(git_cl, 'get_cl_statuses',
1561 lambda branches, fine_grained, max_processes:
1562 [(MockChangelist('master', 1), 'closed')])
1563
1564 self.assertEqual(1, git_cl.main(['archive', '-f']))
1565
1507 def test_cmd_issue_erase_existing(self): 1566 def test_cmd_issue_erase_existing(self):
1508 out = StringIO.StringIO() 1567 out = StringIO.StringIO()
1509 self.mock(git_cl.sys, 'stdout', out) 1568 self.mock(git_cl.sys, 'stdout', out)
1510 self.calls = [ 1569 self.calls = [
1511 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), 1570 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
1512 ((['git', 'config', 'branch.feature.rietveldissue'],), ''), 1571 ((['git', 'config', 'branch.feature.rietveldissue'],), ''),
1513 ((['git', 'config', 'branch.feature.gerritissue'],), '123'), 1572 ((['git', 'config', 'branch.feature.gerritissue'],), '123'),
1514 ((['git', 'config', '--unset', 'branch.feature.gerritissue'],), ''), 1573 ((['git', 'config', '--unset', 'branch.feature.gerritissue'],), ''),
1515 ((['git', 'config', '--unset', 'branch.feature.gerritpatchset'],), ''), 1574 ((['git', 'config', '--unset', 'branch.feature.gerritpatchset'],), ''),
1516 # Let this command raise exception (retcode=1) - it should be ignored. 1575 # Let this command raise exception (retcode=1) - it should be ignored.
1517 ((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],), 1576 ((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],),
1518 '', subprocess2.CalledProcessError(1, '', '', '', '')), 1577 '', subprocess2.CalledProcessError(1, '', '', '', '')),
1519 ((['git', 'config', '--unset', 'branch.feature.gerritserver'],), ''), 1578 ((['git', 'config', '--unset', 'branch.feature.gerritserver'],), ''),
1520 ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],), 1579 ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],),
1521 ''), 1580 ''),
1522 ] 1581 ]
1523 self.assertEqual(0, git_cl.main(['issue', '0'])) 1582 self.assertEqual(0, git_cl.main(['issue', '0']))
1524 1583
1525 1584
1526 if __name__ == '__main__': 1585 if __name__ == '__main__':
1527 git_cl.logging.basicConfig( 1586 git_cl.logging.basicConfig(
1528 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 1587 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
1529 unittest.main() 1588 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