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

@ -516,7 +516,7 @@ class GclChange(object):
# plus the description minus all key/value or "tag" lines.
self._description_without_tags = []
self.tags = {}
for line in change_info.description.splitlines():
for line in self._full_description.splitlines():
m = self._tag_line_re.match(line)
if m:
self.tags[m.group('key')] = m.group('value')
@ -726,7 +726,7 @@ def DoPresubmitChecks(change_info,
True if execution can continue, False if not.
"""
presubmit_files = ListRelevantPresubmitFiles(change_info.GetFileNames(),
change_info.local_root)
change_info.GetLocalRoot())
if not presubmit_files and verbose:
output_stream.write("Warning, no presubmit.py found.\n")
results = []
@ -734,7 +734,7 @@ def DoPresubmitChecks(change_info,
if default_presubmit:
if verbose:
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)
for filename in presubmit_files:
filename = os.path.abspath(filename)
@ -809,7 +809,8 @@ def Main(argv):
files = ParseFiles(args, options.recursive)
if options.verbose:
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.verbose,
sys.stdout,

@ -17,6 +17,7 @@ class GclTestsBase(super_mox.SuperMoxTestBase):
"""Setups and tear downs the mocks but doesn't test anything as-is."""
def setUp(self):
super_mox.SuperMoxTestBase.setUp(self)
self.fake_root_dir = self.RootDir()
self.mox.StubOutWithMock(gcl, 'RunShell')
self.mox.StubOutWithMock(gcl.gclient, 'CaptureSVNInfo')
self.mox.StubOutWithMock(gcl.os, 'getcwd')
@ -60,13 +61,17 @@ class GclUnittest(GclTestsBase):
# If this test fails, you should add the relevant test.
self.compareMembers(gcl, members)
def testIsSVNMoved(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 testGetSVNFileProperty(self):
# TODO(maruel): TEST ME
pass
def testUnknownFiles(self):
# TODO(maruel): TEST ME
pass
def testGetRepositoryRootNone(self):
gcl.REPOSITORY_ROOT = None
@ -93,6 +98,73 @@ class GclUnittest(GclTestsBase):
self.mox.ReplayAll()
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):
def setUp(self):
@ -101,7 +173,6 @@ class ChangeInfoUnittest(GclTestsBase):
self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot')
def testChangeInfoMembers(self):
gcl.GetRepositoryRoot().AndReturn('prout')
self.mox.ReplayAll()
members = [
'CloseIssue', 'Delete', 'GetFiles', 'GetFileNames', 'GetLocalRoot',
@ -110,13 +181,14 @@ class ChangeInfoUnittest(GclTestsBase):
'patch', 'patchset',
]
# 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):
files = [('M', 'foo'), ('A', 'bar')]
gcl.GetRepositoryRoot().AndReturn('prout')
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.issue, 42)
self.assertEquals(o.patchset, 53)
@ -124,7 +196,7 @@ class ChangeInfoUnittest(GclTestsBase):
self.assertEquals(o.patch, None)
self.assertEquals(o.GetFileNames(), ['foo', 'bar'])
self.assertEquals(o.GetFiles(), files)
self.assertEquals(o.GetLocalRoot(), 'prout')
self.assertEquals(o.GetLocalRoot(), self.fake_root_dir)
def testLoadWithIssue(self):
description = ["This is some description.", "force an extra separator."]
@ -132,10 +204,9 @@ class ChangeInfoUnittest(GclTestsBase):
gcl.os.path.exists('bleeeh').AndReturn(True)
gcl.ReadFile('bleeeh').AndReturn(
gcl.ChangeInfo._SEPARATOR.join(["42,53", "G b.cc"] + description))
gcl.GetRepositoryRoot().AndReturn('prout')
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.issue, 42)
self.assertEquals(change_info.patchset, 53)
@ -148,10 +219,9 @@ class ChangeInfoUnittest(GclTestsBase):
gcl.os.path.exists('bleeeh').AndReturn(True)
gcl.ReadFile('bleeeh').AndReturn(
gcl.ChangeInfo._SEPARATOR.join(["", "", ""]))
gcl.GetRepositoryRoot().AndReturn('prout')
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.issue, 0)
self.assertEquals(change_info.patchset, 0)
@ -161,9 +231,9 @@ class ChangeInfoUnittest(GclTestsBase):
def testSaveEmpty(self):
gcl.GetChangelistInfoFile('').AndReturn('foo')
gcl.WriteFile('foo', gcl.ChangeInfo._SEPARATOR.join(['0, 0', '', '']))
gcl.GetRepositoryRoot().AndReturn('prout')
self.mox.ReplayAll()
change_info = gcl.ChangeInfo('', 0, 0, '', None)
change_info = gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir)
change_info.Save()
@ -209,7 +279,8 @@ class UploadCLUnittest(GclTestsBase):
def testServerOverride(self):
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')
args = ['--server=a', '--no_watchlists']
change_info.Save()
@ -230,13 +301,12 @@ class UploadCLUnittest(GclTestsBase):
gcl.os.chdir('somewhere')
self.mox.ReplayAll()
# To balance out the call in gcl.ChangeInfo.__init__().
gcl.GetRepositoryRoot()
gcl.UploadCL(change_info, args)
def testNoTry(self):
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()
args = ['--no-try', '--no_watchlists']
change_info.Save()
@ -257,13 +327,12 @@ class UploadCLUnittest(GclTestsBase):
gcl.os.chdir('somewhere')
self.mox.ReplayAll()
# To balance out the call in gcl.ChangeInfo.__init__().
gcl.GetRepositoryRoot()
gcl.UploadCL(change_info, args)
def testNormal(self):
change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription',
['aa', 'bb'])
[('A', 'aa'), ('M', 'bb')],
self.fake_root_dir)
self.mox.StubOutWithMock(change_info, 'Save')
args = ['--no_watchlists']
change_info.Save()
@ -286,8 +355,6 @@ class UploadCLUnittest(GclTestsBase):
gcl.os.chdir('somewhere')
self.mox.ReplayAll()
# To balance out the call in gcl.ChangeInfo.__init__().
gcl.GetRepositoryRoot()
gcl.UploadCL(change_info, args)
self.assertEquals(change_info.issue, 1)
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.gcl, 'GetSVNFileProperty')
self.mox.StubOutWithMock(presubmit.gcl, 'ReadFile')
self.mox.StubOutWithMock(presubmit.gcl, 'ChangeInfo')
def MakeChangeInfo(self, name, issue, patchset, description):
ci = self.mox.CreateMock(presubmit.gcl.ChangeInfo)
ci.name = name
ci.issue = issue
ci.patchset = patchset
ci.description = description
ci.patch = None
ci.local_root = self.fake_root_dir
# 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
@ -172,9 +170,8 @@ class PresubmitUnittest(PresubmitTestsBase):
{'URL': 'svn:/foo/boo/flap.h'})
presubmit.gcl.ReadFile(blat).AndReturn('boo!\nahh?')
presubmit.gcl.ReadFile(notfound).AndReturn('look!\nthere?')
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines))
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
self.mox.ReplayAll()
change = presubmit.GclChange(ci)
@ -240,11 +237,8 @@ class PresubmitUnittest(PresubmitTestsBase):
['A', 'foo\\blat.cc'],
]
fake_presubmit = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py')
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines))
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
self.mox.ReplayAll()
executer = presubmit.PresubmitExecuter(ci, False)
@ -310,10 +304,8 @@ class PresubmitUnittest(PresubmitTestsBase):
'rU').AndReturn(self.presubmit_text)
presubmit.gcl.ReadFile(haspresubmit_path,
'rU').AndReturn(self.presubmit_text)
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines))
ci.GetFileNames().AndReturn([item[1] for item in files])
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
self.mox.ReplayAll()
output = StringIO.StringIO()
@ -333,7 +325,8 @@ class PresubmitUnittest(PresubmitTestsBase):
]
presubmit_path = join(self.fake_root_dir, '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):
presubmit.os.path.isfile(presubmit_path).AndReturn(True)
presubmit.os.path.isfile(haspresubmit_path).AndReturn(True)
@ -341,9 +334,6 @@ class PresubmitUnittest(PresubmitTestsBase):
).AndReturn(self.presubmit_text)
presubmit.gcl.ReadFile(haspresubmit_path, 'rU'
).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()
output = StringIO.StringIO()
@ -375,10 +365,8 @@ class PresubmitUnittest(PresubmitTestsBase):
presubmit.gcl.ReadFile(presubmit_path, 'rU').AndReturn(self.presubmit_text)
presubmit.gcl.ReadFile(haspresubmit_path, 'rU').AndReturn(
self.presubmit_text)
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines))
ci.GetFileNames().AndReturn([item[1] for item in files])
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
self.mox.ReplayAll()
output = StringIO.StringIO()
@ -408,10 +396,8 @@ def CheckChangeOnCommit(input_api, output_api):
presubmit.os.path.isfile(join(self.fake_root_dir,
'haspresubmit',
'PRESUBMIT.py')).AndReturn(False)
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines))
ci.GetFileNames().AndReturn([item[1] for item in files])
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
self.mox.ReplayAll()
output = StringIO.StringIO()
@ -432,9 +418,7 @@ def CheckChangeOnCommit(input_api, output_api):
presubmit.os.path.isdir(isdir).AndReturn(True)
presubmit.os.path.exists(blat).AndReturn(True)
presubmit.os.path.isdir(blat).AndReturn(False)
ci = self.MakeChangeInfo('mychange', 0, 0, 'foo')
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
ci = self.MakeChangeInfo('mychange', 0, 0, 'foo', files)
self.mox.ReplayAll()
change = presubmit.GclChange(ci)
@ -476,10 +460,8 @@ def CheckChangeOnCommit(input_api, output_api):
raise Exception("Test error")
"""
ci = self.MakeChangeInfo(
'foo', 0, 0, "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n")
ci.GetFileNames().AndReturn([])
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn([])
'foo', 0, 0, "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n",
None)
self.mox.ReplayAll()
output = StringIO.StringIO()
@ -590,9 +572,8 @@ class InputApiUnittest(PresubmitTestsBase):
).AndReturn(None)
presubmit.gcl.ReadFile(blat).AndReturn('whatever\ncookie')
presubmit.gcl.ReadFile(another).AndReturn('whatever\ncookie2')
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines))
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
ci = self.MakeChangeInfo('mychange', 0, 0, '\n'.join(description_lines),
files)
self.mox.ReplayAll()
change = presubmit.GclChange(ci)
@ -704,9 +685,7 @@ class InputApiUnittest(PresubmitTestsBase):
presubmit.os.path.exists(item).AndReturn(True)
presubmit.os.path.isdir(item).AndReturn(False)
presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None)
ci = self.MakeChangeInfo('mychange', 0, 0, '')
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
ci = self.MakeChangeInfo('mychange', 0, 0, '', files)
self.mox.ReplayAll()
change = presubmit.GclChange(ci)
@ -728,9 +707,7 @@ class InputApiUnittest(PresubmitTestsBase):
presubmit.os.path.exists(item).AndReturn(True)
presubmit.os.path.isdir(item).AndReturn(False)
presubmit.gcl.GetSVNFileProperty(item, 'svn:mime-type').AndReturn(None)
ci = self.MakeChangeInfo('mychange', 0, 0, '')
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
ci = self.MakeChangeInfo('mychange', 0, 0, '', files)
self.mox.ReplayAll()
change = presubmit.GclChange(ci)
@ -755,9 +732,7 @@ class InputApiUnittest(PresubmitTestsBase):
['A', join('isdir', 'blat.cc')],
['M', join('elsewhere', 'ouf.cc')],
]
ci = self.MakeChangeInfo('mychange', 0, 0, '')
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn(files)
ci = self.MakeChangeInfo('mychange', 0, 0, '', files)
self.mox.ReplayAll()
# It doesn't make sense on non-Windows platform. This is somewhat hacky,
@ -791,9 +766,7 @@ class InputApiUnittest(PresubmitTestsBase):
def testDeprecated(self):
presubmit.warnings.warn(mox.IgnoreArg(), category=mox.IgnoreArg(),
stacklevel=2)
ci = self.MakeChangeInfo('mychange', 0, 0, 'Bleh\n')
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn([])
ci = self.MakeChangeInfo('mychange', 0, 0, 'Bleh\n', [])
self.mox.ReplayAll()
change = presubmit.GclChange(ci)
@ -803,9 +776,7 @@ class InputApiUnittest(PresubmitTestsBase):
api.AffectedTextFiles(include_deletes=False)
def testReadFileStringDenied(self):
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n')
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn([('M', 'AA')])
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')])
self.mox.ReplayAll()
input_api = presubmit.InputApi(
@ -814,10 +785,8 @@ class InputApiUnittest(PresubmitTestsBase):
self.assertRaises(IOError, input_api.ReadFile, 'boo', 'x')
def testReadFileStringAccepted(self):
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n')
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')])
path = presubmit.os.path.join(self.fake_root_dir, 'AA/boo')
ci.GetFiles().AndReturn([('M', 'AA')])
presubmit.gcl.ReadFile(path, 'x').AndReturn(None)
self.mox.ReplayAll()
@ -827,9 +796,7 @@ class InputApiUnittest(PresubmitTestsBase):
input_api.ReadFile(path, 'x')
def testReadFileAffectedFileDenied(self):
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n')
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn([('M', 'AA')])
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')])
file = presubmit.AffectedFile('boo', 'M', 'Unrelated')
self.mox.ReplayAll()
@ -839,9 +806,7 @@ class InputApiUnittest(PresubmitTestsBase):
self.assertRaises(IOError, input_api.ReadFile, file, 'x')
def testReadFileAffectedFileAccepted(self):
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n')
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn([('M', 'AA')])
ci = self.MakeChangeInfo('foo', 0, 0, 'Foo\n', [('M', 'AA')])
file = presubmit.AffectedFile('AA/boo', 'M', self.fake_root_dir)
presubmit.gcl.ReadFile(file.AbsoluteLocalPath(), 'x').AndReturn(None)
self.mox.ReplayAll()
@ -995,9 +960,7 @@ class GclChangeUnittest(PresubmitTestsBase):
'issue', 'patchset', 'tags',
]
# If this test fails, you should add the relevant test.
ci = self.MakeChangeInfo('', 0, 0, '')
ci.GetLocalRoot().AndReturn(self.fake_root_dir)
ci.GetFiles().AndReturn([])
ci = self.MakeChangeInfo('', 0, 0, '', [])
self.mox.ReplayAll()
self.compareMembers(presubmit.GclChange(ci), members)
@ -1040,14 +1003,10 @@ class CannedChecksUnittest(PresubmitTestsBase):
committing):
input_api1 = self.MockInputApi()
input_api1.is_committing = committing
ci1 = self.MakeChangeInfo('foo', 0, 0, description1)
ci1.GetLocalRoot().AndReturn(self.fake_root_dir)
ci1.GetFiles().AndReturn([])
ci1 = self.MakeChangeInfo('foo', 0, 0, description1, [])
input_api2 = self.MockInputApi()
input_api2.is_committing = committing
ci2 = self.MakeChangeInfo('foo', 0, 0, description2)
ci2.GetLocalRoot().AndReturn(self.fake_root_dir)
ci2.GetFiles().AndReturn([])
ci2 = self.MakeChangeInfo('foo', 0, 0, description2, [])
self.mox.ReplayAll()
input_api1.change = presubmit.GclChange(ci1)
@ -1060,9 +1019,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
def ContentTest(self, check, content1, content2, error_type):
input_api1 = self.MockInputApi()
ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n')
ci1.GetLocalRoot().AndReturn(self.fake_root_dir)
ci1.GetFiles().AndReturn([])
ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n', [])
affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
affected_file.LocalPath().AndReturn('foo.cc')
output1 = [
@ -1072,9 +1029,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
]
input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1)
input_api2 = self.MockInputApi()
ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n')
ci2.GetLocalRoot().AndReturn(self.fake_root_dir)
ci2.GetFiles().AndReturn([])
ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n', None)
output2 = [
(affected_file, 42, 'yo, ' + content2),
(affected_file, 43, 'yer'),
@ -1094,17 +1049,13 @@ class CannedChecksUnittest(PresubmitTestsBase):
def ReadFileTest(self, check, content1, content2, error_type):
input_api1 = self.MockInputApi()
self.mox.StubOutWithMock(input_api1, 'ReadFile')
ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n')
ci1.GetLocalRoot().AndReturn(self.fake_root_dir)
ci1.GetFiles().AndReturn([])
ci1 = self.MakeChangeInfo('foo', 0, 0, 'foo1\n', None)
affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile)
input_api1.AffectedSourceFiles(None).AndReturn([affected_file1])
input_api1.ReadFile(affected_file1, 'rb').AndReturn(content1)
input_api2 = self.MockInputApi()
self.mox.StubOutWithMock(input_api2, 'ReadFile')
ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n')
ci2.GetLocalRoot().AndReturn(self.fake_root_dir)
ci2.GetFiles().AndReturn([])
ci2 = self.MakeChangeInfo('foo2', 0, 0, 'foo2\n', [])
affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile)
input_api2.AffectedSourceFiles(None).AndReturn([affected_file2])
input_api2.ReadFile(affected_file2, 'rb').AndReturn(content2)

Loading…
Cancel
Save