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

Side by Side Diff: tests/presubmit_unittest.py

Issue 119284: Use more sensible behavior in presubmit checks. (Closed)
Patch Set: Created 11 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 | « presubmit_canned_checks.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/python 1 #!/usr/bin/python
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2009 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 import exceptions 8 import exceptions
9 import random 9 import random
10 import string 10 import string
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 presubmit.OutputApi.PresubmitError) 918 presubmit.OutputApi.PresubmitError)
919 919
920 def testCannedCheckDoNotSubmitInFiles(self): 920 def testCannedCheckDoNotSubmitInFiles(self):
921 self.TestContent(presubmit_canned_checks.CheckDoNotSubmitInFiles, 921 self.TestContent(presubmit_canned_checks.CheckDoNotSubmitInFiles,
922 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', 922 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT',
923 presubmit.OutputApi.PresubmitError) 923 presubmit.OutputApi.PresubmitError)
924 924
925 def testCannedCheckChangeHasNoTabs(self): 925 def testCannedCheckChangeHasNoTabs(self):
926 self.TestContent(presubmit_canned_checks.CheckChangeHasNoTabs, 926 self.TestContent(presubmit_canned_checks.CheckChangeHasNoTabs,
927 'blah blah', 'blah\tblah', 927 'blah blah', 'blah\tblah',
928 presubmit.OutputApi.PresubmitError) 928 presubmit.OutputApi.PresubmitPromptWarning)
929 929
930 def testCannedCheckLongLines(self): 930 def testCannedCheckLongLines(self):
931 check = lambda x,y: presubmit_canned_checks.CheckLongLines(x, y, 10) 931 check = lambda x,y: presubmit_canned_checks.CheckLongLines(x, y, 10)
932 self.TestContent(check, '', 'blah blah blah', 932 self.TestContent(check, '', 'blah blah blah',
933 presubmit.OutputApi.PresubmitPromptWarning) 933 presubmit.OutputApi.PresubmitPromptWarning)
934 934
935 def testCannedCheckTreeIsOpenOpen(self): 935 def testCannedCheckTreeIsOpenOpen(self):
936 input_api = self.MockInputApi() 936 input_api = self.MockInputApi()
937 input_api.is_committing = True
937 connection = self.mox.CreateMockAnything() 938 connection = self.mox.CreateMockAnything()
938 input_api.urllib2.urlopen('url_to_open').AndReturn(connection) 939 input_api.urllib2.urlopen('url_to_open').AndReturn(connection)
939 connection.read().AndReturn('1') 940 connection.read().AndReturn('1')
940 connection.close() 941 connection.close()
941 self.mox.ReplayAll() 942 self.mox.ReplayAll()
942 results = presubmit_canned_checks.CheckTreeIsOpen( 943 results = presubmit_canned_checks.CheckTreeIsOpen(
943 input_api, presubmit.OutputApi, url='url_to_open', closed='0') 944 input_api, presubmit.OutputApi, url='url_to_open', closed='0')
944 self.assertEquals(results, []) 945 self.assertEquals(results, [])
945 946
946 def testCannedCheckTreeIsOpenClosed(self): 947 def testCannedCheckTreeIsOpenClosed(self):
947 input_api = self.MockInputApi() 948 input_api = self.MockInputApi()
949 input_api.is_committing = True
948 connection = self.mox.CreateMockAnything() 950 connection = self.mox.CreateMockAnything()
949 input_api.urllib2.urlopen('url_to_closed').AndReturn(connection) 951 input_api.urllib2.urlopen('url_to_closed').AndReturn(connection)
950 connection.read().AndReturn('0') 952 connection.read().AndReturn('0')
951 connection.close() 953 connection.close()
952 self.mox.ReplayAll() 954 self.mox.ReplayAll()
953 results = presubmit_canned_checks.CheckTreeIsOpen( 955 results = presubmit_canned_checks.CheckTreeIsOpen(
954 input_api, presubmit.OutputApi, url='url_to_closed', closed='0') 956 input_api, presubmit.OutputApi, url='url_to_closed', closed='0')
955 self.assertEquals(len(results), 1) 957 self.assertEquals(len(results), 1)
956 self.assertEquals(results[0].__class__, 958 self.assertEquals(results[0].__class__,
957 presubmit.OutputApi.PresubmitError) 959 presubmit.OutputApi.PresubmitPromptWarning)
958 960
959 def testRunPythonUnitTestsNoTest(self): 961 def testRunPythonUnitTestsNoTest(self):
960 input_api = self.MockInputApi() 962 input_api = self.MockInputApi()
961 input_api.is_committing = False 963 input_api.is_committing = False
962 self.mox.ReplayAll() 964 self.mox.ReplayAll()
963 results = presubmit_canned_checks.RunPythonUnitTests( 965 results = presubmit_canned_checks.RunPythonUnitTests(
964 input_api, presubmit.OutputApi, []) 966 input_api, presubmit.OutputApi, [])
965 self.assertEquals(results, []) 967 self.assertEquals(results, [])
966 968
967 def testRunPythonUnitTestsNonExistent1(self): 969 def testRunPythonUnitTestsNonExistent1(self):
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 test_result.errors = 0 1078 test_result.errors = 0
1077 self.mox.ReplayAll() 1079 self.mox.ReplayAll()
1078 1080
1079 results = presubmit_canned_checks.RunPythonUnitTests( 1081 results = presubmit_canned_checks.RunPythonUnitTests(
1080 input_api, presubmit.OutputApi, ['test_module']) 1082 input_api, presubmit.OutputApi, ['test_module'])
1081 self.assertEquals(len(results), 0) 1083 self.assertEquals(len(results), 0)
1082 1084
1083 1085
1084 if __name__ == '__main__': 1086 if __name__ == '__main__':
1085 unittest.main() 1087 unittest.main()
OLDNEW
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698