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

Unified Diff: tests/presubmit_unittest.py

Issue 113859: Add a unit test for input_api.change.tags. (Closed)
Patch Set: Will I get it right?? Created 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « 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 88b2f71b74241156609d5dfba172294a9e96abae..f50a0c59bdf17b54eddaf3f9e24007109783d8f9 100755
--- a/tests/presubmit_unittest.py
+++ b/tests/presubmit_unittest.py
@@ -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."""
« 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