Commit 45cabf37 authored by Zhiling Huang's avatar Zhiling Huang Committed by Commit Bot

Run pydeps check only in src.

Bug: 803245
Change-Id: I645e82663991cd012ced5f19a056d08bbc2c797d
Reviewed-on: https://chromium-review.googlesource.com/952281Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Zhiling Huang <hzl@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542297}
parent cdcb0262
...@@ -2180,15 +2180,21 @@ def _CheckPydepsNeedsUpdating(input_api, output_api, checker_for_tests=None): ...@@ -2180,15 +2180,21 @@ def _CheckPydepsNeedsUpdating(input_api, output_api, checker_for_tests=None):
results = [] results = []
# First, check for new / deleted .pydeps. # First, check for new / deleted .pydeps.
for f in input_api.AffectedFiles(include_deletes=True): for f in input_api.AffectedFiles(include_deletes=True):
if f.LocalPath().endswith('.pydeps'): # Check whether we are running the presubmit check for a file in src.
if f.Action() == 'D' and f.LocalPath() in _ALL_PYDEPS_FILES: # f.LocalPath is relative to repo (src, or internal repo).
results.append(output_api.PresubmitError( # os_path.exists is relative to src repo.
'Please update _ALL_PYDEPS_FILES within //PRESUBMIT.py to ' # Therefore if os_path.exists is true, it means f.LocalPath is relative
'remove %s' % f.LocalPath())) # to src and we can conclude that the pydeps is in src.
elif f.Action() != 'D' and f.LocalPath() not in _ALL_PYDEPS_FILES: if input_api.os_path.exists(f.LocalPath()):
results.append(output_api.PresubmitError( if f.LocalPath().endswith('.pydeps'):
'Please update _ALL_PYDEPS_FILES within //PRESUBMIT.py to ' if f.Action() == 'D' and f.LocalPath() in _ALL_PYDEPS_FILES:
'include %s' % f.LocalPath())) results.append(output_api.PresubmitError(
'Please update _ALL_PYDEPS_FILES within //PRESUBMIT.py to '
'remove %s' % f.LocalPath()))
elif f.Action() != 'D' and f.LocalPath() not in _ALL_PYDEPS_FILES:
results.append(output_api.PresubmitError(
'Please update _ALL_PYDEPS_FILES within //PRESUBMIT.py to '
'include %s' % f.LocalPath()))
if results: if results:
return results return results
......
...@@ -656,10 +656,21 @@ class PydepsNeedsUpdatingTest(unittest.TestCase): ...@@ -656,10 +656,21 @@ class PydepsNeedsUpdatingTest(unittest.TestCase):
MockAffectedFile('new.pydeps', [], action='A'), MockAffectedFile('new.pydeps', [], action='A'),
] ]
self.mock_input_api.CreateMockFileInPath(
[x.LocalPath() for x in self.mock_input_api.AffectedFiles(
include_deletes=True)])
results = self._RunCheck() results = self._RunCheck()
self.assertEqual(1, len(results)) self.assertEqual(1, len(results))
self.assertTrue('PYDEPS_FILES' in str(results[0])) self.assertTrue('PYDEPS_FILES' in str(results[0]))
def testPydepNotInSrc(self):
self.mock_input_api.files = [
MockAffectedFile('new.pydeps', [], action='A'),
]
self.mock_input_api.CreateMockFileInPath([])
results = self._RunCheck()
self.assertEqual(0, len(results))
def testRemovedPydep(self): def testRemovedPydep(self):
# PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android.
if self.mock_input_api.platform != 'linux2': if self.mock_input_api.platform != 'linux2':
...@@ -668,7 +679,9 @@ class PydepsNeedsUpdatingTest(unittest.TestCase): ...@@ -668,7 +679,9 @@ class PydepsNeedsUpdatingTest(unittest.TestCase):
self.mock_input_api.files = [ self.mock_input_api.files = [
MockAffectedFile(PRESUBMIT._ALL_PYDEPS_FILES[0], [], action='D'), MockAffectedFile(PRESUBMIT._ALL_PYDEPS_FILES[0], [], action='D'),
] ]
self.mock_input_api.CreateMockFileInPath(
[x.LocalPath() for x in self.mock_input_api.AffectedFiles(
include_deletes=True)])
results = self._RunCheck() results = self._RunCheck()
self.assertEqual(1, len(results)) self.assertEqual(1, len(results))
self.assertTrue('PYDEPS_FILES' in str(results[0])) self.assertTrue('PYDEPS_FILES' in str(results[0]))
......
...@@ -51,6 +51,7 @@ class MockCannedChecks(object): ...@@ -51,6 +51,7 @@ class MockCannedChecks(object):
return errors return errors
class MockInputApi(object): class MockInputApi(object):
"""Mock class for the InputApi class. """Mock class for the InputApi class.
...@@ -75,6 +76,9 @@ class MockInputApi(object): ...@@ -75,6 +76,9 @@ class MockInputApi(object):
self.change = MockChange([]) self.change = MockChange([])
self.presubmit_local_path = os.path.dirname(__file__) self.presubmit_local_path = os.path.dirname(__file__)
def CreateMockFileInPath(self, f_list):
self.os_path.exists = lambda x: x in f_list
def AffectedFiles(self, file_filter=None, include_deletes=False): def AffectedFiles(self, file_filter=None, include_deletes=False):
for file in self.files: for file in self.files:
if file_filter and not file_filter(file): if file_filter and not file_filter(file):
......
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