From 69eaecb312bfc69aeda3ef58c031772ab2504e86 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Tue, 14 Jun 2011 13:09:13 +0000 Subject: [PATCH] Use tuple everywhere with explicit conversion. TEST=Add PanProjectChecks unittest, there was none. R=dpranke@chromium.org BUG= Review URL: http://codereview.chromium.org/7104141 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@88982 0039d316-1c4b-4281-b951-d872f2087c98 --- presubmit_canned_checks.py | 10 ++++----- tests/presubmit_unittest.py | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index e8bdd3292f..469578e885 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -576,8 +576,8 @@ def RunPylint(input_api, output_api, white_list=None, black_list=None): The default white_list enforces looking only a *.py files. """ - white_list = white_list or ['.*\.py$'] - black_list = black_list or input_api.DEFAULT_BLACK_LIST + white_list = tuple(white_list or ('.*\.py$',)) + black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) if input_api.is_committing: error_type = output_api.PresubmitError else: @@ -846,11 +846,11 @@ def PanProjectChecks(input_api, output_api, Returns: A list of warning or error objects. """ - excluded_paths = excluded_paths or tuple() - text_files = text_files or ( + excluded_paths = tuple(excluded_paths or []) + text_files = tuple(text_files or ( r'.+\.txt$', r'.+\.json$', - ) + )) project_name = project_name or 'Chromium' license_header = license_header or ( r'.*? Copyright \(c\) %(year)s The %(project)s Authors\. ' diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 01f8a4331a..5f87a742ec 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -10,6 +10,7 @@ import StringIO import sys +import time # Fixes include path. from super_mox import mox, SuperMoxTestBase @@ -1361,6 +1362,8 @@ class CannedChecksUnittest(PresubmitTestsBase): input_api.tbr = False input_api.python_executable = 'pyyyyython' input_api.platform = sys.platform + input_api.time = time + input_api.canned_checks = presubmit_canned_checks return input_api def testMembersChanged(self): @@ -2157,6 +2160,44 @@ mac|success|blew self.checkstdout( 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) + def testPanProjectChecks(self): + # Make sure it accepts both list and tuples. + change = presubmit.Change( + 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None) + input_api = self.MockInputApi(change, False) + affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) + for _ in range(3): + input_api.AffectedFiles(file_filter=mox.IgnoreArg(), include_deletes=False + ).AndReturn([affected_file]) + affected_file.NewContents().AndReturn('Hey!\nHo!\nHey!\nHo!\n\n') + affected_file.ChangedContents().AndReturn([ + (0, 'Hey!\n'), + (1, 'Ho!\n'), + (2, 'Hey!\n'), + (3, 'Ho!\n'), + (4, '\n')]) + for _ in range(5): + affected_file.LocalPath().AndReturn('hello.py') + input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file]) + input_api.ReadFile(affected_file).AndReturn('Hey!\nHo!\nHey!\nHo!\n\n') + input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file]) + for _ in range(4): + affected_file.LocalPath().AndReturn('hello.py') + + self.mox.ReplayAll() + results = presubmit_canned_checks.PanProjectChecks( + input_api, + presubmit.OutputApi, + excluded_paths=None, + text_files=None, + license_header=None, + project_name=None, + owners_check=True) + self.assertEqual(1, len(results)) + self.assertEqual( + 'Found line ending with white spaces in:', results[0]._message) + self.checkstdout('') + if __name__ == '__main__': import unittest