Fix gcl breakage.

Small refactor of ChangeInfo to not hardcode the use of GetRepositoryRoot().

TEST=unit tests
BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@18272 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 17 years ago
parent 17f59f2dd9
commit 8d5c9a5a52

@ -265,6 +265,7 @@ class ChangeInfo(object):
description: the description. description: the description.
files: a list of 2 tuple containing (status, filename) of changed files, files: a list of 2 tuple containing (status, filename) of changed files,
with paths being relative to the top repository directory. with paths being relative to the top repository directory.
local_root: Local root directory
""" """
_SEPARATOR = "\n-----\n" _SEPARATOR = "\n-----\n"
@ -279,7 +280,7 @@ class ChangeInfo(object):
# _SEPARATOR\n # _SEPARATOR\n
# description # description
def __init__(self, name, issue, patchset, description, files): def __init__(self, name, issue, patchset, description, files, local_root):
self.name = name self.name = name
self.issue = int(issue) self.issue = int(issue)
self.patchset = int(patchset) self.patchset = int(patchset)
@ -288,7 +289,7 @@ class ChangeInfo(object):
files = [] files = []
self._files = files self._files = files
self.patch = None self.patch = None
self._local_root = GetRepositoryRoot() self._local_root = local_root
def GetFileNames(self): def GetFileNames(self):
"""Returns the list of file names included in this change.""" """Returns the list of file names included in this change."""
@ -417,7 +418,7 @@ class ChangeInfo(object):
return False return False
@staticmethod @staticmethod
def Load(changename, fail_on_not_found=True, update_status=False): def Load(changename, local_root, fail_on_not_found, update_status):
"""Gets information about a changelist. """Gets information about a changelist.
Args: Args:
@ -432,7 +433,7 @@ class ChangeInfo(object):
if not os.path.exists(info_file): if not os.path.exists(info_file):
if fail_on_not_found: if fail_on_not_found:
ErrorExit("Changelist " + changename + " not found.") ErrorExit("Changelist " + changename + " not found.")
return ChangeInfo(changename, 0, 0, '', None) return ChangeInfo(changename, 0, 0, '', None, local_root)
split_data = ReadFile(info_file).split(ChangeInfo._SEPARATOR, 2) split_data = ReadFile(info_file).split(ChangeInfo._SEPARATOR, 2)
if len(split_data) != 3: if len(split_data) != 3:
ErrorExit("Changelist file %s is corrupt" % info_file) ErrorExit("Changelist file %s is corrupt" % info_file)
@ -452,7 +453,7 @@ class ChangeInfo(object):
save = False save = False
if update_status: if update_status:
for file in files: for file in files:
filename = os.path.join(GetRepositoryRoot(), file[1]) filename = os.path.join(local_root, file[1])
status_result = gclient.CaptureSVNStatus(filename) status_result = gclient.CaptureSVNStatus(filename)
if not status_result or not status_result[0][0]: if not status_result or not status_result[0][0]:
# File has been reverted. # File has been reverted.
@ -463,7 +464,8 @@ class ChangeInfo(object):
if status != file[0]: if status != file[0]:
save = True save = True
files[files.index(file)] = (status, file[1]) files[files.index(file)] = (status, file[1])
change_info = ChangeInfo(changename, issue, patchset, description, files) change_info = ChangeInfo(changename, issue, patchset, description, files,
local_root)
if save: if save:
change_info.Save() change_info.Save()
return change_info return change_info
@ -476,16 +478,18 @@ def GetChangelistInfoFile(changename):
return os.path.join(GetChangesDir(), changename) return os.path.join(GetChangesDir(), changename)
def LoadChangelistInfoForMultiple(changenames, fail_on_not_found=True, def LoadChangelistInfoForMultiple(changenames, local_root, fail_on_not_found,
update_status=False): update_status):
"""Loads many changes and merge their files list into one pseudo change. """Loads many changes and merge their files list into one pseudo change.
This is mainly usefull to concatenate many changes into one for a 'gcl try'. This is mainly usefull to concatenate many changes into one for a 'gcl try'.
""" """
changes = changenames.split(',') changes = changenames.split(',')
aggregate_change_info = ChangeInfo(changenames, 0, 0, '', None) aggregate_change_info = ChangeInfo(changenames, 0, 0, '', None, local_root)
for change in changes: for change in changes:
aggregate_change_info._files += ChangeInfo.Load(change, fail_on_not_found, aggregate_change_info._files += ChangeInfo.Load(change,
local_root,
fail_on_not_found,
update_status).GetFiles() update_status).GetFiles()
return aggregate_change_info return aggregate_change_info
@ -528,7 +532,8 @@ def GetModifiedFiles():
# Get a list of all files in changelists. # Get a list of all files in changelists.
files_in_cl = {} files_in_cl = {}
for cl in GetCLs(): for cl in GetCLs():
change_info = ChangeInfo.Load(cl) change_info = ChangeInfo.Load(cl, GetRepositoryRoot(),
fail_on_not_found=True, update_status=False)
for status, filename in change_info.GetFiles(): for status, filename in change_info.GetFiles():
files_in_cl[filename] = change_info.name files_in_cl[filename] = change_info.name
@ -597,7 +602,9 @@ def Opened():
for cl_name in cl_keys: for cl_name in cl_keys:
if cl_name: if cl_name:
note = "" note = ""
if len(ChangeInfo.Load(cl_name).GetFiles()) != len(files[cl_name]): change_info = ChangeInfo.Load(cl_name, GetRepositoryRoot(),
fail_on_not_found=True, update_status=False)
if len(change_info.GetFiles()) != len(files[cl_name]):
note = " (Note: this changelist contains files outside this directory)" note = " (Note: this changelist contains files outside this directory)"
print "\n--- Changelist " + cl_name + note + ":" print "\n--- Changelist " + cl_name + note + ":"
for file in files[cl_name]: for file in files[cl_name]:
@ -1072,7 +1079,7 @@ def DoPresubmitChecks(change_info, committing, may_prompt):
def Changes(): def Changes():
"""Print all the changelists and their files.""" """Print all the changelists and their files."""
for cl in GetCLs(): for cl in GetCLs():
change_info = ChangeInfo.Load(cl, True, True) change_info = ChangeInfo.Load(cl, GetRepositoryRoot(), True, True)
print "\n--- Changelist " + change_info.name + ":" print "\n--- Changelist " + change_info.name + ":"
for file in change_info.GetFiles(): for file in change_info.GetFiles():
print "".join(file) print "".join(file)
@ -1146,9 +1153,11 @@ def main(argv=None):
# change didn't exist. All other commands require an existing change. # change didn't exist. All other commands require an existing change.
fail_on_not_found = command != "try" and command != "change" fail_on_not_found = command != "try" and command != "change"
if command == "try" and changename.find(',') != -1: if command == "try" and changename.find(',') != -1:
change_info = LoadChangelistInfoForMultiple(changename, True, True) change_info = LoadChangelistInfoForMultiple(changename, GetRepositoryRoot(),
True, True)
else: else:
change_info = ChangeInfo.Load(changename, fail_on_not_found, True) change_info = ChangeInfo.Load(changename, GetRepositoryRoot(),
fail_on_not_found, True)
if command == "change": if command == "change":
if (len(argv) == 4): if (len(argv) == 4):

