Commit 02e9e068 authored by maruel@chromium.org's avatar maruel@chromium.org

When I copied presubmit_unittest.py, I picked the old one. Fix with the latest...

When I copied presubmit_unittest.py, I picked the old one. Fix with the latest version from the "old" depot_tools.

TBR=nsylvain
Review URL: http://codereview.chromium.org/100055

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@14635 0039d316-1c4b-4281-b951-d872f2087c98
parent 9af21a00
...@@ -60,18 +60,16 @@ class PresubmitTestsBase(unittest.TestCase): ...@@ -60,18 +60,16 @@ class PresubmitTestsBase(unittest.TestCase):
self.fail('Should not attempt to read file that is directory.') self.fail('Should not attempt to read file that is directory.')
elif path.endswith('PRESUBMIT.py'): elif path.endswith('PRESUBMIT.py'):
# used in testDoPresubmitChecks # used in testDoPresubmitChecks
return """ return ('def CheckChangeOnUpload(input_api, output_api):\n'
def CheckChangeOnUpload(input_api, output_api): ' if not input_api.change.NOSUCHKEY:\n'
if not input_api.change.NOSUCHKEY: ' return [output_api.PresubmitError("!!")]\n'
return [output_api.PresubmitError("!!")] ' elif not input_api.change.REALLYNOSUCHKEY:\n'
elif not input_api.change.REALLYNOSUCHKEY: ' return [output_api.PresubmitPromptWarning("??")]\n'
return [output_api.PresubmitPromptWarning("??")] ' elif not input_api.change.REALLYABSOLUTELYNOSUCHKEY:\n'
elif not input_api.change.REALLYABSOLUTELYNOSUCHKEY: ' return [output_api.PresubmitPromptWarning("??"),\n'
return [output_api.PresubmitPromptWarning("??"), ' output_api.PresubmitError("XX!!XX")]\n'
output_api.PresubmitError("XX!!XX")] ' else:\n'
else: ' return ()')
return ()
"""
else: else:
return 'one:%s\r\ntwo:%s' % (path, path) return 'one:%s\r\ntwo:%s' % (path, path)
gcl.ReadFile = MockReadFile gcl.ReadFile = MockReadFile
...@@ -300,9 +298,8 @@ class PresubmitUnittest(PresubmitTestsBase): ...@@ -300,9 +298,8 @@ class PresubmitUnittest(PresubmitTestsBase):
output = StringIO.StringIO() output = StringIO.StringIO()
input = StringIO.StringIO('y\n') input = StringIO.StringIO('y\n')
self.failIf(presubmit.DoPresubmitChecks(ci, False, False, output, input, self.failIf(presubmit.DoPresubmitChecks(ci, False, False, output, input))
None)) self.failUnless(output.getvalue().count('!!'))
self.assertEqual(output.getvalue().count('!!'), 2)
def testDoPresubmitChecksPromptsAfterWarnings(self): def testDoPresubmitChecksPromptsAfterWarnings(self):
description_lines = ('Hello there', description_lines = ('Hello there',
...@@ -318,9 +315,8 @@ class PresubmitUnittest(PresubmitTestsBase): ...@@ -318,9 +315,8 @@ class PresubmitUnittest(PresubmitTestsBase):
output = StringIO.StringIO() output = StringIO.StringIO()
input = StringIO.StringIO('n\n') # say no to the warning input = StringIO.StringIO('n\n') # say no to the warning
self.failIf(presubmit.DoPresubmitChecks(ci, False, False, output, input, self.failIf(presubmit.DoPresubmitChecks(ci, False, False, output, input))
None)) self.failUnless(output.getvalue().count('??'))
self.assertEqual(output.getvalue().count('??'), 2)
output = StringIO.StringIO() output = StringIO.StringIO()
input = StringIO.StringIO('y\n') # say yes to the warning input = StringIO.StringIO('y\n') # say yes to the warning
...@@ -329,8 +325,7 @@ class PresubmitUnittest(PresubmitTestsBase): ...@@ -329,8 +325,7 @@ class PresubmitUnittest(PresubmitTestsBase):
False, False,
False, False,
output, output,
input, input))
None))
self.failUnless(output.getvalue().count('??')) self.failUnless(output.getvalue().count('??'))
def testDoPresubmitChecksNoWarningPromptIfErrors(self): def testDoPresubmitChecksNoWarningPromptIfErrors(self):
...@@ -348,38 +343,10 @@ class PresubmitUnittest(PresubmitTestsBase): ...@@ -348,38 +343,10 @@ class PresubmitUnittest(PresubmitTestsBase):
output = StringIO.StringIO() output = StringIO.StringIO()
input = StringIO.StringIO() # should be unused input = StringIO.StringIO() # should be unused
self.failIf(presubmit.DoPresubmitChecks(ci, False, False, output, input, self.failIf(presubmit.DoPresubmitChecks(ci, False, False, output, input))
None)) self.failUnless(output.getvalue().count('??'))
self.assertEqual(output.getvalue().count('??'), 2) self.failUnless(output.getvalue().count('XX!!XX'))
self.assertEqual(output.getvalue().count('XX!!XX'), 2) self.failIf(output.getvalue().count('(y/N)'))
self.assertEqual(output.getvalue().count('(y/N)'), 0)
def testDoDefaultPresubmitChecks(self):
description_lines = ('Hello there',
'this is a change',
'STORY=http://tracker/123')
files = [
['A', 'haspresubmit\\blat.cc'],
]
ci = gcl.ChangeInfo(name='mychange',
description='\n'.join(description_lines),
files=files)
output = StringIO.StringIO()
input = StringIO.StringIO('y\n')
DEFAULT_SCRIPT = """
def CheckChangeOnUpload(input_api, output_api):
return [output_api.PresubmitError("!!")]
"""
def MockReadFile(dummy):
return ''
gcl.ReadFile = MockReadFile
def MockIsFile(dummy):
return False
os.path.isfile = MockIsFile
self.failUnless(presubmit.DoPresubmitChecks(ci, False, False, output, input,
DEFAULT_SCRIPT))
self.failIf(output.getvalue().count('!!') == 1)
def testDirectoryHandling(self): def testDirectoryHandling(self):
files = [ files = [
......
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