From 92022ec60097252d19f5a8bf654f623942cba394 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Thu, 11 Jun 2009 01:59:28 +0000 Subject: [PATCH] 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 --- presubmit_support.py | 14 +++++------ tests/presubmit_unittest.py | 49 +++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/presubmit_support.py b/presubmit_support.py index 1368665ed..fe7b94927 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -529,7 +529,7 @@ class GclChange(object): for info in change_info.files ] - def Change(self): + def Name(self): """Returns the change name.""" return self._name @@ -547,15 +547,15 @@ class GclChange(object): return self._full_description 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 def __getattr__(self, attr): - """Return keys directly as attributes on the object. - - You may use a friendly name (from SPECIAL_KEYS) or the actual name of - the key. - """ + """Return tags directly as attributes on the object.""" + if not re.match(r"^[A-Z_]*$", attr): + raise AttributeError(self, attr) return self.tags.get(attr) def AffectedFiles(self, include_dirs=False, include_deletes=True): diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index cf21017bb..6bc1f0e35 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -210,7 +210,7 @@ class PresubmitUnittest(PresubmitTestsBase): files=files) change = presubmit.GclChange(ci) - self.failUnless(change.Change() == 'mychange') + self.failUnless(change.Name() == 'mychange') self.failUnless(change.DescriptionText() == 'Hello there\nthis is a change\nand some more regular text') self.failUnless(change.FullDescriptionText() == @@ -481,24 +481,31 @@ def CheckChangeOnCommit(input_api, output_api): def testTags(self): DEFAULT_SCRIPT = """ def CheckChangeOnUpload(input_api, output_api): - if input_api.change.tags['BUG'] != 'boo': - return [output_api.PresubmitError('Tag parsing failed. 1')] - if input_api.change.tags['STORY'] != 'http://tracker.com/42': - return [output_api.PresubmitError('Tag parsing failed. 2')] - if input_api.change.BUG != 'boo': - return [output_api.PresubmitError('Tag parsing failed. 6')] - if input_api.change.STORY != 'http://tracker.com/42': - return [output_api.PresubmitError('Tag parsing failed. 7')] - if 'TEST' in input_api.change.tags: - return [output_api.PresubmitError('Tag parsing failed. 3')] - 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'])] + if input_api.change.tags['BUG'] != 'boo': + return [output_api.PresubmitError('Tag parsing failed. 1')] + if input_api.change.tags['STORY'] != 'http://tracker.com/42': + return [output_api.PresubmitError('Tag parsing failed. 2')] + if input_api.change.BUG != 'boo': + return [output_api.PresubmitError('Tag parsing failed. 6')] + if input_api.change.STORY != 'http://tracker.com/42': + return [output_api.PresubmitError('Tag parsing failed. 7')] + try: + y = False + x = input_api.change.invalid + except AttributeError: + y = True + if not y: + return [output_api.PresubmitError('Tag parsing failed. 8')] + if 'TEST' in input_api.change.tags: + return [output_api.PresubmitError('Tag parsing failed. 3')] + 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): raise Exception("Test error") """ @@ -907,8 +914,8 @@ class GclChangeUnittest(PresubmitTestsBase): def testMembersChanged(self): self.mox.ReplayAll() members = [ - 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', 'Change', - 'DescriptionText', 'FullDescriptionText', 'LocalPaths', + 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', + 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', 'issue', 'patchset', 'tags', ]