@ -516,7 +516,7 @@ class GclChange(object):
# 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 change_info.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')
@ -726,7 +726,7 @@ def DoPresubmitChecks(change_info,
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_info.GetFileNames(),
change_info.local_root) change_info.GetLocalRoot())
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 = []
@ -734,7 +734,7 @@ def DoPresubmitChecks(change_info,
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.local_root, 'PRESUBMIT.py') fake_path = os.path.join(change_info.GetLocalRoot(), '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)
@ -809,7 +809,8 @@ def Main(argv):
files = ParseFiles(args, options.recursive) files = ParseFiles(args, options.recursive)
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(gcl.ChangeInfo('No name', 0, 0, '', files,
gcl.GetRepositoryRoot()),
options.commit, options.commit,
options.verbose, options.verbose,
sys.stdout, sys.stdout,

@ -17,6 +17,7 @@ class GclTestsBase(super_mox.SuperMoxTestBase):
"""Setups and tear downs the mocks but doesn't test anything as-is.""" """Setups and tear downs the mocks but doesn't test anything as-is."""
def setUp(self): def setUp(self):
super_mox.SuperMoxTestBase.setUp(self) super_mox.SuperMoxTestBase.setUp(self)
self.fake_root_dir = self.RootDir()
self.mox.StubOutWithMock(gcl, 'RunShell') self.mox.StubOutWithMock(gcl, 'RunShell')
self.mox.StubOutWithMock(gcl.gclient, 'CaptureSVNInfo') self.mox.StubOutWithMock(gcl.gclient, 'CaptureSVNInfo')
self.mox.StubOutWithMock(gcl.os, 'getcwd') self.mox.StubOutWithMock(gcl.os, 'getcwd')
@ -60,13 +61,17 @@ class GclUnittest(GclTestsBase):
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(gcl, members) self.compareMembers(gcl, members)
def testIsSVNMoved(self):
# TODO(maruel): TEST ME
pass
def testHelp(self): def testGetSVNFileProperty(self):
self.mox.StubOutWithMock(gcl.sys, 'stdout') # TODO(maruel): TEST ME
gcl.sys.stdout.write(mox.StrContains('GCL is a wrapper for Subversion')) pass
gcl.sys.stdout.write('\n')
self.mox.ReplayAll() def testUnknownFiles(self):
gcl.Help() # TODO(maruel): TEST ME
pass
def testGetRepositoryRootNone(self): def testGetRepositoryRootNone(self):
gcl.REPOSITORY_ROOT = None gcl.REPOSITORY_ROOT = None
@ -93,6 +98,73 @@ class GclUnittest(GclTestsBase):
self.mox.ReplayAll() self.mox.ReplayAll()
self.assertEquals(gcl.GetRepositoryRoot(), root_path) self.assertEquals(gcl.GetRepositoryRoot(), root_path)
def testGetCachedFile(self):
# TODO(maruel): TEST ME
pass
def testGetCodeReviewSetting(self):
# TODO(maruel): TEST ME
pass
def testGetChangelistInfoFile(self):
# TODO(maruel): TEST ME
pass
def testLoadChangelistInfoForMultiple(self):
# TODO(maruel): TEST ME
pass
def testGetModifiedFiles(self):
# TODO(maruel): TEST ME
pass
def testGetFilesNotInCL(self):
# TODO(maruel): TEST ME
pass
def testSendToRietveld(self):
# TODO(maruel): TEST ME
pass
def testOpened(self):
# TODO(maruel): TEST ME
pass
def testHelp(self):
self.mox.StubOutWithMock(gcl.sys, 'stdout')
gcl.sys.stdout.write(mox.StrContains('GCL is a wrapper for Subversion'))
gcl.sys.stdout.write('\n')
self.mox.ReplayAll()
gcl.Help()
def testGenerateDiff(self):
# TODO(maruel): TEST ME
pass
def testPresubmitCL(self):
# TODO(maruel): TEST ME
pass
def testTryChange(self):
# TODO(maruel): TEST ME
pass
def testCommit(self):
# TODO(maruel): TEST ME
pass
def testChange(self):
# TODO(maruel): TEST ME
pass
def testLint(self):
# TODO(maruel): TEST ME
pass
def testDoPresubmitChecks(self):
# TODO(maruel): TEST ME
pass
class ChangeInfoUnittest(GclTestsBase): class ChangeInfoUnittest(GclTestsBase):
def setUp(self): def setUp(self):
@ -101,7 +173,6 @@ class ChangeInfoUnittest(GclTestsBase):
self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot') self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot')
def testChangeInfoMembers(self): def testChangeInfoMembers(self):
gcl.GetRepositoryRoot().AndReturn('prout')
self.mox.ReplayAll() self.mox.ReplayAll()
members = [ members = [
'CloseIssue', 'Delete', 'GetFiles', 'GetFileNames', 'GetLocalRoot', 'CloseIssue', 'Delete', 'GetFiles', 'GetFileNames', 'GetLocalRoot',
@ -110,13 +181,14 @@ class ChangeInfoUnittest(GclTestsBase):
'patch', 'patchset', 'patch', 'patchset',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(gcl.ChangeInfo('', 0, 0, '', None), members) self.compareMembers(gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir),
members)
def testChangeInfoBase(self): def testChangeInfoBase(self):
files = [('M', 'foo'), ('A', 'bar')] files = [('M', 'foo'), ('A', 'bar')]
gcl.GetRepositoryRoot().AndReturn('prout')
self.mox.ReplayAll() self.mox.ReplayAll()
o = gcl.ChangeInfo('name2', '42', '53', 'description2', files) o = gcl.ChangeInfo('name2', '42', '53', 'description2', files,
self.fake_root_dir)
self.assertEquals(o.name, 'name2') self.assertEquals(o.name, 'name2')
self.assertEquals(o.issue, 42) self.assertEquals(o.issue, 42)
self.assertEquals(o.patchset, 53) self.assertEquals(o.patchset, 53)
@ -124,7 +196,7 @@ class ChangeInfoUnittest(GclTestsBase):
self.assertEquals(o.patch, None) self.assertEquals(o.patch, None)
self.assertEquals(o.GetFileNames(), ['foo', 'bar']) self.assertEquals(o.GetFileNames(), ['foo', 'bar'])
self.assertEquals(o.GetFiles(), files) self.assertEquals(o.GetFiles(), files)
self.assertEquals(o.GetLocalRoot(), 'prout') self.assertEquals(o.GetLocalRoot(), self.fake_root_dir)
def testLoadWithIssue(self): def testLoadWithIssue(self):
description = ["This is some description.", "force an extra separator."] description = ["This is some description.", "force an extra separator."]
@ -132,10 +204,9 @@ class ChangeInfoUnittest(GclTestsBase):
gcl.os.path.exists('bleeeh').AndReturn(True) gcl.os.path.exists('bleeeh').AndReturn(True)
gcl.ReadFile('bleeeh').AndReturn( gcl.ReadFile('bleeeh').AndReturn(
gcl.ChangeInfo._SEPARATOR.join(["42,53", "G b.cc"] + description)) gcl.ChangeInfo._SEPARATOR.join(["42,53", "G b.cc"] + description))
gcl.GetRepositoryRoot().AndReturn('prout')
self.mox.ReplayAll() self.mox.ReplayAll()
change_info = gcl.ChangeInfo.Load('bleh', True, False) change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False)
self.assertEquals(change_info.name, 'bleh') self.assertEquals(change_info.name, 'bleh')
self.assertEquals(change_info.issue, 42) self.assertEquals(change_info.issue, 42)
self.assertEquals(change_info.patchset, 53) self.assertEquals(change_info.patchset, 53)
@ -148,10 +219,9 @@ class ChangeInfoUnittest(GclTestsBase):
gcl.os.path.exists('bleeeh').AndReturn(True) gcl.os.path.exists('bleeeh').AndReturn(True)
gcl.ReadFile('bleeeh').AndReturn( gcl.ReadFile('bleeeh').AndReturn(
gcl.ChangeInfo._SEPARATOR.join(["", "", ""])) gcl.ChangeInfo._SEPARATOR.join(["", "", ""]))
gcl.GetRepositoryRoot().AndReturn('prout')
self.mox.ReplayAll() self.mox.ReplayAll()
change_info = gcl.ChangeInfo.Load('bleh', True, False) change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False)
self.assertEquals(change_info.name, 'bleh') self.assertEquals(change_info.name, 'bleh')
self.assertEquals(change_info.issue, 0) self.assertEquals(change_info.issue, 0)
self.assertEquals(change_info.patchset, 0) self.assertEquals(change_info.patchset, 0)
@ -161,9 +231,9 @@ class ChangeInfoUnittest(GclTestsBase):
def testSaveEmpty(self): def testSaveEmpty(self):
gcl.GetChangelistInfoFile('').AndReturn('foo') gcl.GetChangelistInfoFile('').AndReturn('foo')
gcl.WriteFile('foo', gcl.ChangeInfo._SEPARATOR.join(['0, 0', '', ''])) gcl.WriteFile('foo', gcl.ChangeInfo._SEPARATOR.join(['0, 0', '', '']))
gcl.GetRepositoryRoot().AndReturn('prout')
self.mox.ReplayAll() self.mox.ReplayAll()
change_info = gcl.ChangeInfo('', 0, 0, '', None)
change_info = gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir)
change_info.Save() change_info.Save()
@ -209,7 +279,8 @@ class UploadCLUnittest(GclTestsBase):
def testServerOverride(self): def testServerOverride(self):
change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription', change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription',
[('A', 'aa'), ('M', 'bb')]) [('A', 'aa'), ('M', 'bb')],
self.fake_root_dir)
self.mox.StubOutWithMock(change_info, 'Save') self.mox.StubOutWithMock(change_info, 'Save')
args = ['--server=a', '--no_watchlists'] args = ['--server=a', '--no_watchlists']
change_info.Save() change_info.Save()
@ -230,13 +301,12 @@ class UploadCLUnittest(GclTestsBase):
gcl.os.chdir('somewhere') gcl.os.chdir('somewhere')
self.mox.ReplayAll() self.mox.ReplayAll()
# To balance out the call in gcl.ChangeInfo.__init__().
gcl.GetRepositoryRoot()
gcl.UploadCL(change_info, args) gcl.UploadCL(change_info, args)
def testNoTry(self): def testNoTry(self):
change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription', change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription',
[('A', 'aa'), ('M', 'bb')]) [('A', 'aa'), ('M', 'bb')],
self.fake_root_dir)
change_info.Save = self.mox.CreateMockAnything() change_info.Save = self.mox.CreateMockAnything()
args = ['--no-try', '--no_watchlists'] args = ['--no-try', '--no_watchlists']
change_info.Save() change_info.Save()
@ -257,13 +327,12 @@ class UploadCLUnittest(GclTestsBase):
gcl.os.chdir('somewhere') gcl.os.chdir('somewhere')
self.mox.ReplayAll() self.mox.ReplayAll()
# To balance out the call in gcl.ChangeInfo.__init__().
gcl.GetRepositoryRoot()
gcl.UploadCL(change_info, args) gcl.UploadCL(change_info, args)
def testNormal(self): def testNormal(self):
change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription', change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription',
['aa', 'bb']) [('A', 'aa'), ('M', 'bb')],
self.fake_root_dir)
self.mox.StubOutWithMock(change_info, 'Save') self.mox.StubOutWithMock(change_info, 'Save')
args = ['--no_watchlists'] args = ['--no_watchlists']
change_info.Save() change_info.Save()
@ -286,8 +355,6 @@ class UploadCLUnittest(GclTestsBase):
gcl.os.chdir('somewhere') gcl.os.chdir('somewhere')
self.mox.ReplayAll() self.mox.ReplayAll()
# To balance out the call in gcl.ChangeInfo.__init__().
gcl.GetRepositoryRoot()
gcl.UploadCL(change_info, args) gcl.UploadCL(change_info, args)
self.assertEquals(change_info.issue, 1) self.assertEquals(change_info.issue, 1)
self.assertEquals(change_info.patchset, 2) self.assertEquals(change_info.patchset, 2)

