Chromium Code Reviews| 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 1725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1736 return self.branch | 1736 return self.branch |
| 1737 def GetIssue(self): | 1737 def GetIssue(self): |
| 1738 return self.issue | 1738 return self.issue |
| 1739 | 1739 |
| 1740 self.mock(git_cl, 'get_cl_statuses', | 1740 self.mock(git_cl, 'get_cl_statuses', |
| 1741 lambda branches, fine_grained, max_processes: | 1741 lambda branches, fine_grained, max_processes: |
| 1742 [(MockChangelist('master', 1), 'closed')]) | 1742 [(MockChangelist('master', 1), 'closed')]) |
| 1743 | 1743 |
| 1744 self.assertEqual(1, git_cl.main(['archive', '-f'])) | 1744 self.assertEqual(1, git_cl.main(['archive', '-f'])) |
| 1745 | 1745 |
| 1746 def test_archive_dry_run(self): | |
| 1747 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | |
| 1748 | |
| 1749 self.calls = \ | |
| 1750 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],), | |
| 1751 'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'), | |
| 1752 ((['git', 'config', 'branch.master.rietveldissue'],), '1'), | |
| 1753 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), | |
| 1754 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), | |
| 1755 ((['git', 'config', 'branch.foo.rietveldissue'],), '456'), | |
| 1756 ((['git', 'config', 'branch.bar.rietveldissue'],), CERR1), | |
| 1757 ((['git', 'config', 'branch.bar.gerritissue'],), '789'), | |
| 1758 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),] | |
| 1759 | |
| 1760 class MockChangelist(): | |
|
tandrii(chromium)
2016/08/23 18:41:49
this thing is being copy-pasted in this file like
| |
| 1761 def __init__(self, branch, issue): | |
| 1762 self.branch = branch | |
| 1763 self.issue = issue | |
| 1764 def GetBranch(self): | |
| 1765 return self.branch | |
| 1766 def GetIssue(self): | |
| 1767 return self.issue | |
| 1768 | |
| 1769 self.mock(git_cl, 'get_cl_statuses', | |
| 1770 lambda branches, fine_grained, max_processes: | |
| 1771 [(MockChangelist('master', 1), 'open'), | |
| 1772 (MockChangelist('foo', 456), 'closed'), | |
| 1773 (MockChangelist('bar', 789), 'open')]) | |
| 1774 | |
| 1775 self.assertEqual(0, git_cl.main(['archive', '-f', '--dry-run'])) | |
| 1776 | |
| 1777 def test_archive_no_tags(self): | |
| 1778 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | |
| 1779 | |
| 1780 self.calls = \ | |
| 1781 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],), | |
| 1782 'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'), | |
| 1783 ((['git', 'config', 'branch.master.rietveldissue'],), '1'), | |
| 1784 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), | |
| 1785 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), | |
| 1786 ((['git', 'config', 'branch.foo.rietveldissue'],), '456'), | |
| 1787 ((['git', 'config', 'branch.bar.rietveldissue'],), CERR1), | |
| 1788 ((['git', 'config', 'branch.bar.gerritissue'],), '789'), | |
| 1789 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | |
| 1790 ((['git', 'branch', '-D', 'foo'],), '')] | |
| 1791 | |
| 1792 class MockChangelist(): | |
| 1793 def __init__(self, branch, issue): | |
| 1794 self.branch = branch | |
| 1795 self.issue = issue | |
| 1796 def GetBranch(self): | |
| 1797 return self.branch | |
| 1798 def GetIssue(self): | |
| 1799 return self.issue | |
| 1800 | |
| 1801 self.mock(git_cl, 'get_cl_statuses', | |
| 1802 lambda branches, fine_grained, max_processes: | |
| 1803 [(MockChangelist('master', 1), 'open'), | |
| 1804 (MockChangelist('foo', 456), 'closed'), | |
| 1805 (MockChangelist('bar', 789), 'open')]) | |
| 1806 | |
| 1807 self.assertEqual(0, git_cl.main(['archive', '-f', '--notags'])) | |
| 1808 | |
| 1746 def test_cmd_issue_erase_existing(self): | 1809 def test_cmd_issue_erase_existing(self): |
| 1747 out = StringIO.StringIO() | 1810 out = StringIO.StringIO() |
| 1748 self.mock(git_cl.sys, 'stdout', out) | 1811 self.mock(git_cl.sys, 'stdout', out) |
| 1749 self.calls = [ | 1812 self.calls = [ |
| 1750 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), | 1813 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 1751 ((['git', 'config', 'branch.feature.rietveldissue'],), CERR1), | 1814 ((['git', 'config', 'branch.feature.rietveldissue'],), CERR1), |
| 1752 ((['git', 'config', 'branch.feature.gerritissue'],), '123'), | 1815 ((['git', 'config', 'branch.feature.gerritissue'],), '123'), |
| 1753 # Let this command raise exception (retcode=1) - it should be ignored. | 1816 # Let this command raise exception (retcode=1) - it should be ignored. |
| 1754 ((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],), | 1817 ((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],), |
| 1755 CERR1), | 1818 CERR1), |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1857 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],), | 1920 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],), |
| 1858 ''), | 1921 ''), |
| 1859 ] | 1922 ] |
| 1860 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) | 1923 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) |
| 1861 | 1924 |
| 1862 | 1925 |
| 1863 if __name__ == '__main__': | 1926 if __name__ == '__main__': |
| 1864 git_cl.logging.basicConfig( | 1927 git_cl.logging.basicConfig( |
| 1865 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 1928 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
| 1866 unittest.main() | 1929 unittest.main() |
| OLD | NEW |