Commit f3eee569 authored by maruel@chromium.org's avatar maruel@chromium.org

Add a unit test for input_api.change.tags.

Review URL: http://codereview.chromium.org/113859

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@16959 0039d316-1c4b-4281-b951-d872f2087c98
parent ce30ef7c
......@@ -661,17 +661,17 @@ def DoPresubmitChecks(change_info,
"""
presubmit_files = ListRelevantPresubmitFiles(change_info.FileList())
if not presubmit_files and verbose:
output_stream.write("Warning, no presubmit.py found.")
output_stream.write("Warning, no presubmit.py found.\n")
results = []
executer = PresubmitExecuter(change_info, committing)
if default_presubmit:
if verbose:
output_stream.write("Running default presubmit script")
output_stream.write("Running default presubmit script.\n")
results += executer.ExecPresubmitScript(default_presubmit, 'PRESUBMIT.py')
for filename in presubmit_files:
filename = os.path.abspath(filename)
if verbose:
output_stream.write("Running %s" % filename)
output_stream.write("Running %s\n" % filename)
# Accept CRLF presubmit script.
presubmit_script = gcl.ReadFile(filename, 'rU')
results += executer.ExecPresubmitScript(presubmit_script, filename)
......
......@@ -366,6 +366,8 @@ class PresubmitUnittest(PresubmitTestsBase):
def CheckChangeOnUpload(input_api, output_api):
print 'This is a test'
return [output_api.PresubmitError("!!")]
def CheckChangeOnCommit(input_api, output_api):
raise Exception("Test error")
"""
def MockReadFile(dummy):
return ''
......@@ -394,6 +396,45 @@ def CheckChangeOnUpload(input_api, output_api):
affected_files_and_dirs = change.AffectedFiles(include_dirs=True)
self.failUnless(len(affected_files_and_dirs) == 2)
def testTags(self):
DEFAULT_SCRIPT = """
def CheckChangeOnUpload(input_api, output_api):
if input_api.change.tags['BUG'] != 'boo':
return [output_api.PresubmitError('Tag parsing failed. 1')]
if input_api.change.tags['STORY'] != 'http://tracker.com/42':
return [output_api.PresubmitError('Tag parsing failed. 2')]
if 'TEST' in input_api.change.tags:
return [output_api.PresubmitError('Tag parsing failed. 3')]
if input_api.change.DescriptionText() != 'Blah Blah':
return [output_api.PresubmitError('Tag parsing failed. 4 ' +
input_api.change.DescriptionText())]
if (input_api.change.FullDescriptionText() !=
'Blah Blah\\n\\nSTORY=http://tracker.com/42\\nBUG=boo\\n'):
return [output_api.PresubmitError('Tag parsing failed. 5 ' +
input_api.change.FullDescriptionText())]
return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])]
def CheckChangeOnCommit(input_api, output_api):
raise Exception("Test error")
"""
def MockReadFile(dummy):
return ''
gcl.ReadFile = MockReadFile
def MockIsFile(dummy):
return False
os.path.isfile = MockIsFile
change = gcl.ChangeInfo(
name='foo',
description="Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n")
output = StringIO.StringIO()
input = StringIO.StringIO('y\n')
self.failUnless(presubmit.DoPresubmitChecks(change, False, True, output,
input, DEFAULT_SCRIPT))
self.assertEquals(output.getvalue(),
('Warning, no presubmit.py found.\n'
'Running default presubmit script.\n\n'
'** Presubmit Messages **\n\n'
'http://tracker.com/42\n\n'))
class InputApiUnittest(PresubmitTestsBase):
"""Tests presubmit.InputApi."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment