Commit ecee74ca authored by Aaron Gable's avatar Aaron Gable Committed by Commit Bot

presubmit: don't die when skipping unknown checks

If someone doesn't want to run a check, and that check doesn't
exist... great! We won't be running that check anyway.

R=iannucci

Bug: 770408, 828154
Change-Id: I74478cac9988e21a1fadfb2c9d23dac1697aaa46
Reviewed-on: https://chromium-review.googlesource.com/991093Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Reviewed-by: 's avatarSean McCullough <seanmccullough@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
parent 81b26429
......@@ -1513,17 +1513,14 @@ def load_files(options, args):
return change_class, files
class NonexistantCannedCheckFilter(Exception):
pass
@contextlib.contextmanager
def canned_check_filter(method_names):
filtered = {}
try:
for method_name in method_names:
if not hasattr(presubmit_canned_checks, method_name):
raise NonexistantCannedCheckFilter(method_name)
logging.warn('Skipping unknown "canned" check %s' % method_name)
continue
filtered[method_name] = getattr(presubmit_canned_checks, method_name)
setattr(presubmit_canned_checks, method_name, lambda *_a, **_kw: [])
yield
......@@ -1692,10 +1689,6 @@ def main(argv=None):
gerrit_obj,
options.dry_run)
return not results.should_continue()
except NonexistantCannedCheckFilter, e:
print >> sys.stderr, (
'Attempted to skip nonexistent canned presubmit check: %s' % e.message)
return 2
except PresubmitFailure, e:
print >> sys.stderr, e
print >> sys.stderr, 'Maybe your depot_tools is out of date?'
......
......@@ -175,7 +175,7 @@ class PresubmitUnittest(PresubmitTestsBase):
'AffectedFile', 'Change', 'DoPostUploadExecuter', 'DoPresubmitChecks',
'GetPostUploadExecuter', 'GitAffectedFile', 'CallCommand', 'CommandData',
'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'main',
'NonexistantCannedCheckFilter', 'OutputApi', 'ParseFiles',
'OutputApi', 'ParseFiles',
'PresubmitFailure', 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs',
'ast', 'auth', 'cPickle', 'cpplint', 'cStringIO', 'contextlib',
'canned_check_filter', 'fix_encoding', 'fnmatch', 'gclient_utils',
......@@ -198,15 +198,6 @@ class PresubmitUnittest(PresubmitTestsBase):
self.assertEqual(canned.CheckOwners(None, None), [])
self.assertEqual(canned.CheckOwners, orig)
def testCannedCheckFilterFail(self):
canned = presubmit.presubmit_canned_checks
orig = canned.CheckOwners
def failAttempt():
with presubmit.canned_check_filter(['CheckOwners', 'Spazfleem']):
pass
self.assertRaises(presubmit.NonexistantCannedCheckFilter, failAttempt)
self.assertEqual(canned.CheckOwners, orig)
def testListRelevantPresubmitFiles(self):
files = [
'blat.cc',
......
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