Melting pot of changes.

Fix GclChangeInfo.__getattr__ to only accept uppercase tags.
Rename illnamed GclChangeInfo.Change() to GclChangeInfo.Name().
Fix random comments.

TEST=unit test
BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@18138 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 16 years ago
parent 196f8cbabb
commit 92022ec600

@ -529,7 +529,7 @@ class GclChange(object):
for info in change_info.files for info in change_info.files
] ]
def Change(self): def Name(self):
"""Returns the change name.""" """Returns the change name."""
return self._name return self._name
@ -547,15 +547,15 @@ class GclChange(object):
return self._full_description return self._full_description
def RepositoryRoot(self): def RepositoryRoot(self):
"""Returns the repository root for this change, as an absolute path.""" """Returns the repository (checkout) root directory for this change,
as an absolute path.
"""
return self._repository_root return self._repository_root
def __getattr__(self, attr): def __getattr__(self, attr):
"""Return keys directly as attributes on the object. """Return tags directly as attributes on the object."""
if not re.match(r"^[A-Z_]*$", attr):
You may use a friendly name (from SPECIAL_KEYS) or the actual name of raise AttributeError(self, attr)
the key.
"""
return self.tags.get(attr) return self.tags.get(attr)
def AffectedFiles(self, include_dirs=False, include_deletes=True): def AffectedFiles(self, include_dirs=False, include_deletes=True):

@ -210,7 +210,7 @@ class PresubmitUnittest(PresubmitTestsBase):
files=files) files=files)
change = presubmit.GclChange(ci) change = presubmit.GclChange(ci)
self.failUnless(change.Change() == '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')
self.failUnless(change.FullDescriptionText() == self.failUnless(change.FullDescriptionText() ==
@ -481,24 +481,31 @@ def CheckChangeOnCommit(input_api, output_api):
def testTags(self): def testTags(self):
DEFAULT_SCRIPT = """ DEFAULT_SCRIPT = """
def CheckChangeOnUpload(input_api, output_api): def CheckChangeOnUpload(input_api, output_api):
if input_api.change.tags['BUG'] != 'boo': if input_api.change.tags['BUG'] != 'boo':
return [output_api.PresubmitError('Tag parsing failed. 1')] return [output_api.PresubmitError('Tag parsing failed. 1')]
if input_api.change.tags['STORY'] != 'http://tracker.com/42': if input_api.change.tags['STORY'] != 'http://tracker.com/42':
return [output_api.PresubmitError('Tag parsing failed. 2')] return [output_api.PresubmitError('Tag parsing failed. 2')]
if input_api.change.BUG != 'boo': if input_api.change.BUG != 'boo':
return [output_api.PresubmitError('Tag parsing failed. 6')] return [output_api.PresubmitError('Tag parsing failed. 6')]
if input_api.change.STORY != 'http://tracker.com/42': if input_api.change.STORY != 'http://tracker.com/42':
return [output_api.PresubmitError('Tag parsing failed. 7')] return [output_api.PresubmitError('Tag parsing failed. 7')]
if 'TEST' in input_api.change.tags: try:
return [output_api.PresubmitError('Tag parsing failed. 3')] y = False
if input_api.change.DescriptionText() != 'Blah Blah': x = input_api.change.invalid
return [output_api.PresubmitError('Tag parsing failed. 4 ' + except AttributeError:
input_api.change.DescriptionText())] y = True
if (input_api.change.FullDescriptionText() != if not y:
'Blah Blah\\n\\nSTORY=http://tracker.com/42\\nBUG=boo\\n'): return [output_api.PresubmitError('Tag parsing failed. 8')]
return [output_api.PresubmitError('Tag parsing failed. 5 ' + if 'TEST' in input_api.change.tags:
input_api.change.FullDescriptionText())] return [output_api.PresubmitError('Tag parsing failed. 3')]
return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])] if input_api.change.DescriptionText() != 'Blah Blah':
return [output_api.PresubmitError('Tag parsing failed. 4 ' +
input_api.change.DescriptionText())]
if (input_api.change.FullDescriptionText() !=
'Blah Blah\\n\\nSTORY=http://tracker.com/42\\nBUG=boo\\n'):
return [output_api.PresubmitError('Tag parsing failed. 5 ' +
input_api.change.FullDescriptionText())]
return [output_api.PresubmitNotifyResult(input_api.change.tags['STORY'])]
def CheckChangeOnCommit(input_api, output_api): def CheckChangeOnCommit(input_api, output_api):
raise Exception("Test error") raise Exception("Test error")
""" """
@ -907,8 +914,8 @@ class GclChangeUnittest(PresubmitTestsBase):
def testMembersChanged(self): def testMembersChanged(self):
self.mox.ReplayAll() self.mox.ReplayAll()
members = [ members = [
'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', 'Change', 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles',
'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name',
'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths',
'issue', 'patchset', 'tags', 'issue', 'patchset', 'tags',
] ]

Loading…
Cancel
Save