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

Unified Diff: tests/presubmit_unittest.py

Issue 147162: Ask for feedback one time out of 5, only when there is presubmit check notification. (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 side-by-side diff with in-line comments
Download patch
« presubmit_support.py ('K') | « presubmit_support.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/presubmit_unittest.py
diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py
index bf9237cac2cf4d6c0c01816c6782837d4e075948..f6399c7e0394bd8979eadbcc02ec04bb470282fc 100755
--- a/tests/presubmit_unittest.py
+++ b/tests/presubmit_unittest.py
@@ -48,7 +48,9 @@ def CheckChangeOnUpload(input_api, output_api):
presubmit.os.path.dirname = os_path_dirname
presubmit.os.path.normpath = os_path_normpath
presubmit.os.path.splitext = os_path_splitext
+ self.mox.StubOutWithMock(presubmit, 'random')
self.mox.StubOutWithMock(presubmit, 'sys')
+ presubmit._ASKED_FOR_FEEDBACK = False
# Special mocks.
def MockAbsPath(f):
return f
@@ -71,8 +73,8 @@ class PresubmitUnittest(PresubmitTestsBase):
'SvnAffectedFile', 'SvnChange',
'cPickle', 'cStringIO', 'exceptions',
'fnmatch', 'gcl', 'gclient', 'glob', 'logging', 'marshal', 'normpath',
- 'optparse',
- 'os', 'pickle', 'presubmit_canned_checks', 're', 'subprocess', 'sys',
+ 'optparse', 'os', 'pickle',
+ 'presubmit_canned_checks', 'random', 're', 'subprocess', 'sys',
'tempfile', 'traceback', 'types', 'unittest', 'urllib2', 'warnings',
]
# If this test fails, you should add the relevant test.
@@ -295,6 +297,7 @@ class PresubmitUnittest(PresubmitTestsBase):
'rU').AndReturn(self.presubmit_text)
presubmit.gcl.ReadFile(haspresubmit_path,
'rU').AndReturn(self.presubmit_text)
+ presubmit.random.randint(0, 4).AndReturn(1)
self.mox.ReplayAll()
output = StringIO.StringIO()
@@ -322,6 +325,8 @@ class PresubmitUnittest(PresubmitTestsBase):
).AndReturn(self.presubmit_text)
presubmit.gcl.ReadFile(haspresubmit_path, 'rU'
).AndReturn(self.presubmit_text)
+ presubmit.random.randint(0, 4).AndReturn(1)
+ presubmit.random.randint(0, 4).AndReturn(1)
self.mox.ReplayAll()
output = StringIO.StringIO()
@@ -355,6 +360,7 @@ class PresubmitUnittest(PresubmitTestsBase):
presubmit.gcl.ReadFile(presubmit_path, 'rU').AndReturn(self.presubmit_text)
presubmit.gcl.ReadFile(haspresubmit_path, 'rU').AndReturn(
self.presubmit_text)
+ presubmit.random.randint(0, 4).AndReturn(1)
self.mox.ReplayAll()
output = StringIO.StringIO()
@@ -367,7 +373,7 @@ class PresubmitUnittest(PresubmitTestsBase):
self.assertEqual(output.getvalue().count('XX!!XX'), 2)
self.assertEqual(output.getvalue().count('(y/N)'), 0)
- def testDoDefaultPresubmitChecks(self):
+ def testDoDefaultPresubmitChecksAndFeedback(self):
join = presubmit.os.path.join
description_lines = ('Hello there',
'this is a change',
@@ -386,6 +392,7 @@ def CheckChangeOnCommit(input_api, output_api):
presubmit.os.path.isfile(join(self.fake_root_dir,
'haspresubmit',
'PRESUBMIT.py')).AndReturn(False)
+ presubmit.random.randint(0, 4).AndReturn(0)
self.mox.ReplayAll()
output = StringIO.StringIO()
@@ -395,7 +402,12 @@ def CheckChangeOnCommit(input_api, output_api):
self.fake_root_dir, files, 0, 0)
self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input,
DEFAULT_SCRIPT, False))
- self.assertEquals(output.getvalue().count('!!'), 1)
+ text = ('Warning, no presubmit.py found.\n'
+ 'Running default presubmit script.\n'
+ '** Presubmit ERRORS **\n!!\n\n'
+ 'Was the presubmit check useful? Please send feedback & hate mail '
+ 'to maruel@chromium.org!\n')
+ self.assertEquals(output.getvalue(), text)
def testDirectoryHandling(self):
files = [
@@ -449,6 +461,7 @@ def CheckChangeOnUpload(input_api, output_api):
def CheckChangeOnCommit(input_api, output_api):
raise Exception("Test error")
"""
+ presubmit.random.randint(0, 4).AndReturn(1)
self.mox.ReplayAll()
output = StringIO.StringIO()
« presubmit_support.py ('K') | « presubmit_support.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698