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

Side by Side Diff: tests/presubmit_unittest.py

Issue 1923623004: Add --dry_run to presubmit_support. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: fix Created 4 years, 7 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 | « presubmit_support.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 presubmit_support.py and presubmit_canned_checks.py.""" 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py."""
7 7
8 # pylint: disable=E1101,E1103 8 # pylint: disable=E1101,E1103
9 9
10 import StringIO 10 import StringIO
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 self.mox.StubOutWithMock(presubmit, 'ParseFiles') 1146 self.mox.StubOutWithMock(presubmit, 'ParseFiles')
1147 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None) 1147 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None)
1148 presubmit.ParseFiles(['random_file.txt'], None 1148 presubmit.ParseFiles(['random_file.txt'], None
1149 ).AndReturn([('M', 'random_file.txt')]) 1149 ).AndReturn([('M', 'random_file.txt')])
1150 output = self.mox.CreateMock(presubmit.PresubmitOutput) 1150 output = self.mox.CreateMock(presubmit.PresubmitOutput)
1151 output.should_continue().AndReturn(False) 1151 output.should_continue().AndReturn(False)
1152 1152
1153 presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False, 1153 presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False,
1154 mox.IgnoreArg(), 1154 mox.IgnoreArg(),
1155 mox.IgnoreArg(), 1155 mox.IgnoreArg(),
1156 None, False, None).AndReturn(output) 1156 None, False, None, None).AndReturn(output)
1157 self.mox.ReplayAll() 1157 self.mox.ReplayAll()
1158 1158
1159 self.assertEquals( 1159 self.assertEquals(
1160 True, 1160 True,
1161 presubmit.main(['--root', self.fake_root_dir, 'random_file.txt'])) 1161 presubmit.main(['--root', self.fake_root_dir, 'random_file.txt']))
1162 1162
1163 def testMainUnversionedFail(self): 1163 def testMainUnversionedFail(self):
1164 # OptParser calls presubmit.os.path.exists and is a pain when mocked. 1164 # OptParser calls presubmit.os.path.exists and is a pain when mocked.
1165 self.UnMock(presubmit.os.path, 'exists') 1165 self.UnMock(presubmit.os.path, 'exists')
1166 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks') 1166 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks')
(...skipping 23 matching lines...) Expand all
1190 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles', 1190 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles',
1191 'AffectedTextFiles', 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST', 1191 'AffectedTextFiles', 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST',
1192 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths', 'LocalToDepotPath', 1192 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths', 'LocalToDepotPath',
1193 'Command', 'RunTests', 'PresubmitLocalPath', 'ReadFile', 1193 'Command', 'RunTests', 'PresubmitLocalPath', 'ReadFile',
1194 'RightHandSideLines', 'ServerPaths', 'basename', 'cPickle', 'cpplint', 1194 'RightHandSideLines', 'ServerPaths', 'basename', 'cPickle', 'cpplint',
1195 'cStringIO', 'canned_checks', 'change', 'cpu_count', 'environ', 'glob', 1195 'cStringIO', 'canned_checks', 'change', 'cpu_count', 'environ', 'glob',
1196 'host_url', 'is_committing', 'json', 'logging', 'marshal', 'os_listdir', 1196 'host_url', 'is_committing', 'json', 'logging', 'marshal', 'os_listdir',
1197 'os_walk', 'os_path', 'os_stat', 'owners_db', 'pickle', 'platform', 1197 'os_walk', 'os_path', 'os_stat', 'owners_db', 'pickle', 'platform',
1198 'python_executable', 're', 'rietveld', 'subprocess', 'tbr', 'tempfile', 1198 'python_executable', 're', 'rietveld', 'subprocess', 'tbr', 'tempfile',
1199 'time', 'traceback', 'unittest', 'urllib2', 'version', 'verbose', 1199 'time', 'traceback', 'unittest', 'urllib2', 'version', 'verbose',
1200 'dry_run',
1200 ] 1201 ]
1201 # If this test fails, you should add the relevant test. 1202 # If this test fails, you should add the relevant test.
1202 self.compareMembers( 1203 self.compareMembers(
1203 presubmit.InputApi(self.fake_change, './.', False, None, False), 1204 presubmit.InputApi(self.fake_change, './.', False, None, False),
1204 members) 1205 members)
1205 1206
1206 def testDepotToLocalPath(self): 1207 def testDepotToLocalPath(self):
1207 presubmit.scm.SVN._CaptureInfo(['svn://foo/smurf'], self.fake_root_dir 1208 presubmit.scm.SVN._CaptureInfo(['svn://foo/smurf'], self.fake_root_dir
1208 ).AndReturn({'Path': 'prout'}) 1209 ).AndReturn({'Path': 'prout'})
1209 presubmit.scm.SVN._CaptureInfo( 1210 presubmit.scm.SVN._CaptureInfo(
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 class fake_CalledProcessError(Exception): 1847 class fake_CalledProcessError(Exception):
1847 def __str__(self): 1848 def __str__(self):
1848 return 'foo' 1849 return 'foo'
1849 input_api.subprocess.CalledProcessError = fake_CalledProcessError 1850 input_api.subprocess.CalledProcessError = fake_CalledProcessError
1850 input_api.verbose = False 1851 input_api.verbose = False
1851 1852
1852 input_api.change = change 1853 input_api.change = change
1853 input_api.host_url = 'http://localhost' 1854 input_api.host_url = 'http://localhost'
1854 input_api.is_committing = committing 1855 input_api.is_committing = committing
1855 input_api.tbr = False 1856 input_api.tbr = False
1857 input_api.dry_run = None
1856 input_api.python_executable = 'pyyyyython' 1858 input_api.python_executable = 'pyyyyython'
1857 input_api.platform = sys.platform 1859 input_api.platform = sys.platform
1858 input_api.cpu_count = 2 1860 input_api.cpu_count = 2
1859 input_api.time = time 1861 input_api.time = time
1860 input_api.canned_checks = presubmit_canned_checks 1862 input_api.canned_checks = presubmit_canned_checks
1861 input_api.Command = presubmit.CommandData 1863 input_api.Command = presubmit.CommandData
1862 input_api.RunTests = functools.partial( 1864 input_api.RunTests = functools.partial(
1863 presubmit.InputApi.RunTests, input_api) 1865 presubmit.InputApi.RunTests, input_api)
1864 return input_api 1866 return input_api
1865 1867
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 def testCannedCheckOwners_DryRun(self): 2637 def testCannedCheckOwners_DryRun(self):
2636 response = { 2638 response = {
2637 "owner_email": "john@example.com", 2639 "owner_email": "john@example.com",
2638 "cq_dry_run": True, 2640 "cq_dry_run": True,
2639 "reviewers": ["ben@example.com"], 2641 "reviewers": ["ben@example.com"],
2640 } 2642 }
2641 self.AssertOwnersWorks(approvers=set(), 2643 self.AssertOwnersWorks(approvers=set(),
2642 cq_dry_run=True, 2644 cq_dry_run=True,
2643 rietveld_response=response, 2645 rietveld_response=response,
2644 reviewers=set(["ben@example.com"]), 2646 reviewers=set(["ben@example.com"]),
2645 expected_output='This is a CQ dry run, skipping OWNERS check\n') 2647 expected_output='This is a dry run, skipping OWNERS check\n')
2646 2648
2647 self.AssertOwnersWorks(approvers=set(['ben@example.com']), 2649 self.AssertOwnersWorks(approvers=set(['ben@example.com']),
2648 is_committing=False, 2650 is_committing=False,
2649 rietveld_response=response, 2651 rietveld_response=response,
2650 expected_output='') 2652 expected_output='')
2651 2653
2652 def testCannedCheckOwners_Approved(self): 2654 def testCannedCheckOwners_Approved(self):
2653 response = { 2655 response = {
2654 "owner_email": "john@example.com", 2656 "owner_email": "john@example.com",
2655 "messages": [ 2657 "messages": [
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2888 owners_check=False) 2890 owners_check=False)
2889 self.assertEqual(2, len(results)) 2891 self.assertEqual(2, len(results))
2890 self.assertEqual( 2892 self.assertEqual(
2891 'Found line ending with white spaces in:', results[0]._message) 2893 'Found line ending with white spaces in:', results[0]._message)
2892 self.checkstdout('') 2894 self.checkstdout('')
2893 2895
2894 2896
2895 if __name__ == '__main__': 2897 if __name__ == '__main__':
2896 import unittest 2898 import unittest
2897 unittest.main() 2899 unittest.main()
OLDNEW
« no previous file with comments | « presubmit_support.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698