From 58407af8be821387d84acc9b32f005dc4864a73e Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Tue, 12 Apr 2011 23:15:57 +0000 Subject: [PATCH] Add author to Change object. Don't set it yet. It's mostly to be used with the commit queue. R=dpranke@chromium.org BUG= TEST= Review URL: http://codereview.chromium.org/6820076 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@81326 0039d316-1c4b-4281-b951-d872f2087c98 --- gcl.py | 3 +- git_cl.py | 10 ++- presubmit_support.py | 9 +- tests/presubmit_unittest.py | 172 +++++++++++++++++++++++++----------- 4 files changed, 135 insertions(+), 59 deletions(-) diff --git a/gcl.py b/gcl.py index 76f302ee1..831360ac2 100755 --- a/gcl.py +++ b/gcl.py @@ -1219,7 +1219,8 @@ def DoPresubmitChecks(change_info, committing, may_prompt): change_info.GetLocalRoot(), change_info.GetFiles(), change_info.issue, - change_info.patchset) + change_info.patchset, + None) output = presubmit_support.DoPresubmitChecks( change=change, committing=committing, diff --git a/git_cl.py b/git_cl.py index 8cdf1318c..d0866ca3a 100755 --- a/git_cl.py +++ b/git_cl.py @@ -837,8 +837,14 @@ def RunHook(committing, upstream_branch, rietveld_server, tbr, may_prompt, # with these log messages. description = RunCommand(['git', 'log', '--pretty=format:%s%n%n%b', '%s...' % (upstream_branch)]).strip() - change = presubmit_support.GitChange(name, description, absroot, files, - issue, patchset) + change = presubmit_support.GitChange( + name, + description, + absroot, + files, + issue, + patchset, + None) # Apply watchlists on upload. if not committing: diff --git a/presubmit_support.py b/presubmit_support.py index 3e4d43330..1e16758b0 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -530,6 +530,7 @@ class AffectedFile(object): def GenerateScmDiff(self): raise NotImplementedError() # Implemented in derived classes. + class SvnAffectedFile(AffectedFile): """Representation of a file in a change out of a Subversion checkout.""" # Method 'NNN' is abstract in class 'NNN' but is not overridden @@ -645,7 +646,8 @@ class Change(object): '^\s*(?P[A-Z][A-Z_0-9]*)\s*=\s*(?P.*?)\s*$') scm = '' - def __init__(self, name, description, local_root, files, issue, patchset): + def __init__( + self, name, description, local_root, files, issue, patchset, author): if files is None: files = [] self._name = name @@ -654,6 +656,7 @@ class Change(object): self._local_root = os.path.abspath(local_root) self.issue = issue self.patchset = patchset + self.author_email = author # From the description text, build up a dictionary of key/value pairs # plus the description minus all key/value or "tag" lines. @@ -1159,6 +1162,7 @@ def Main(argv): parser.add_option("-v", "--verbose", action="count", default=0, help="Use 2 times for more debug info") parser.add_option("--name", default='no name') + parser.add_option("--author") parser.add_option("--description", default='') parser.add_option("--issue", type='int', default=0) parser.add_option("--patchset", type='int', default=0) @@ -1187,7 +1191,8 @@ def Main(argv): options.root, files, options.issue, - options.patchset), + options.patchset, + options.author), options.commit, options.verbose, sys.stdout, diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index c0e7916ab..22c1496b2 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -273,8 +273,14 @@ class PresubmitUnittest(PresubmitTestsBase): self.mox.ReplayAll() - change = presubmit.SvnChange('mychange', '\n'.join(description_lines), - self.fake_root_dir, files, 0, 0) + change = presubmit.SvnChange( + 'mychange', + '\n'.join(description_lines), + self.fake_root_dir, + files, + 0, + 0, + None) self.failUnless(change.Name() == 'mychange') self.failUnless(change.DescriptionText() == 'Hello there\nthis is a change\nand some more regular text') @@ -343,8 +349,14 @@ class PresubmitUnittest(PresubmitTestsBase): fake_presubmit = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py') self.mox.ReplayAll() - change = presubmit.Change('mychange', '\n'.join(description_lines), - self.fake_root_dir, files, 0, 0) + change = presubmit.Change( + 'mychange', + '\n'.join(description_lines), + self.fake_root_dir, + files, + 0, + 0, + None) executer = presubmit.PresubmitExecuter(change, False, False, None, False) self.failIf(executer.ExecPresubmitScript('', fake_presubmit)) # No error if no on-upload entry point @@ -415,8 +427,14 @@ class PresubmitUnittest(PresubmitTestsBase): self.mox.ReplayAll() input_buf = StringIO.StringIO('y\n') - change = presubmit.Change('mychange', '\n'.join(description_lines), - self.fake_root_dir, files, 0, 0) + change = presubmit.Change( + 'mychange', + '\n'.join(description_lines), + self.fake_root_dir, + files, + 0, + 0, + None) output = presubmit.DoPresubmitChecks( change, False, True, None, input_buf, None, False, False, None) self.failIf(output.should_continue()) @@ -449,8 +467,14 @@ class PresubmitUnittest(PresubmitTestsBase): self.mox.ReplayAll() input_buf = StringIO.StringIO('n\n') # say no to the warning - change = presubmit.Change('mychange', '\n'.join(description_lines), - self.fake_root_dir, files, 0, 0) + change = presubmit.Change( + 'mychange', + '\n'.join(description_lines), + self.fake_root_dir, + files, + 0, + 0, + None) output = presubmit.DoPresubmitChecks( change, False, True, None, input_buf, None, True, False, None) self.failIf(output.should_continue()) @@ -488,8 +512,14 @@ class PresubmitUnittest(PresubmitTestsBase): presubmit.random.randint(0, 4).AndReturn(1) self.mox.ReplayAll() - change = presubmit.Change('mychange', '\n'.join(description_lines), - self.fake_root_dir, files, 0, 0) + change = presubmit.Change( + 'mychange', + '\n'.join(description_lines), + self.fake_root_dir, + files, + 0, + 0, + None) output = presubmit.DoPresubmitChecks(change, False, True, None, None, None, False, False, None) self.assertEqual(output.getvalue().count('??'), 2) @@ -525,8 +555,14 @@ def CheckChangeOnCommit(input_api, output_api): input_buf = StringIO.StringIO('y\n') # Always fail. - change = presubmit.Change('mychange', '\n'.join(description_lines), - self.fake_root_dir, files, 0, 0) + change = presubmit.Change( + 'mychange', + '\n'.join(description_lines), + self.fake_root_dir, + files, + 0, + 0, + None) output = presubmit.DoPresubmitChecks( change, False, True, None, input_buf, DEFAULT_SCRIPT, False, False, None) @@ -553,8 +589,8 @@ def CheckChangeOnCommit(input_api, output_api): presubmit.os.path.isdir(blat).AndReturn(False) self.mox.ReplayAll() - change = presubmit.Change('mychange', 'foo', self.fake_root_dir, files, - 0, 0) + change = presubmit.Change( + 'mychange', 'foo', self.fake_root_dir, files, 0, 0, None) affected_files = change.AffectedFiles(include_dirs=False) self.failUnless(len(affected_files) == 1) self.failUnless(affected_files[0].LocalPath().endswith('blat.cc')) @@ -601,8 +637,13 @@ def CheckChangeOnCommit(input_api, output_api): output = StringIO.StringIO() input_buf = StringIO.StringIO('y\n') change = presubmit.Change( - 'foo', "Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n", - self.fake_root_dir, None, 0, 0) + 'foo', + 'Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n', + self.fake_root_dir, + None, + 0, + 0, + None) self.failUnless(presubmit.DoPresubmitChecks( change, False, True, output, input_buf, DEFAULT_SCRIPT, False, False, None)) @@ -827,8 +868,14 @@ class InputApiUnittest(PresubmitTestsBase): self.mox.ReplayAll() - change = presubmit.SvnChange('mychange', '\n'.join(description_lines), - self.fake_root_dir, files, 0, 0) + change = presubmit.SvnChange( + 'mychange', + '\n'.join(description_lines), + self.fake_root_dir, + files, + 0, + 0, + None) input_api = presubmit.InputApi( change, join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), @@ -945,8 +992,8 @@ class InputApiUnittest(PresubmitTestsBase): presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None) self.mox.ReplayAll() - change = presubmit.SvnChange('mychange', '', self.fake_root_dir, files, 0, - 0) + change = presubmit.SvnChange( + 'mychange', '', self.fake_root_dir, files, 0, 0, None) input_api = presubmit.InputApi( change, presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py'), @@ -967,8 +1014,8 @@ class InputApiUnittest(PresubmitTestsBase): presubmit.scm.SVN.GetFileProperty(item, 'svn:mime-type').AndReturn(None) self.mox.ReplayAll() - change = presubmit.SvnChange('mychange', '', self.fake_root_dir, files, 0, - 0) + change = presubmit.SvnChange( + 'mychange', '', self.fake_root_dir, files, 0, 0, None) input_api = presubmit.InputApi( change, './PRESUBMIT.py', False, False, None, False) # Sample usage of overiding the default white and black lists. @@ -993,7 +1040,8 @@ class InputApiUnittest(PresubmitTestsBase): ] self.mox.ReplayAll() - change = presubmit.Change('mychange', '', self.fake_root_dir, files, 0, 0) + change = presubmit.Change( + 'mychange', '', self.fake_root_dir, files, 0, 0, None) affected_files = change.AffectedFiles(include_dirs=True) # Local paths should remain the same self.assertEquals(affected_files[0].LocalPath(), normpath('isdir')) @@ -1023,7 +1071,8 @@ class InputApiUnittest(PresubmitTestsBase): presubmit.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), stacklevel=2) self.mox.ReplayAll() - change = presubmit.Change('mychange', '', self.fake_root_dir, [], 0, 0) + change = presubmit.Change( + 'mychange', '', self.fake_root_dir, [], 0, 0, None) api = presubmit.InputApi( change, presubmit.os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True, @@ -1033,8 +1082,8 @@ class InputApiUnittest(PresubmitTestsBase): def testReadFileStringDenied(self): self.mox.ReplayAll() - change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], - 0, 0) + change = presubmit.Change( + 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None) input_api = presubmit.InputApi( change, presubmit.os.path.join(self.fake_root_dir, '/p'), False, False, None, False) @@ -1045,8 +1094,8 @@ class InputApiUnittest(PresubmitTestsBase): presubmit.gclient_utils.FileRead(path, 'x').AndReturn(None) self.mox.ReplayAll() - change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], - 0, 0) + change = presubmit.Change( + 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None) input_api = presubmit.InputApi( change, presubmit.os.path.join(self.fake_root_dir, '/p'), False, False, None, False) @@ -1056,8 +1105,8 @@ class InputApiUnittest(PresubmitTestsBase): fileobj = presubmit.AffectedFile('boo', 'M', 'Unrelated') self.mox.ReplayAll() - change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], - 0, 0) + change = presubmit.Change( + 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None) input_api = presubmit.InputApi( change, presubmit.os.path.join(self.fake_root_dir, '/p'), False, False, None, False) @@ -1069,8 +1118,8 @@ class InputApiUnittest(PresubmitTestsBase): ).AndReturn(None) self.mox.ReplayAll() - change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], - 0, 0) + change = presubmit.Change( + 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None) input_api = presubmit.InputApi( change, presubmit.os.path.join(self.fake_root_dir, '/p'), False, False, None, False) @@ -1222,21 +1271,34 @@ class AffectedFileUnittest(PresubmitTestsBase): self.failUnless(files[0] == output[0]) -class GclChangeUnittest(PresubmitTestsBase): +class ChangeUnittest(PresubmitTestsBase): def testMembersChanged(self): members = [ 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', - 'issue', 'patchset', 'scm', 'tags', + 'author_email', 'issue', 'patchset', 'scm', 'tags', ] # If this test fails, you should add the relevant test. self.mox.ReplayAll() - change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], - 0, 0) + change = presubmit.Change( + 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, 'foo') self.compareMembers(change, members) + def testMembers(self): + change = presubmit.Change( + 'foo1', 'foo2\nDRU=ro', self.fake_root_dir, [('Y', 'AA')], 3, 5, 'foo3') + self.assertEquals('foo1', change.Name()) + self.assertEquals('foo2', change.DescriptionText()) + self.assertEquals('foo3', change.author_email) + self.assertEquals('ro', change.DRU) + self.assertEquals(3, change.issue) + self.assertEquals(5, change.patchset) + self.assertEquals(self.fake_root_dir, change.RepositoryRoot()) + self.assertEquals(1, len(change.AffectedFiles(include_dirs=True))) + self.assertEquals('Y', change.AffectedFiles(include_dirs=True)[0].Action()) + class CannedChecksUnittest(PresubmitTestsBase): """Tests presubmit_canned_checks.py.""" @@ -1297,11 +1359,11 @@ class CannedChecksUnittest(PresubmitTestsBase): def DescriptionTest(self, check, description1, description2, error_type, committing): - change1 = presubmit.Change('foo1', description1, self.fake_root_dir, None, - 0, 0) + change1 = presubmit.Change( + 'foo1', description1, self.fake_root_dir, None, 0, 0, None) input_api1 = self.MockInputApi(change1, committing) - change2 = presubmit.Change('foo2', description2, self.fake_root_dir, None, - 0, 0) + change2 = presubmit.Change( + 'foo2', description2, self.fake_root_dir, None, 0, 0, None) input_api2 = self.MockInputApi(change2, committing) self.mox.ReplayAll() @@ -1312,8 +1374,8 @@ class CannedChecksUnittest(PresubmitTestsBase): self.assertEquals(results2[0].__class__, error_type) def ContentTest(self, check, content1, content2, error_type): - change1 = presubmit.Change('foo1', 'foo1\n', self.fake_root_dir, None, - 0, 0) + change1 = presubmit.Change( + 'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None) input_api1 = self.MockInputApi(change1, False) affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) affected_file.LocalPath().AndReturn('foo.cc') @@ -1324,8 +1386,8 @@ class CannedChecksUnittest(PresubmitTestsBase): (affected_file, 23, 'ya'), ] input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1) - change2 = presubmit.Change('foo2', 'foo2\n', self.fake_root_dir, None, - 0, 0) + change2 = presubmit.Change( + 'foo2', 'foo2\n', self.fake_root_dir, None, 0, 0, None) input_api2 = self.MockInputApi(change2, False) output2 = [ (affected_file, 42, 'yo, ' + content2), @@ -1343,14 +1405,14 @@ class CannedChecksUnittest(PresubmitTestsBase): def ReadFileTest(self, check, content1, content2, error_type): self.mox.StubOutWithMock(presubmit.InputApi, 'ReadFile') - change1 = presubmit.Change('foo1', 'foo1\n', self.fake_root_dir, None, - 0, 0) + change1 = presubmit.Change( + 'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None) input_api1 = self.MockInputApi(change1, False) affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile) input_api1.AffectedSourceFiles(None).AndReturn([affected_file1]) input_api1.ReadFile(affected_file1, 'rb').AndReturn(content1) - change2 = presubmit.Change('foo2', 'foo2\n', self.fake_root_dir, None, - 0, 0) + change2 = presubmit.Change( + 'foo2', 'foo2\n', self.fake_root_dir, None, 0, 0, None) input_api2 = self.MockInputApi(change2, False) affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile) input_api2.AffectedSourceFiles(None).AndReturn([affected_file2]) @@ -1366,7 +1428,8 @@ class CannedChecksUnittest(PresubmitTestsBase): def SvnPropertyTest(self, check, property_name, value1, value2, committing, error_type, use_source_file): - change1 = presubmit.SvnChange('mychange', '', self.fake_root_dir, [], 0, 0) + change1 = presubmit.SvnChange( + 'mychange', '', self.fake_root_dir, [], 0, 0, None) input_api1 = self.MockInputApi(change1, committing) files1 = [ presubmit.SvnAffectedFile('foo/bar.cc', 'A'), @@ -1380,7 +1443,8 @@ class CannedChecksUnittest(PresubmitTestsBase): property_name).AndReturn(value1) presubmit.scm.SVN.GetFileProperty(presubmit.normpath('foo.cc'), property_name).AndReturn(value1) - change2 = presubmit.SvnChange('mychange', '', self.fake_root_dir, [], 0, 0) + change2 = presubmit.SvnChange( + 'mychange', '', self.fake_root_dir, [], 0, 0, None) input_api2 = self.MockInputApi(change2, committing) files2 = [ presubmit.SvnAffectedFile('foo/bar.cc', 'A'), @@ -1489,8 +1553,8 @@ class CannedChecksUnittest(PresubmitTestsBase): presubmit.OutputApi.PresubmitPromptWarning) # Make sure makefiles are ignored. - change1 = presubmit.Change('foo1', 'foo1\n', self.fake_root_dir, None, - 0, 0) + change1 = presubmit.Change( + 'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None) input_api1 = self.MockInputApi(change1, False) affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile) affected_file1.LocalPath().AndReturn('foo.cc') @@ -2008,7 +2072,7 @@ mac|success|blew def testCannedRunUnitTests(self): change = presubmit.Change( - 'foo1', 'description1', self.fake_root_dir, None, 0, 0) + 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None) input_api = self.MockInputApi(change, False) input_api.verbose = True unit_tests = ['allo', 'bar.py'] @@ -2035,7 +2099,7 @@ mac|success|blew def testCannedRunUnitTestsInDirectory(self): change = presubmit.Change( - 'foo1', 'description1', self.fake_root_dir, None, 0, 0) + 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None) input_api = self.MockInputApi(change, False) input_api.verbose = True input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir)