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

Side by Side Diff: tests/git_cl_test.py

Issue 2274743003: Add a --json option to git cl try-results. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Add url and bucket, update test Created 4 years, 3 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 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 self.assertIsNone(cl.EnsureAuthenticated(force=False)) 1477 self.assertIsNone(cl.EnsureAuthenticated(force=False))
1478 1478
1479 def test_gerrit_ensure_authenticated_conflict(self): 1479 def test_gerrit_ensure_authenticated_conflict(self):
1480 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 1480 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1481 cl = self._test_gerrit_ensure_authenticated_common(auth={ 1481 cl = self._test_gerrit_ensure_authenticated_common(auth={
1482 'chromium.googlesource.com': 'one', 1482 'chromium.googlesource.com': 'one',
1483 'chromium-review.googlesource.com': 'other', 1483 'chromium-review.googlesource.com': 'other',
1484 }) 1484 })
1485 self.calls.append( 1485 self.calls.append(
1486 ((['ask_for_data', 'If you know what you are doing, ' 1486 ((['ask_for_data', 'If you know what you are doing, '
1487 » » » » » » » » » » » » 'press Enter to continue, Ctrl+C to abort.'],), '')) 1487 'press Enter to continue, Ctrl+C to abort.'],), ''))
1488 self.assertIsNone(cl.EnsureAuthenticated(force=False)) 1488 self.assertIsNone(cl.EnsureAuthenticated(force=False))
1489 1489
1490 def test_gerrit_ensure_authenticated_ok(self): 1490 def test_gerrit_ensure_authenticated_ok(self):
1491 cl = self._test_gerrit_ensure_authenticated_common(auth={ 1491 cl = self._test_gerrit_ensure_authenticated_common(auth={
1492 'chromium.googlesource.com': 'same', 1492 'chromium.googlesource.com': 'same',
1493 'chromium-review.googlesource.com': 'same', 1493 'chromium-review.googlesource.com': 'same',
1494 }) 1494 })
1495 self.assertIsNone(cl.EnsureAuthenticated(force=False)) 1495 self.assertIsNone(cl.EnsureAuthenticated(force=False))
1496 1496
1497 def test_gerrit_ensure_authenticated_skipped(self): 1497 def test_gerrit_ensure_authenticated_skipped(self):
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 ((['DoGetTrySlaves'], ), None), 1843 ((['DoGetTrySlaves'], ), None),
1844 ((['SetCQState', git_cl._CQState.DRY_RUN], ), None), 1844 ((['SetCQState', git_cl._CQState.DRY_RUN], ), None),
1845 ] 1845 ]
1846 out = StringIO.StringIO() 1846 out = StringIO.StringIO()
1847 self.mock(git_cl.sys, 'stdout', out) 1847 self.mock(git_cl.sys, 'stdout', out)
1848 self.assertEqual(0, git_cl.main(['try'])) 1848 self.assertEqual(0, git_cl.main(['try']))
1849 self.assertEqual( 1849 self.assertEqual(
1850 out.getvalue(), 1850 out.getvalue(),
1851 'scheduled CQ Dry Run on https://codereview.chromium.org/123\n') 1851 'scheduled CQ Dry Run on https://codereview.chromium.org/123\n')
1852 1852
1853 def test_write_try_results_json(self):
1854 builds = {
1855 '9000': {
1856 'id': '9000',
1857 'status': 'STARTED',
1858 'url': 'http://build.cr.org/p/x.y/builders/my-builder/builds/2',
1859 'result_details_json': '{"properties": {}}',
1860 'bucket': 'master.x.y',
1861 'created_by': 'user:someone@chromium.org',
1862 'created_ts': '147200002222000',
1863 'parameters_json': '{"builder_name": "my-builder", "category": ""}',
1864 },
1865 '8000': {
1866 'id': '8000',
1867 'status': 'COMPLETED',
1868 'result': 'FAILURE',
1869 'failure_reason': 'BUILD_FAILURE',
1870 'url': 'http://build.cr.org/p/x.y/builders/my-builder/builds/1',
1871 'result_details_json': '{"properties": {}}',
1872 'bucket': 'master.x.y',
1873 'created_by': 'user:someone@chromium.org',
1874 'created_ts': '147200001111000',
1875 'parameters_json': '{"builder_name": "my-builder", "category": ""}',
1876 },
1877 }
1878 expected_output = [
1879 {
1880 'buildbucket_id': '8000',
1881 'bucket': 'master.x.y',
1882 'builder_name': 'my-builder',
1883 'status': 'COMPLETED',
1884 'result': 'FAILURE',
1885 'failure_reason': 'BUILD_FAILURE',
1886 'url': 'http://build.cr.org/p/x.y/builders/my-builder/builds/1',
1887 },
1888 {
1889 'buildbucket_id': '9000',
1890 'bucket': 'master.x.y',
1891 'builder_name': 'my-builder',
1892 'status': 'STARTED',
1893 'result': None,
1894 'failure_reason': None,
1895 'url': 'http://build.cr.org/p/x.y/builders/my-builder/builds/2',
1896 }
1897 ]
1898 self.calls = [(('write_json', 'output.json', expected_output), '')]
1899 git_cl.write_try_results_json('output.json', builds)
1900
1853 def _common_GerritCommitMsgHookCheck(self): 1901 def _common_GerritCommitMsgHookCheck(self):
1854 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 1902 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1855 self.mock(git_cl.os.path, 'abspath', 1903 self.mock(git_cl.os.path, 'abspath',
1856 lambda path: self._mocked_call(['abspath', path])) 1904 lambda path: self._mocked_call(['abspath', path]))
1857 self.mock(git_cl.os.path, 'exists', 1905 self.mock(git_cl.os.path, 'exists',
1858 lambda path: self._mocked_call(['exists', path])) 1906 lambda path: self._mocked_call(['exists', path]))
1859 self.mock(git_cl.gclient_utils, 'FileRead', 1907 self.mock(git_cl.gclient_utils, 'FileRead',
1860 lambda path: self._mocked_call(['FileRead', path])) 1908 lambda path: self._mocked_call(['FileRead', path]))
1861 self.mock(git_cl.gclient_utils, 'rm_file_or_tree', 1909 self.mock(git_cl.gclient_utils, 'rm_file_or_tree',
1862 lambda path: self._mocked_call(['rm_file_or_tree', path])) 1910 lambda path: self._mocked_call(['rm_file_or_tree', path]))
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1909 'current_revision': 'deadbeaf', 1957 'current_revision': 'deadbeaf',
1910 } 1958 }
1911 cl._codereview_impl.SubmitIssue = lambda wait_for_merge: None 1959 cl._codereview_impl.SubmitIssue = lambda wait_for_merge: None
1912 self.assertEqual(0, cl.CMDLand(force=True, bypass_hooks=True, verbose=True)) 1960 self.assertEqual(0, cl.CMDLand(force=True, bypass_hooks=True, verbose=True))
1913 1961
1914 1962
1915 if __name__ == '__main__': 1963 if __name__ == '__main__':
1916 git_cl.logging.basicConfig( 1964 git_cl.logging.basicConfig(
1917 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 1965 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
1918 unittest.main() 1966 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