@ -56,16 +56,14 @@ 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')
self.mox.StubOutWithMock(presubmit.gcl, 'ChangeInfo') # Stub any non-getter function in gcl.ChangeInfo.
to_skip = lambda x: not x.startswith('_') and not x.startswith('Get')
def MakeChangeInfo(self, name, issue, patchset, description): for member in filter(to_skip, dir(presubmit.gcl.ChangeInfo)):
ci = self.mox.CreateMock(presubmit.gcl.ChangeInfo) self.mox.StubOutWithMock(presubmit.gcl.ChangeInfo, member)
ci.name = name
ci.issue = issue def MakeChangeInfo(self, name, issue, patchset, description, files):
ci.patchset = patchset ci = presubmit.gcl.ChangeInfo(name, issue, patchset, description, files,
ci.description = description self.fake_root_dir)
ci.patch = None
ci.local_root = self.fake_root_dir
return ci return ci
@ -172,9 +170,8 @@ 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)) ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
ci.GetLocalRoot().AndReturn(self.fake_root_dir) files)
ci.GetFiles().AndReturn(files)
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.GclChange(ci) change = presubmit.GclChange(ci)
@ -240,11 +237,8 @@ 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)) ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
ci.GetLocalRoot().AndReturn(self.fake_root_dir) files)
ci.GetFiles().AndReturn(files)
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
self.mox.ReplayAll() self.mox.ReplayAll()
executer = presubmit.PresubmitExecuter(ci, False) executer = presubmit.PresubmitExecuter(ci, False)
@ -310,10 +304,8 @@ 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)) ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
ci.GetFileNames().AndReturn([item[1] for item in files]) files)
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
self.mox.ReplayAll() self.mox.ReplayAll()
output = StringIO.StringIO() output = StringIO.StringIO()
@ -333,7 +325,8 @@ 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)) 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)
@ -341,9 +334,6 @@ class PresubmitUnittest(PresubmitTestsBase):
).AndReturn(self.presubmit_text) ).AndReturn(self.presubmit_text)
presubmit.gcl.ReadFile(haspresubmit_path, 'rU' presubmit.gcl.ReadFile(haspresubmit_path, 'rU'
).AndReturn(self.presubmit_text) ).AndReturn(self.presubmit_text)
ci.GetFileNames().AndReturn([item[1] for item in files])
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
self.mox.ReplayAll() self.mox.ReplayAll()
output = StringIO.StringIO() output = StringIO.StringIO()
@ -375,10 +365,8 @@ 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)) ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
ci.GetFileNames().AndReturn([item[1] for item in files]) files)
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
self.mox.ReplayAll() self.mox.ReplayAll()
output = StringIO.StringIO() output = StringIO.StringIO()
@ -408,10 +396,8 @@ 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)) ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
ci.GetFileNames().AndReturn([item[1] for item in files]) files)
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
self.mox.ReplayAll() self.mox.ReplayAll()
output = StringIO.StringIO() output = StringIO.StringIO()
@ -432,9 +418,7 @@ 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') ci = self.MakeChangeInfo('mychange', 0, 0, 'foo', files)
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.GclChange(ci) change = presubmit.GclChange(ci)
@ -476,10 +460,8 @@ def CheckChangeOnCommit(input_api, output_api):
raise Exception("Test error") raise Exception("Test error")
""" """
ci = self.MakeChangeInfo( ci = self.MakeChangeInfo(
'foo', 0, 0, "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n") 'foo', 0, 0, "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n",
ci.GetFileNames().AndReturn([]) None)
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn([])
self.mox.ReplayAll() self.mox.ReplayAll()
output = StringIO.StringIO() output = StringIO.StringIO()
@ -590,9 +572,8 @@ 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)) ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
ci.GetLocalRoot().AndReturn(self.fake_root_dir) files)
ci.GetFiles().AndReturn(files)
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.GclChange(ci) change = presubmit.GclChange(ci)
@ -704,9 +685,7 @@ 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, '') ci = self.MakeChangeInfo('mychange', 0, 0, '', files)
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.GclChange(ci) change = presubmit.GclChange(ci)
@ -728,9 +707,7 @@ 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, '') ci = self.MakeChangeInfo('mychange', 0, 0, '', files)
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.GclChange(ci) change = presubmit.GclChange(ci)
@ -755,9 +732,7 @@ 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, '') ci = self.MakeChangeInfo('mychange', 0, 0, '', files)
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
self.mox.ReplayAll() self.mox.ReplayAll()
# It doesn't make sense on non-Windows platform. This is somewhat hacky, # It doesn't make sense on non-Windows platform. This is somewhat hacky,
@ -791,9 +766,7 @@ 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') ci = self.MakeChangeInfo('mychange', 0, 0, 'Bleh\n', [])
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn([])
self.mox.ReplayAll() self.mox.ReplayAll()
change = presubmit.GclChange(ci) change = presubmit.GclChange(ci)
@ -803,9 +776,7 @@ class InputApiUnittest(PresubmitTestsBase):
api.AffectedTextFiles(include_deletes=False) api.AffectedTextFiles(include_deletes=False)
def testReadFileStringDenied(self): def testReadFileStringDenied(self):
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n') ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')])
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn([('M', 'AA')])
self.mox.ReplayAll() self.mox.ReplayAll()
input_api = presubmit.InputApi( input_api = presubmit.InputApi(
@ -814,10 +785,8 @@ class InputApiUnittest(PresubmitTestsBase):
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') ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')])
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo') path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo')
ci.GetFiles().AndReturn([('M', 'AA')])
presubmit.gcl.ReadFile(path, 'x').AndReturn(None) presubmit.gcl.ReadFile(path, 'x').AndReturn(None)
self.mox.ReplayAll() self.mox.ReplayAll()
@ -827,9 +796,7 @@ class InputApiUnittest(PresubmitTestsBase):
input_api.ReadFile(path, 'x') input_api.ReadFile(path, 'x')
def testReadFileAffectedFileDenied(self): def testReadFileAffectedFileDenied(self):
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n') ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')])
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn([('M', 'AA')])
file = presubmit.AffectedFile('boo', 'M', 'Unrelated') file = presubmit.AffectedFile('boo', 'M', 'Unrelated')
self.mox.ReplayAll() self.mox.ReplayAll()
@ -839,9 +806,7 @@ class InputApiUnittest(PresubmitTestsBase):
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') ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')])
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn([('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()
@ -995,9 +960,7 @@ 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, '') ci = self.MakeChangeInfo('', 0, 0, '', [])
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn([])
self.mox.ReplayAll() self.mox.ReplayAll()
self.compareMembers(presubmit.GclChange(ci), members) self.compareMembers(presubmit.GclChange(ci), members)
@ -1040,14 +1003,10 @@ class CannedChecksUnittest(PresubmitTestsBase):
committing): committing):
input_api1 = self.MockInputApi() input_api1 = self.MockInputApi()
input_api1.is_committing = committing input_api1.is_committing = committing
ci1 = self.MakeChangeInfo('foo', 0, 0, description1) ci1 = self.MakeChangeInfo('foo', 0, 0, description1, [])
ci1.GetLocalRoot().AndReturn(self.fake_root_dir)
ci1.GetFiles().AndReturn([])
input_api2 = self.MockInputApi() input_api2 = self.MockInputApi()
input_api2.is_committing = committing input_api2.is_committing = committing
ci2 = self.MakeChangeInfo('foo', 0, 0, description2) ci2 = self.MakeChangeInfo('foo', 0, 0, description2, [])
ci2.GetLocalRoot().AndReturn(self.fake_root_dir)
ci2.GetFiles().AndReturn([])
self.mox.ReplayAll() self.mox.ReplayAll()
input_api1.change = presubmit.GclChange(ci1) input_api1.change = presubmit.GclChange(ci1)
@ -1060,9 +1019,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
def ContentTest(self, check, content1, content2, error_type): def ContentTest(self, check, content1, content2, error_type):
input_api1 = self.MockInputApi() input_api1 = self.MockInputApi()
ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n') ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n', [])
ci1.GetLocalRoot().AndReturn(self.fake_root_dir)
ci1.GetFiles().AndReturn([])
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 = [
@ -1072,9 +1029,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
] ]
input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1) input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1)
input_api2 = self.MockInputApi() input_api2 = self.MockInputApi()
ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n') ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n', None)
ci2.GetLocalRoot().AndReturn(self.fake_root_dir)
ci2.GetFiles().AndReturn([])
output2 = [ output2 = [
(affected_file, 42, 'yo, ' + content2), (affected_file, 42, 'yo, ' + content2),
(affected_file, 43, 'yer'), (affected_file, 43, 'yer'),
@ -1094,17 +1049,13 @@ class CannedChecksUnittest(PresubmitTestsBase):
def ReadFileTest(self, check, content1, content2, error_type): def ReadFileTest(self, check, content1, content2, error_type):
input_api1 = self.MockInputApi() input_api1 = self.MockInputApi()
self.mox.StubOutWithMock(input_api1, 'ReadFile') self.mox.StubOutWithMock(input_api1, 'ReadFile')
ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n') ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n', None)
ci1.GetLocalRoot().AndReturn(self.fake_root_dir)
ci1.GetFiles().AndReturn([])
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() input_api2 = self.MockInputApi()
self.mox.StubOutWithMock(input_api2, 'ReadFile') self.mox.StubOutWithMock(input_api2, 'ReadFile')
ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n') ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n', [])
ci2.GetLocalRoot().AndReturn(self.fake_root_dir)
ci2.GetFiles().AndReturn([])
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)

Loading…
Cancel
Save