| Index: scripts/slave/unittests/recipe_lint_test.py
|
| diff --git a/scripts/slave/unittests/recipe_lint_test.py b/scripts/slave/unittests/recipe_lint_test.py
|
| index 5e98dc1223a9283a58c0f6fc807b954383e6a8fc..258cce4d9267dcd2828953cf5bcea4eb747106f8 100755
|
| --- a/scripts/slave/unittests/recipe_lint_test.py
|
| +++ b/scripts/slave/unittests/recipe_lint_test.py
|
| @@ -1,81 +1,24 @@
|
| #!/usr/bin/env python
|
| -# Copyright 2015 The Chromium Authors. All rights reserved.
|
| +# Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| -"""Tests that recipes are on their best behavior.
|
| +import os
|
| +import sys
|
|
|
| -Checks that recipes only import modules from a whitelist. Imports are
|
| -generally not safe in recipes if they depend on the platform, since
|
| -e.g. you can run a recipe simulation for a Windows recipe on Linux.
|
| -"""
|
| +import test_env # pylint: disable=W0403,W0611
|
|
|
| -import re
|
| -import types
|
| -
|
| -import test_env # pylint: disable=W0611,W0403
|
| -
|
| -from slave import recipe_loader
|
| -
|
| -
|
| -MODULES_WHITELIST = map(re.compile, [
|
| - r'base64',
|
| - r'collections',
|
| - r'datetime',
|
| - r'json',
|
| - r'math',
|
| - r're',
|
| - r'urlparse',
|
| -
|
| - r'slave\.recipe_api',
|
| +from recipe_engine import lint_test
|
| +from slave import recipe_universe
|
|
|
| +MODULES_WHITELIST = [
|
| # TODO(luqui): Move skia modules into recipe resources
|
| r'common\.skia\..*',
|
| r'slave\.skia\..*',
|
|
|
| # TODO(luqui): Move cros modules into recipe resources
|
| r'common\.cros_chromite',
|
| -])
|
| -
|
| -
|
| -class ImportViolationError(Exception):
|
| - pass
|
| -
|
| -
|
| -class TestFailure(Exception):
|
| - pass
|
| -
|
| -
|
| -def ImportsTest(recipe_path, recipe_name, universe):
|
| - """Tests that recipe_name only uses allowed imports.
|
| -
|
| - Returns a list of errors, or an empty list if there are no errors (duh).
|
| - """
|
| -
|
| - recipe = universe.load_recipe(recipe_name)
|
| - for attr in dir(recipe):
|
| - val = getattr(recipe, attr)
|
| - if isinstance(val, types.ModuleType):
|
| - module_name = val.__name__
|
| - for pattern in MODULES_WHITELIST:
|
| - if pattern.match(val.__name__):
|
| - break
|
| - else:
|
| - yield ('In %s:\n'
|
| - ' Non-whitelisted import of %s' %
|
| - (recipe_path, module_name))
|
| -
|
| -
|
| -def MainTest():
|
| - universe = recipe_loader.RecipeUniverse()
|
| -
|
| - errors = []
|
| - for recipe_path, recipe_name in recipe_loader.loop_over_recipes():
|
| - errors.extend(ImportsTest(recipe_path, recipe_name, universe))
|
| -
|
| - if errors:
|
| - raise TestFailure('\n'.join(map(str, errors)))
|
| -
|
| +]
|
|
|
| if __name__ == '__main__':
|
| - MainTest()
|
| + lint_test.main(recipe_universe.get_universe(), whitelist=MODULES_WHITELIST)
|
|
|