Commit 69eaecb3 authored by maruel@chromium.org's avatar maruel@chromium.org

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
parent 03b3bdcb
...@@ -576,8 +576,8 @@ def RunPylint(input_api, output_api, white_list=None, black_list=None): ...@@ -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. The default white_list enforces looking only a *.py files.
""" """
white_list = white_list or ['.*\.py$'] white_list = tuple(white_list or ('.*\.py$',))
black_list = black_list or input_api.DEFAULT_BLACK_LIST black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
if input_api.is_committing: if input_api.is_committing:
error_type = output_api.PresubmitError error_type = output_api.PresubmitError
else: else:
...@@ -846,11 +846,11 @@ def PanProjectChecks(input_api, output_api, ...@@ -846,11 +846,11 @@ def PanProjectChecks(input_api, output_api,
Returns: Returns:
A list of warning or error objects. A list of warning or error objects.
""" """
excluded_paths = excluded_paths or tuple() excluded_paths = tuple(excluded_paths or [])
text_files = text_files or ( text_files = tuple(text_files or (
r'.+\.txt$', r'.+\.txt$',
r'.+\.json$', r'.+\.json$',
) ))
project_name = project_name or 'Chromium' project_name = project_name or 'Chromium'
license_header = license_header or ( license_header = license_header or (
r'.*? Copyright \(c\) %(year)s The %(project)s Authors\. ' r'.*? Copyright \(c\) %(year)s The %(project)s Authors\. '
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
import StringIO import StringIO
import sys import sys
import time
# Fixes include path. # Fixes include path.
from super_mox import mox, SuperMoxTestBase from super_mox import mox, SuperMoxTestBase
...@@ -1361,6 +1362,8 @@ class CannedChecksUnittest(PresubmitTestsBase): ...@@ -1361,6 +1362,8 @@ class CannedChecksUnittest(PresubmitTestsBase):
input_api.tbr = False input_api.tbr = False
input_api.python_executable = 'pyyyyython' input_api.python_executable = 'pyyyyython'
input_api.platform = sys.platform input_api.platform = sys.platform
input_api.time = time
input_api.canned_checks = presubmit_canned_checks
return input_api return input_api
def testMembersChanged(self): def testMembersChanged(self):
...@@ -2157,6 +2160,44 @@ mac|success|blew ...@@ -2157,6 +2160,44 @@ mac|success|blew
self.checkstdout( self.checkstdout(
'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) '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__': if __name__ == '__main__':
import unittest import unittest
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment