Remove gcl.ChangeInfo dependency in presubmit_support.py.

TEST=none
BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@18309 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 16 years ago
parent 07f0186d08
commit 4ff922af46

@ -173,7 +173,7 @@ class InputApi(object):
"""Builds an InputApi object. """Builds an InputApi object.
Args: Args:
change: A presubmit.GclChange object. change: A presubmit.Change object.
presubmit_path: The path to the presubmit script being processed. presubmit_path: The path to the presubmit script being processed.
is_committing: True if the change is about to be committed. is_committing: True if the change is about to be committed.
""" """
@ -360,7 +360,7 @@ class AffectedFile(object):
def __init__(self, path, action, repository_root=''): def __init__(self, path, action, repository_root=''):
self._path = path self._path = path
self._action = action self._action = action
self._repository_root = repository_root self._local_root = repository_root
self._is_directory = None self._is_directory = None
self._properties = {} self._properties = {}
self.scm = '' self.scm = ''
@ -380,7 +380,7 @@ class AffectedFile(object):
def AbsoluteLocalPath(self): def AbsoluteLocalPath(self):
"""Returns the absolute path of this file on the local disk. """Returns the absolute path of this file on the local disk.
""" """
return normpath(os.path.join(self._repository_root, self.LocalPath())) return normpath(os.path.join(self._local_root, self.LocalPath()))
def IsDirectory(self): def IsDirectory(self):
"""Returns true if this object is a directory.""" """Returns true if this object is a directory."""
@ -489,7 +489,7 @@ class SvnAffectedFile(AffectedFile):
return self._is_text_file return self._is_text_file
class GclChange(object): class Change(object):
"""Describe a change. """Describe a change.
Used directly by the presubmit scripts to query the current change being Used directly by the presubmit scripts to query the current change being
@ -500,24 +500,27 @@ class GclChange(object):
self.KEY: equivalent to tags['KEY'] self.KEY: equivalent to tags['KEY']
""" """
_AFFECTED_FILES = AffectedFile
# Matches key/value (or "tag") lines in changelist descriptions. # Matches key/value (or "tag") lines in changelist descriptions.
_tag_line_re = re.compile( _TAG_LINE_RE = re.compile(
'^\s*(?P<key>[A-Z][A-Z_0-9]*)\s*=\s*(?P<value>.*?)\s*$') '^\s*(?P<key>[A-Z][A-Z_0-9]*)\s*=\s*(?P<value>.*?)\s*$')
def __init__(self, change_info): def __init__(self, name, description, local_root, files, issue, patchset):
# Do not keep a reference to the original change_info. if files is None:
self._name = change_info.name files = []
self._full_description = change_info.description self._name = name
self._repository_root = change_info.GetLocalRoot() self._full_description = description
self.issue = change_info.issue self._local_root = local_root
self.patchset = change_info.patchset self.issue = issue
self.patchset = patchset
# From the description text, build up a dictionary of key/value pairs # From the description text, build up a dictionary of key/value pairs
# plus the description minus all key/value or "tag" lines. # plus the description minus all key/value or "tag" lines.
self._description_without_tags = [] self._description_without_tags = []
self.tags = {} self.tags = {}
for line in self._full_description.splitlines(): for line in self._full_description.splitlines():
m = self._tag_line_re.match(line) m = self._TAG_LINE_RE.match(line)
if m: if m:
self.tags[m.group('key')] = m.group('value') self.tags[m.group('key')] = m.group('value')
else: else:
@ -528,8 +531,8 @@ class GclChange(object):
self._description_without_tags = self._description_without_tags.rstrip() self._description_without_tags = self._description_without_tags.rstrip()
self._affected_files = [ self._affected_files = [
SvnAffectedFile(info[1], info[0].strip(), self._repository_root) self._AFFECTED_FILES(info[1], info[0].strip(), self._local_root)
for info in change_info.GetFiles() for info in files
] ]
def Name(self): def Name(self):
@ -553,7 +556,7 @@ class GclChange(object):
"""Returns the repository (checkout) root directory for this change, """Returns the repository (checkout) root directory for this change,
as an absolute path. as an absolute path.
""" """
return self._repository_root return self._local_root
def __getattr__(self, attr): def __getattr__(self, attr):
"""Return tags directly as attributes on the object.""" """Return tags directly as attributes on the object."""
@ -622,6 +625,10 @@ class GclChange(object):
self.AffectedFiles(include_deletes=False))) self.AffectedFiles(include_deletes=False)))
class SvnChange(Change):
_AFFECTED_FILES = SvnAffectedFile
def ListRelevantPresubmitFiles(files, root): def ListRelevantPresubmitFiles(files, root):
"""Finds all presubmit files that apply to a given set of source files. """Finds all presubmit files that apply to a given set of source files.
@ -648,14 +655,13 @@ def ListRelevantPresubmitFiles(files, root):
class PresubmitExecuter(object): class PresubmitExecuter(object):
def __init__(self, change_info, committing): def __init__(self, change, committing):
""" """
Args: Args:
change_info: The gcl.ChangeInfo object for the change. change: The Change object.
committing: True if 'gcl commit' is running, False if 'gcl upload' is. committing: True if 'gcl commit' is running, False if 'gcl upload' is.
""" """
# TODO(maruel): Determine the SCM. self.change = change
self.change = GclChange(change_info)
self.committing = committing self.committing = committing
def ExecPresubmitScript(self, script_text, presubmit_path): def ExecPresubmitScript(self, script_text, presubmit_path):
@ -697,7 +703,7 @@ class PresubmitExecuter(object):
return result return result
def DoPresubmitChecks(change_info, def DoPresubmitChecks(change,
committing, committing,
verbose, verbose,
output_stream, output_stream,
@ -714,7 +720,7 @@ def DoPresubmitChecks(change_info,
when needed. when needed.
Args: Args:
change_info: The gcl.ChangeInfo object for the change. change: The Change object.
committing: True if 'gcl commit' is running, False if 'gcl upload' is. committing: True if 'gcl commit' is running, False if 'gcl upload' is.
verbose: Prints debug info. verbose: Prints debug info.
output_stream: A stream to write output from presubmit tests to. output_stream: A stream to write output from presubmit tests to.
@ -725,16 +731,16 @@ def DoPresubmitChecks(change_info,
Return: Return:
True if execution can continue, False if not. True if execution can continue, False if not.
""" """
presubmit_files = ListRelevantPresubmitFiles(change_info.GetFileNames(), presubmit_files = ListRelevantPresubmitFiles(change.AbsoluteLocalPaths(True),
change_info.GetLocalRoot()) change.RepositoryRoot())
if not presubmit_files and verbose: if not presubmit_files and verbose:
output_stream.write("Warning, no presubmit.py found.\n") output_stream.write("Warning, no presubmit.py found.\n")
results = [] results = []
executer = PresubmitExecuter(change_info, committing) executer = PresubmitExecuter(change, committing)
if default_presubmit: if default_presubmit:
if verbose: if verbose:
output_stream.write("Running default presubmit script.\n") output_stream.write("Running default presubmit script.\n")
fake_path = os.path.join(change_info.GetLocalRoot(), 'PRESUBMIT.py') fake_path = os.path.join(change.RepositoryRoot(), 'PRESUBMIT.py')
results += executer.ExecPresubmitScript(default_presubmit, fake_path) results += executer.ExecPresubmitScript(default_presubmit, fake_path)
for filename in presubmit_files: for filename in presubmit_files:
filename = os.path.abspath(filename) filename = os.path.abspath(filename)
@ -805,18 +811,33 @@ def Main(argv):
help="Act recursively") help="Act recursively")
parser.add_option("-v", "--verbose", action="store_true", parser.add_option("-v", "--verbose", action="store_true",
help="Verbose output") help="Verbose output")
parser.add_option("--files", default='')
parser.add_option("--name", default='no name')
parser.add_option("--description", default='')
parser.add_option("--issue", type='int', default=0)
parser.add_option("--patchset", type='int', default=0)
parser.add_options("--root", default='')
parser.add_options("--default_presubmit", default='')
parser.add_options("--may_prompt", action='store_true')
options, args = parser.parse_args(argv[1:]) options, args = parser.parse_args(argv[1:])
files = ParseFiles(args, options.recursive) if not options.files:
options.files = ParseFiles(args, options.recursive)
if not options.root:
options.root = gcl.GetRepositoryRoot()
if options.verbose: if options.verbose:
print "Found %d files." % len(files) print "Found %d files." % len(files)
return not DoPresubmitChecks(gcl.ChangeInfo('No name', 0, 0, '', files, return not DoPresubmitChecks(SvnChange(options.name,
gcl.GetRepositoryRoot()), options.description,
options.root,
options.files,
options.issue,
options.patchset),
options.commit, options.commit,
options.verbose, options.verbose,
sys.stdout, sys.stdout,
sys.stdin, sys.stdin,
None, options.default_presubmit,
False) options.may_prompt)
if __name__ == '__main__': if __name__ == '__main__':

@ -56,15 +56,6 @@ def CheckChangeOnUpload(input_api, output_api):
self.mox.StubOutWithMock(presubmit.gclient, 'CaptureSVNInfo') self.mox.StubOutWithMock(presubmit.gclient, 'CaptureSVNInfo')
self.mox.StubOutWithMock(presubmit.gcl, 'GetSVNFileProperty') self.mox.StubOutWithMock(presubmit.gcl, 'GetSVNFileProperty')
self.mox.StubOutWithMock(presubmit.gcl, 'ReadFile') self.mox.StubOutWithMock(presubmit.gcl, 'ReadFile')
# Stub any non-getter function in gcl.ChangeInfo.
to_skip = lambda x: not x.startswith('_') and not x.startswith('Get')
for member in filter(to_skip, dir(presubmit.gcl.ChangeInfo)):
self.mox.StubOutWithMock(presubmit.gcl.ChangeInfo, member)
def MakeChangeInfo(self, name, issue, patchset, description, files):
ci = presubmit.gcl.ChangeInfo(name, issue, patchset, description, files,
self.fake_root_dir)
return ci
class PresubmitUnittest(PresubmitTestsBase): class PresubmitUnittest(PresubmitTestsBase):
@ -72,10 +63,10 @@ class PresubmitUnittest(PresubmitTestsBase):
def testMembersChanged(self): def testMembersChanged(self):
self.mox.ReplayAll() self.mox.ReplayAll()
members = [ members = [
'AffectedFile', 'DoPresubmitChecks', 'GclChange', 'InputApi', 'AffectedFile', 'Change', 'DoPresubmitChecks', 'InputApi',
'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException', 'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException',
'OutputApi', 'ParseFiles', 'PresubmitExecuter', 'ScanSubDirs', 'OutputApi', 'ParseFiles', 'PresubmitExecuter', 'ScanSubDirs',
'SvnAffectedFile', 'SvnAffectedFile', 'SvnChange',
'cPickle', 'cStringIO', 'exceptions', 'cPickle', 'cStringIO', 'exceptions',
'fnmatch', 'gcl', 'gclient', 'glob', 'logging', 'marshal', 'normpath', 'fnmatch', 'gcl', 'gclient', 'glob', 'logging', 'marshal', 'normpath',
'optparse', 'optparse',
@ -107,7 +98,6 @@ class PresubmitUnittest(PresubmitTestsBase):
'PRESUBMIT.py')).AndReturn(False) 'PRESUBMIT.py')).AndReturn(False)
presubmit.os.path.isfile(join(self.fake_root_dir, 'moo', 'mat', 'gat', presubmit.os.path.isfile(join(self.fake_root_dir, 'moo', 'mat', 'gat',
'PRESUBMIT.py')).AndReturn(False) 'PRESUBMIT.py')).AndReturn(False)
#isfile(join('moo', 'PRESUBMIT.py')).AndReturn(False)
self.mox.ReplayAll() self.mox.ReplayAll()
presubmit_files = presubmit.ListRelevantPresubmitFiles(files, presubmit_files = presubmit.ListRelevantPresubmitFiles(files,
@ -122,7 +112,7 @@ class PresubmitUnittest(PresubmitTestsBase):
def testTagLineRe(self): def testTagLineRe(self):
self.mox.ReplayAll() self.mox.ReplayAll()
m = presubmit.GclChange._tag_line_re.match(' BUG =1223, 1445 \t') m = presubmit.Change._TAG_LINE_RE.match(' BUG =1223, 1445 \t')
self.failUnless(m) self.failUnless(m)
self.failUnlessEqual(m.group('key'), 'BUG') self.failUnlessEqual(m.group('key'), 'BUG')
self.failUnlessEqual(m.group('value'), '1223, 1445') self.failUnlessEqual(m.group('value'), '1223, 1445')
@ -170,12 +160,10 @@ class PresubmitUnittest(PresubmitTestsBase):
{'URL': 'svn:/foo/boo/flap.h'}) {'URL': 'svn:/foo/boo/flap.h'})
presubmit.gcl.ReadFile(blat).AndReturn('boo!\nahh?') presubmit.gcl.ReadFile(blat).AndReturn('boo!\nahh?')
presubmit.gcl.ReadFile(notfound).AndReturn('look!\nthere?') presubmit.gcl.ReadFile(notfound).AndReturn('look!\nthere?')
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.GclChange(ci) change = presubmit.SvnChange('mychange', '\n'.join(description_lines),
self.fake_root_dir, files, 0, 0)
self.failUnless(change.Name() == 'mychange') self.failUnless(change.Name() == 'mychange')
self.failUnless(change.DescriptionText() == self.failUnless(change.DescriptionText() ==
'Hello there\nthis is a change\nand some more regular text') 'Hello there\nthis is a change\nand some more regular text')
@ -184,6 +172,7 @@ class PresubmitUnittest(PresubmitTestsBase):
self.failUnless(change.BUG == '123') self.failUnless(change.BUG == '123')
self.failUnless(change.STORY == 'http://foo/') self.failUnless(change.STORY == 'http://foo/')
self.failUnless(change.BLEH == None)
self.failUnless(len(change.AffectedFiles()) == 4) self.failUnless(len(change.AffectedFiles()) == 4)
self.failUnless(len(change.AffectedFiles(include_dirs=True)) == 5) self.failUnless(len(change.AffectedFiles(include_dirs=True)) == 5)
@ -237,11 +226,11 @@ class PresubmitUnittest(PresubmitTestsBase):
['A', 'foo\\blat.cc'], ['A', 'foo\\blat.cc'],
] ]
fake_presubmit = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py') fake_presubmit = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py')
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
self.mox.ReplayAll() self.mox.ReplayAll()
executer = presubmit.PresubmitExecuter(ci, False) change = presubmit.Change('mychange', '\n'.join(description_lines),
self.fake_root_dir, files, 0, 0)
executer = presubmit.PresubmitExecuter(change, False)
self.failIf(executer.ExecPresubmitScript('', fake_presubmit)) self.failIf(executer.ExecPresubmitScript('', fake_presubmit))
# No error if no on-upload entry point # No error if no on-upload entry point
self.failIf(executer.ExecPresubmitScript( self.failIf(executer.ExecPresubmitScript(
@ -250,7 +239,7 @@ class PresubmitUnittest(PresubmitTestsBase):
fake_presubmit fake_presubmit
)) ))
executer = presubmit.PresubmitExecuter(ci, True) executer = presubmit.PresubmitExecuter(change, True)
# No error if no on-commit entry point # No error if no on-commit entry point
self.failIf(executer.ExecPresubmitScript( self.failIf(executer.ExecPresubmitScript(
('def CheckChangeOnUpload(input_api, output_api):\n' ('def CheckChangeOnUpload(input_api, output_api):\n'
@ -304,14 +293,13 @@ class PresubmitUnittest(PresubmitTestsBase):
'rU').AndReturn(self.presubmit_text) 'rU').AndReturn(self.presubmit_text)
presubmit.gcl.ReadFile(haspresubmit_path, presubmit.gcl.ReadFile(haspresubmit_path,
'rU').AndReturn(self.presubmit_text) 'rU').AndReturn(self.presubmit_text)
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
self.mox.ReplayAll() self.mox.ReplayAll()
output = StringIO.StringIO() output = StringIO.StringIO()
input = StringIO.StringIO('y\n') input = StringIO.StringIO('y\n')
change = presubmit.Change('mychange', '\n'.join(description_lines),
self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, self.fake_root_dir, files, 0, 0)
self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input,
None, False)) None, False))
self.assertEqual(output.getvalue().count('!!'), 2) self.assertEqual(output.getvalue().count('!!'), 2)
@ -325,8 +313,6 @@ class PresubmitUnittest(PresubmitTestsBase):
] ]
presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py') presubmit_path = join(self.fake_root_dir, 'PRESUBMIT.py')
haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py') haspresubmit_path = join(self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py')
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
for i in range(2): for i in range(2):
presubmit.os.path.isfile(presubmit_path).AndReturn(True) presubmit.os.path.isfile(presubmit_path).AndReturn(True)
presubmit.os.path.isfile(haspresubmit_path).AndReturn(True) presubmit.os.path.isfile(haspresubmit_path).AndReturn(True)
@ -338,14 +324,16 @@ 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, True, output, input, change = presubmit.Change('mychange', '\n'.join(description_lines),
self.fake_root_dir, files, 0, 0)
self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input,
None, True)) None, True))
self.assertEqual(output.getvalue().count('??'), 2) 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
self.failUnless(presubmit.DoPresubmitChecks(ci, False, True, output, input, self.failUnless(presubmit.DoPresubmitChecks(change, False, True, output,
None, True)) input, None, True))
self.assertEquals(output.getvalue().count('??'), 2) self.assertEquals(output.getvalue().count('??'), 2)
def testDoPresubmitChecksNoWarningPromptIfErrors(self): def testDoPresubmitChecksNoWarningPromptIfErrors(self):
@ -365,13 +353,13 @@ class PresubmitUnittest(PresubmitTestsBase):
presubmit.gcl.ReadFile(presubmit_path, 'rU').AndReturn(self.presubmit_text) presubmit.gcl.ReadFile(presubmit_path, 'rU').AndReturn(self.presubmit_text)
presubmit.gcl.ReadFile(haspresubmit_path, 'rU').AndReturn( presubmit.gcl.ReadFile(haspresubmit_path, 'rU').AndReturn(
self.presubmit_text) self.presubmit_text)
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
self.mox.ReplayAll() self.mox.ReplayAll()
output = StringIO.StringIO() output = StringIO.StringIO()
input = StringIO.StringIO() # should be unused input = StringIO.StringIO() # should be unused
self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, change = presubmit.Change('mychange', '\n'.join(description_lines),
self.fake_root_dir, files, 0, 0)
self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input,
None, False)) None, False))
self.assertEqual(output.getvalue().count('??'), 2) self.assertEqual(output.getvalue().count('??'), 2)
self.assertEqual(output.getvalue().count('XX!!XX'), 2) self.assertEqual(output.getvalue().count('XX!!XX'), 2)
@ -396,14 +384,14 @@ def CheckChangeOnCommit(input_api, output_api):
presubmit.os.path.isfile(join(self.fake_root_dir, presubmit.os.path.isfile(join(self.fake_root_dir,
'haspresubmit', 'haspresubmit',
'PRESUBMIT.py')).AndReturn(False) 'PRESUBMIT.py')).AndReturn(False)
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
self.mox.ReplayAll() self.mox.ReplayAll()
output = StringIO.StringIO() output = StringIO.StringIO()
input = StringIO.StringIO('y\n') input = StringIO.StringIO('y\n')
# Always fail. # Always fail.
self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, change = presubmit.Change('mychange', '\n'.join(description_lines),
self.fake_root_dir, files, 0, 0)
self.failIf(presubmit.DoPresubmitChecks(change, False, True, output, input,
DEFAULT_SCRIPT, False)) DEFAULT_SCRIPT, False))
self.assertEquals(output.getvalue().count('!!'), 1) self.assertEquals(output.getvalue().count('!!'), 1)
@ -418,10 +406,10 @@ def CheckChangeOnCommit(input_api, output_api):
presubmit.os.path.isdir(isdir).AndReturn(True) presubmit.os.path.isdir(isdir).AndReturn(True)
presubmit.os.path.exists(blat).AndReturn(True) presubmit.os.path.exists(blat).AndReturn(True)
presubmit.os.path.isdir(blat).AndReturn(False) presubmit.os.path.isdir(blat).AndReturn(False)
ci = self.MakeChangeInfo('mychange', 0, 0, 'foo', files)
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.GclChange(ci) change = presubmit.Change('mychange', 'foo', self.fake_root_dir, files,
0, 0)
affected_files = change.AffectedFiles(include_dirs=False) affected_files = change.AffectedFiles(include_dirs=False)
self.failUnless(len(affected_files) == 1) self.failUnless(len(affected_files) == 1)
self.failUnless(affected_files[0].LocalPath().endswith('blat.cc')) self.failUnless(affected_files[0].LocalPath().endswith('blat.cc'))
@ -459,14 +447,14 @@ def CheckChangeOnUpload(input_api, output_api):
def CheckChangeOnCommit(input_api, output_api): def CheckChangeOnCommit(input_api, output_api):
raise Exception("Test error") raise Exception("Test error")
""" """
ci = self.MakeChangeInfo(
'foo', 0, 0, "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n",
None)
self.mox.ReplayAll() self.mox.ReplayAll()
output = StringIO.StringIO() output = StringIO.StringIO()
input = StringIO.StringIO('y\n') input = StringIO.StringIO('y\n')
self.failUnless(presubmit.DoPresubmitChecks(ci, False, True, output, change = presubmit.Change(
'foo', "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n",
self.fake_root_dir, None, 0, 0)
self.failUnless(presubmit.DoPresubmitChecks(change, False, True, output,
input, DEFAULT_SCRIPT, False)) input, DEFAULT_SCRIPT, False))
self.assertEquals(output.getvalue(), self.assertEquals(output.getvalue(),
('Warning, no presubmit.py found.\n' ('Warning, no presubmit.py found.\n'
@ -572,11 +560,10 @@ class InputApiUnittest(PresubmitTestsBase):
).AndReturn(None) ).AndReturn(None)
presubmit.gcl.ReadFile(blat).AndReturn('whatever\ncookie') presubmit.gcl.ReadFile(blat).AndReturn('whatever\ncookie')
presubmit.gcl.ReadFile(another).AndReturn('whatever\ncookie2') presubmit.gcl.ReadFile(another).AndReturn('whatever\ncookie2')
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.GclChange(ci) change = presubmit.SvnChange('mychange', '\n'.join(description_lines),
self.fake_root_dir, files, 0, 0)
input_api = presubmit.InputApi(change, input_api = presubmit.InputApi(change,
join(self.fake_root_dir, 'foo', join(self.fake_root_dir, 'foo',
'PRESUBMIT.py'), 'PRESUBMIT.py'),
@ -685,10 +672,10 @@ class InputApiUnittest(PresubmitTestsBase):
presubmit.os.path.exists(item).AndReturn(True) presubmit.os.path.exists(item).AndReturn(True)
presubmit.os.path.isdir(item).AndReturn(False) presubmit.os.path.isdir(item).AndReturn(False)
presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None) presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None)
ci = self.MakeChangeInfo('mychange', 0, 0, '', files)
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.GclChange(ci) change = presubmit.SvnChange('mychange', '', self.fake_root_dir, files, 0,
0)
input_api = presubmit.InputApi(change, input_api = presubmit.InputApi(change,
presubmit.os.path.join(self.fake_root_dir, presubmit.os.path.join(self.fake_root_dir,
'PRESUBMIT.py'), 'PRESUBMIT.py'),
@ -707,10 +694,10 @@ class InputApiUnittest(PresubmitTestsBase):
presubmit.os.path.exists(item).AndReturn(True) presubmit.os.path.exists(item).AndReturn(True)
presubmit.os.path.isdir(item).AndReturn(False) presubmit.os.path.isdir(item).AndReturn(False)
presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None) presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None)
ci = self.MakeChangeInfo('mychange', 0, 0, '', files)
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.GclChange(ci) change = presubmit.SvnChange('mychange', '', self.fake_root_dir, files, 0,
0)
input_api = presubmit.InputApi(change, './PRESUBMIT.py', False) input_api = presubmit.InputApi(change, './PRESUBMIT.py', False)
# Sample usage of overiding the default white and black lists. # Sample usage of overiding the default white and black lists.
got_files = input_api.AffectedSourceFiles( got_files = input_api.AffectedSourceFiles(
@ -732,12 +719,9 @@ class InputApiUnittest(PresubmitTestsBase):
['A', join('isdir', 'blat.cc')], ['A', join('isdir', 'blat.cc')],
['M', join('elsewhere', 'ouf.cc')], ['M', join('elsewhere', 'ouf.cc')],
] ]
ci = self.MakeChangeInfo('mychange', 0, 0, '', files)
self.mox.ReplayAll() self.mox.ReplayAll()
# It doesn't make sense on non-Windows platform. This is somewhat hacky, change = presubmit.Change('mychange', '', self.fake_root_dir, files, 0, 0)
# but it is needed since we can't just use os.path.join('c:', 'temp').
change = presubmit.GclChange(ci)
affected_files = change.AffectedFiles(include_dirs=True) affected_files = change.AffectedFiles(include_dirs=True)
# Local paths should remain the same # Local paths should remain the same
self.assertEquals(affected_files[0].LocalPath(), normpath('isdir')) self.assertEquals(affected_files[0].LocalPath(), normpath('isdir'))
@ -766,54 +750,53 @@ class InputApiUnittest(PresubmitTestsBase):
def testDeprecated(self): def testDeprecated(self):
presubmit.warnings.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), presubmit.warnings.warn(mox.IgnoreArg(), category=mox.IgnoreArg(),
stacklevel=2) stacklevel=2)
ci = self.MakeChangeInfo('mychange', 0, 0, 'Bleh\n', [])
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.GclChange(ci) change = presubmit.Change('mychange', '', self.fake_root_dir, [], 0, 0)
api = presubmit.InputApi( api = presubmit.InputApi(
change, change,
presubmit.os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True) presubmit.os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True)
api.AffectedTextFiles(include_deletes=False) api.AffectedTextFiles(include_deletes=False)
def testReadFileStringDenied(self): def testReadFileStringDenied(self):
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')])
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
0, 0)
input_api = presubmit.InputApi( input_api = presubmit.InputApi(
None, presubmit.os.path.join(self.fake_root_dir, '/p'), False) change, presubmit.os.path.join(self.fake_root_dir, '/p'), False)
input_api.change = presubmit.GclChange(ci)
self.assertRaises(IOError, input_api.ReadFile, 'boo', 'x') self.assertRaises(IOError, input_api.ReadFile, 'boo', 'x')
def testReadFileStringAccepted(self): def testReadFileStringAccepted(self):
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')])
path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo') path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo')
presubmit.gcl.ReadFile(path, 'x').AndReturn(None) presubmit.gcl.ReadFile(path, 'x').AndReturn(None)
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
0, 0)
input_api = presubmit.InputApi( input_api = presubmit.InputApi(
None, presubmit.os.path.join(self.fake_root_dir, '/p'), False) change, presubmit.os.path.join(self.fake_root_dir, '/p'), False)
input_api.change = presubmit.GclChange(ci)
input_api.ReadFile(path, 'x') input_api.ReadFile(path, 'x')
def testReadFileAffectedFileDenied(self): def testReadFileAffectedFileDenied(self):
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')])
file = presubmit.AffectedFile('boo', 'M', 'Unrelated') file = presubmit.AffectedFile('boo', 'M', 'Unrelated')
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
0, 0)
input_api = presubmit.InputApi( input_api = presubmit.InputApi(
None, presubmit.os.path.join(self.fake_root_dir, '/p'), False) change, presubmit.os.path.join(self.fake_root_dir, '/p'), False)
input_api.change = presubmit.GclChange(ci)
self.assertRaises(IOError, input_api.ReadFile, file, 'x') self.assertRaises(IOError, input_api.ReadFile, file, 'x')
def testReadFileAffectedFileAccepted(self): def testReadFileAffectedFileAccepted(self):
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')])
file = presubmit.AffectedFile('AA/boo', 'M', self.fake_root_dir) file = presubmit.AffectedFile('AA/boo', 'M', self.fake_root_dir)
presubmit.gcl.ReadFile(file.AbsoluteLocalPath(), 'x').AndReturn(None) presubmit.gcl.ReadFile(file.AbsoluteLocalPath(), 'x').AndReturn(None)
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
0, 0)
input_api = presubmit.InputApi( input_api = presubmit.InputApi(
None, presubmit.os.path.join(self.fake_root_dir, '/p'), False) change, presubmit.os.path.join(self.fake_root_dir, '/p'), False)
input_api.change = presubmit.GclChange(ci)
input_api.ReadFile(file, 'x') input_api.ReadFile(file, 'x')
@ -960,10 +943,11 @@ class GclChangeUnittest(PresubmitTestsBase):
'issue', 'patchset', 'tags', 'issue', 'patchset', 'tags',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
ci = self.MakeChangeInfo('', 0, 0, '', [])
self.mox.ReplayAll() self.mox.ReplayAll()
self.compareMembers(presubmit.GclChange(ci), members) change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
0, 0)
self.compareMembers(change, members)
class CannedChecksUnittest(PresubmitTestsBase): class CannedChecksUnittest(PresubmitTestsBase):
@ -974,13 +958,15 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.mox.StubOutWithMock(presubmit_canned_checks, self.mox.StubOutWithMock(presubmit_canned_checks,
'_RunPythonUnitTests_LoadTests') '_RunPythonUnitTests_LoadTests')
def MockInputApi(self): def MockInputApi(self, change, committing):
input_api = self.mox.CreateMock(presubmit.InputApi) input_api = self.mox.CreateMock(presubmit.InputApi)
input_api.cStringIO = presubmit.cStringIO input_api.cStringIO = presubmit.cStringIO
input_api.re = presubmit.re input_api.re = presubmit.re
input_api.traceback = presubmit.traceback input_api.traceback = presubmit.traceback
input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2)
input_api.unittest = unittest input_api.unittest = unittest
input_api.change = change
input_api.is_committing = committing
return input_api return input_api
def testMembersChanged(self): def testMembersChanged(self):
@ -1001,16 +987,14 @@ class CannedChecksUnittest(PresubmitTestsBase):
def DescriptionTest(self, check, description1, description2, error_type, def DescriptionTest(self, check, description1, description2, error_type,
committing): committing):
input_api1 = self.MockInputApi() change1 = presubmit.Change('foo1', description1, self.fake_root_dir, None,
input_api1.is_committing = committing 0, 0)
ci1 = self.MakeChangeInfo('foo', 0, 0, description1, []) input_api1 = self.MockInputApi(change1, committing)
input_api2 = self.MockInputApi() change2 = presubmit.Change('foo2', description2, self.fake_root_dir, None,
input_api2.is_committing = committing 0, 0)
ci2 = self.MakeChangeInfo('foo', 0, 0, description2, []) input_api2 = self.MockInputApi(change2, committing)
self.mox.ReplayAll() self.mox.ReplayAll()
input_api1.change = presubmit.GclChange(ci1)
input_api2.change = presubmit.GclChange(ci2)
results1 = check(input_api1, presubmit.OutputApi) results1 = check(input_api1, presubmit.OutputApi)
self.assertEquals(results1, []) self.assertEquals(results1, [])
results2 = check(input_api2, presubmit.OutputApi) results2 = check(input_api2, presubmit.OutputApi)
@ -1018,8 +1002,9 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.assertEquals(results2[0].__class__, error_type) self.assertEquals(results2[0].__class__, error_type)
def ContentTest(self, check, content1, content2, error_type): def ContentTest(self, check, content1, content2, error_type):
input_api1 = self.MockInputApi() change1 = presubmit.Change('foo1', 'foo1\n', self.fake_root_dir, None,
ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n', []) 0, 0)
input_api1 = self.MockInputApi(change1, False)
affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
affected_file.LocalPath().AndReturn('foo.cc') affected_file.LocalPath().AndReturn('foo.cc')
output1 = [ output1 = [
@ -1028,8 +1013,9 @@ class CannedChecksUnittest(PresubmitTestsBase):
(affected_file, 23, 'ya'), (affected_file, 23, 'ya'),
] ]
input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1) input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1)
input_api2 = self.MockInputApi() change2 = presubmit.Change('foo2', 'foo2\n', self.fake_root_dir, None,
ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n', None) 0, 0)
input_api2 = self.MockInputApi(change2, False)
output2 = [ output2 = [
(affected_file, 42, 'yo, ' + content2), (affected_file, 42, 'yo, ' + content2),
(affected_file, 43, 'yer'), (affected_file, 43, 'yer'),
@ -1038,8 +1024,6 @@ class CannedChecksUnittest(PresubmitTestsBase):
input_api2.RightHandSideLines(mox.IgnoreArg()).AndReturn(output2) input_api2.RightHandSideLines(mox.IgnoreArg()).AndReturn(output2)
self.mox.ReplayAll() self.mox.ReplayAll()
input_api1.change = presubmit.GclChange(ci1)
input_api2.change = presubmit.GclChange(ci2)
results1 = check(input_api1, presubmit.OutputApi, None) results1 = check(input_api1, presubmit.OutputApi, None)
self.assertEquals(results1, []) self.assertEquals(results1, [])
results2 = check(input_api2, presubmit.OutputApi, None) results2 = check(input_api2, presubmit.OutputApi, None)
@ -1047,23 +1031,22 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.assertEquals(results2[0].__class__, error_type) self.assertEquals(results2[0].__class__, error_type)
def ReadFileTest(self, check, content1, content2, error_type): def ReadFileTest(self, check, content1, content2, error_type):
input_api1 = self.MockInputApi() self.mox.StubOutWithMock(presubmit.InputApi, 'ReadFile')
self.mox.StubOutWithMock(input_api1, 'ReadFile') change1 = presubmit.Change('foo1', 'foo1\n', self.fake_root_dir, None,
ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n', None) 0, 0)
input_api1 = self.MockInputApi(change1, False)
affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile) affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile)
input_api1.AffectedSourceFiles(None).AndReturn([affected_file1]) input_api1.AffectedSourceFiles(None).AndReturn([affected_file1])
input_api1.ReadFile(affected_file1, 'rb').AndReturn(content1) input_api1.ReadFile(affected_file1, 'rb').AndReturn(content1)
input_api2 = self.MockInputApi() change2 = presubmit.Change('foo2', 'foo2\n', self.fake_root_dir, None,
self.mox.StubOutWithMock(input_api2, 'ReadFile') 0, 0)
ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n', []) input_api2 = self.MockInputApi(change2, False)
affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile) affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile)
input_api2.AffectedSourceFiles(None).AndReturn([affected_file2]) input_api2.AffectedSourceFiles(None).AndReturn([affected_file2])
input_api2.ReadFile(affected_file2, 'rb').AndReturn(content2) input_api2.ReadFile(affected_file2, 'rb').AndReturn(content2)
affected_file2.LocalPath().AndReturn('bar.cc') affected_file2.LocalPath().AndReturn('bar.cc')
self.mox.ReplayAll() self.mox.ReplayAll()
input_api1.change = presubmit.GclChange(ci1)
input_api2.change = presubmit.GclChange(ci2)
results = check(input_api1, presubmit.OutputApi) results = check(input_api1, presubmit.OutputApi)
self.assertEquals(results, []) self.assertEquals(results, [])
results2 = check(input_api2, presubmit.OutputApi) results2 = check(input_api2, presubmit.OutputApi)
@ -1072,8 +1055,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
def SvnPropertyTest(self, check, property, value1, value2, committing, def SvnPropertyTest(self, check, property, value1, value2, committing,
error_type): error_type):
input_api1 = self.MockInputApi() input_api1 = self.MockInputApi(None, committing)
input_api1.is_committing = committing
files1 = [ files1 = [
presubmit.SvnAffectedFile('foo/bar.cc', 'A'), presubmit.SvnAffectedFile('foo/bar.cc', 'A'),
presubmit.SvnAffectedFile('foo.cc', 'M'), presubmit.SvnAffectedFile('foo.cc', 'M'),
@ -1083,8 +1065,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
property).AndReturn(value1) property).AndReturn(value1)
presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'),
property).AndReturn(value1) property).AndReturn(value1)
input_api2 = self.MockInputApi() input_api2 = self.MockInputApi(None, committing)
input_api2.is_committing = committing
files2 = [ files2 = [
presubmit.SvnAffectedFile('foo/bar.cc', 'A'), presubmit.SvnAffectedFile('foo/bar.cc', 'A'),
presubmit.SvnAffectedFile('foo.cc', 'M'), presubmit.SvnAffectedFile('foo.cc', 'M'),
@ -1199,8 +1180,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
presubmit.OutputApi.PresubmitNotifyResult) presubmit.OutputApi.PresubmitNotifyResult)
def testCannedCheckTreeIsOpenOpen(self): def testCannedCheckTreeIsOpenOpen(self):
input_api = self.MockInputApi() input_api = self.MockInputApi(None, True)
input_api.is_committing = True
connection = self.mox.CreateMockAnything() connection = self.mox.CreateMockAnything()
input_api.urllib2.urlopen('url_to_open').AndReturn(connection) input_api.urllib2.urlopen('url_to_open').AndReturn(connection)
connection.read().AndReturn('1') connection.read().AndReturn('1')
@ -1211,8 +1191,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.assertEquals(results, []) self.assertEquals(results, [])
def testCannedCheckTreeIsOpenClosed(self): def testCannedCheckTreeIsOpenClosed(self):
input_api = self.MockInputApi() input_api = self.MockInputApi(None, True)
input_api.is_committing = True
connection = self.mox.CreateMockAnything() connection = self.mox.CreateMockAnything()
input_api.urllib2.urlopen('url_to_closed').AndReturn(connection) input_api.urllib2.urlopen('url_to_closed').AndReturn(connection)
connection.read().AndReturn('0') connection.read().AndReturn('0')
@ -1225,20 +1204,19 @@ class CannedChecksUnittest(PresubmitTestsBase):
presubmit.OutputApi.PresubmitPromptWarning) presubmit.OutputApi.PresubmitPromptWarning)
def testRunPythonUnitTestsNoTest(self): def testRunPythonUnitTestsNoTest(self):
input_api = self.MockInputApi() input_api = self.MockInputApi(None, False)
input_api.is_committing = False
self.mox.ReplayAll() self.mox.ReplayAll()
results = presubmit_canned_checks.RunPythonUnitTests( results = presubmit_canned_checks.RunPythonUnitTests(
input_api, presubmit.OutputApi, []) input_api, presubmit.OutputApi, [])
self.assertEquals(results, []) self.assertEquals(results, [])
def testRunPythonUnitTestsNonExistentUpload(self): def testRunPythonUnitTestsNonExistentUpload(self):
input_api = self.MockInputApi() input_api = self.MockInputApi(None, False)
input_api.is_committing = False
presubmit_canned_checks._RunPythonUnitTests_LoadTests( presubmit_canned_checks._RunPythonUnitTests_LoadTests(
input_api, '_non_existent_module').AndRaise( input_api, '_non_existent_module').AndRaise(
exceptions.ImportError('Blehh')) exceptions.ImportError('Blehh'))
self.mox.ReplayAll() self.mox.ReplayAll()
results = presubmit_canned_checks.RunPythonUnitTests( results = presubmit_canned_checks.RunPythonUnitTests(
input_api, presubmit.OutputApi, ['_non_existent_module']) input_api, presubmit.OutputApi, ['_non_existent_module'])
self.assertEquals(len(results), 1) self.assertEquals(len(results), 1)
@ -1246,8 +1224,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
presubmit.OutputApi.PresubmitNotifyResult) presubmit.OutputApi.PresubmitNotifyResult)
def testRunPythonUnitTestsNonExistentCommitting(self): def testRunPythonUnitTestsNonExistentCommitting(self):
input_api = self.MockInputApi() input_api = self.MockInputApi(None, True)
input_api.is_committing = True
presubmit_canned_checks._RunPythonUnitTests_LoadTests( presubmit_canned_checks._RunPythonUnitTests_LoadTests(
input_api, '_non_existent_module').AndRaise( input_api, '_non_existent_module').AndRaise(
exceptions.ImportError('Blehh')) exceptions.ImportError('Blehh'))
@ -1258,8 +1235,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError) self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError)
def testRunPythonUnitTestsEmptyUpload(self): def testRunPythonUnitTestsEmptyUpload(self):
input_api = self.MockInputApi() input_api = self.MockInputApi(None, False)
input_api.is_committing = False
test_module = self.mox.CreateMockAnything() test_module = self.mox.CreateMockAnything()
presubmit_canned_checks._RunPythonUnitTests_LoadTests( presubmit_canned_checks._RunPythonUnitTests_LoadTests(
input_api, 'test_module').AndReturn([]) input_api, 'test_module').AndReturn([])
@ -1270,8 +1246,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.assertEquals(results, []) self.assertEquals(results, [])
def testRunPythonUnitTestsEmptyCommitting(self): def testRunPythonUnitTestsEmptyCommitting(self):
input_api = self.MockInputApi() input_api = self.MockInputApi(None, True)
input_api.is_committing = True
test_module = self.mox.CreateMockAnything() test_module = self.mox.CreateMockAnything()
presubmit_canned_checks._RunPythonUnitTests_LoadTests( presubmit_canned_checks._RunPythonUnitTests_LoadTests(
input_api, 'test_module').AndReturn([]) input_api, 'test_module').AndReturn([])
@ -1282,8 +1257,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.assertEquals(results, []) self.assertEquals(results, [])
def testRunPythonUnitTestsFailureUpload(self): def testRunPythonUnitTestsFailureUpload(self):
input_api = self.MockInputApi() input_api = self.MockInputApi(None, False)
input_api.is_committing = False
input_api.unittest = self.mox.CreateMock(unittest) input_api.unittest = self.mox.CreateMock(unittest)
input_api.cStringIO = self.mox.CreateMock(presubmit.cStringIO) input_api.cStringIO = self.mox.CreateMock(presubmit.cStringIO)
test = self.mox.CreateMockAnything() test = self.mox.CreateMockAnything()
@ -1312,8 +1286,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.assertEquals(results[0]._long_text, 'BOO HOO!') self.assertEquals(results[0]._long_text, 'BOO HOO!')
def testRunPythonUnitTestsFailureCommitting(self): def testRunPythonUnitTestsFailureCommitting(self):
input_api = self.MockInputApi() input_api = self.MockInputApi(None, True)
input_api.is_committing = True
input_api.unittest = self.mox.CreateMock(unittest) input_api.unittest = self.mox.CreateMock(unittest)
input_api.cStringIO = self.mox.CreateMock(presubmit.cStringIO) input_api.cStringIO = self.mox.CreateMock(presubmit.cStringIO)
test = self.mox.CreateMockAnything() test = self.mox.CreateMockAnything()
@ -1341,10 +1314,9 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.assertEquals(results[0]._long_text, 'BOO HOO!') self.assertEquals(results[0]._long_text, 'BOO HOO!')
def testRunPythonUnitTestsSuccess(self): def testRunPythonUnitTestsSuccess(self):
input_api = self.MockInputApi() input_api = self.MockInputApi(None, False)
input_api.is_committing = False
input_api.unittest = self.mox.CreateMock(unittest)
input_api.cStringIO = self.mox.CreateMock(presubmit.cStringIO) input_api.cStringIO = self.mox.CreateMock(presubmit.cStringIO)
input_api.unittest = self.mox.CreateMock(unittest)
test = self.mox.CreateMockAnything() test = self.mox.CreateMockAnything()
presubmit_canned_checks._RunPythonUnitTests_LoadTests( presubmit_canned_checks._RunPythonUnitTests_LoadTests(
input_api, 'test_module').AndReturn([test]) input_api, 'test_module').AndReturn([test])

Loading…
Cancel
Save