Make DoPresubmitChecks unit tests clearer.

This is a follow-up to https://chromium-review.googlesource.com/c/419148/;
the purpose is to confirm that the behavior is how we want it to be when
there are presubmit errors and warnings.

BUG=671683

Change-Id: I5b295c200d3db1a374e4294bdd78a777ae36c832
Reviewed-on: https://chromium-review.googlesource.com/420975
Commit-Queue: Quinten Yearsley <qyearsley@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Reviewed-by: Aaron Gable <agable@chromium.org>
changes/75/420975/5
Quinten Yearsley 9 years ago committed by Commit Bot
parent 208db564b0
commit e9c794ea4e

@ -36,16 +36,13 @@ presubmit_canned_checks = presubmit.presubmit_canned_checks
class PresubmitTestsBase(SuperMoxTestBase): class PresubmitTestsBase(SuperMoxTestBase):
"""Setups and tear downs the mocks but doesn't test anything as-is.""" """Sets up and tears down the mocks but doesn't test anything as-is."""
presubmit_text = """ presubmit_text = """
def CheckChangeOnUpload(input_api, output_api): def CheckChangeOnUpload(input_api, output_api):
if not input_api.change.NOSUCHKEY: if input_api.change.ERROR:
return [output_api.PresubmitError("!!")] return [output_api.PresubmitError("!!")]
elif not input_api.change.REALLYNOSUCHKEY: if input_api.change.PROMPT_WARNING:
return [output_api.PresubmitPromptWarning("??")] return [output_api.PresubmitPromptWarning("??")]
elif not input_api.change.REALLYABSOLUTELYNOSUCHKEY:
return [output_api.PresubmitPromptWarning("??"),
output_api.PresubmitError("XX!!XX")]
else: else:
return () return ()
""" """
@ -542,7 +539,7 @@ class PresubmitUnittest(PresubmitTestsBase):
self.failUnless(executer.ExecPresubmitScript( self.failUnless(executer.ExecPresubmitScript(
('def CheckChangeOnCommit(input_api, output_api):\n' ('def CheckChangeOnCommit(input_api, output_api):\n'
' if not input_api.change.NOSUCHKEY:\n' ' if not input_api.change.ERROR:\n'
' return [output_api.PresubmitError("!!")]\n' ' return [output_api.PresubmitError("!!")]\n'
' else:\n' ' else:\n'
' return ()'), ' return ()'),
@ -561,7 +558,7 @@ class PresubmitUnittest(PresubmitTestsBase):
' return ["foo"]', ' return ["foo"]',
fake_presubmit) fake_presubmit)
def testDoPresubmitChecks(self): def testDoPresubmitChecksNoWarningsOrErrors(self):
haspresubmit_path = presubmit.os.path.join( haspresubmit_path = presubmit.os.path.join(
self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py')
root_path = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py') root_path = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py')
@ -577,7 +574,6 @@ class PresubmitUnittest(PresubmitTestsBase):
self.presubmit_text) self.presubmit_text)
presubmit.gclient_utils.FileRead(haspresubmit_path, 'rU').AndReturn( presubmit.gclient_utils.FileRead(haspresubmit_path, 'rU').AndReturn(
self.presubmit_text) self.presubmit_text)
presubmit.random.randint(0, 4).AndReturn(1)
self.mox.ReplayAll() self.mox.ReplayAll()
# Make a change which will have no warnings. # Make a change which will have no warnings.
@ -587,8 +583,9 @@ class PresubmitUnittest(PresubmitTestsBase):
change=change, committing=False, verbose=True, change=change, committing=False, verbose=True,
output_stream=None, input_stream=None, output_stream=None, input_stream=None,
default_presubmit=None, may_prompt=False, rietveld_obj=None) default_presubmit=None, may_prompt=False, rietveld_obj=None)
self.failIf(output.should_continue()) self.failUnless(output.should_continue())
self.assertEqual(output.getvalue().count('!!'), 2) self.assertEqual(output.getvalue().count('!!'), 0)
self.assertEqual(output.getvalue().count('??'), 0)
self.assertEqual(output.getvalue().count( self.assertEqual(output.getvalue().count(
'Running presubmit upload checks ...\n'), 1) 'Running presubmit upload checks ...\n'), 1)
@ -614,7 +611,7 @@ class PresubmitUnittest(PresubmitTestsBase):
self.mox.ReplayAll() self.mox.ReplayAll()
# Make a change with a single warning. # Make a change with a single warning.
change = self.ExampleChange(extra_lines=['NOSUCHKEY=http://tracker/123']) change = self.ExampleChange(extra_lines=['PROMPT_WARNING=yes'])
input_buf = StringIO.StringIO('n\n') # say no to the warning input_buf = StringIO.StringIO('n\n') # say no to the warning
output = presubmit.DoPresubmitChecks( output = presubmit.DoPresubmitChecks(
@ -653,7 +650,7 @@ class PresubmitUnittest(PresubmitTestsBase):
presubmit.random.randint(0, 4).AndReturn(1) presubmit.random.randint(0, 4).AndReturn(1)
self.mox.ReplayAll() self.mox.ReplayAll()
change = self.ExampleChange(extra_lines=['NOSUCHKEY=http://tracker/123']) change = self.ExampleChange(extra_lines=['PROMPT_WARNING=yes'])
# There is no input buffer and may_prompt is set to False. # There is no input buffer and may_prompt is set to False.
output = presubmit.DoPresubmitChecks( output = presubmit.DoPresubmitChecks(
@ -663,6 +660,7 @@ class PresubmitUnittest(PresubmitTestsBase):
# A warning is printed, and should_continue is True. # A warning is printed, and should_continue is True.
self.failUnless(output.should_continue()) self.failUnless(output.should_continue())
self.assertEquals(output.getvalue().count('??'), 2) self.assertEquals(output.getvalue().count('??'), 2)
self.assertEqual(output.getvalue().count('(y/N)'), 0)
self.assertEqual(output.getvalue().count( self.assertEqual(output.getvalue().count(
'Running presubmit upload checks ...\n'), 1) 'Running presubmit upload checks ...\n'), 1)
@ -685,16 +683,14 @@ class PresubmitUnittest(PresubmitTestsBase):
presubmit.random.randint(0, 4).AndReturn(1) presubmit.random.randint(0, 4).AndReturn(1)
self.mox.ReplayAll() self.mox.ReplayAll()
change = self.ExampleChange(extra_lines=[ change = self.ExampleChange(extra_lines=['ERROR=yes'])
'NOSUCHKEY=http://tracker/123',
'REALLYNOSUCHKEY=http://tracker/123'
])
output = presubmit.DoPresubmitChecks( output = presubmit.DoPresubmitChecks(
change=change, committing=False, verbose=True, change=change, committing=False, verbose=True,
output_stream=None, input_stream=None, output_stream=None, input_stream=None,
default_presubmit=None, may_prompt=False, rietveld_obj=None) default_presubmit=None, may_prompt=True, rietveld_obj=None)
self.assertEqual(output.getvalue().count('??'), 2) self.failIf(output.should_continue())
self.assertEqual(output.getvalue().count('XX!!XX'), 2) self.assertEqual(output.getvalue().count('??'), 0)
self.assertEqual(output.getvalue().count('!!'), 2)
self.assertEqual(output.getvalue().count('(y/N)'), 0) self.assertEqual(output.getvalue().count('(y/N)'), 0)
self.assertEqual(output.getvalue().count( self.assertEqual(output.getvalue().count(
'Running presubmit upload checks ...\n'), 1) 'Running presubmit upload checks ...\n'), 1)

Loading…
Cancel
Save