Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: recipe_engine/lint_test.py

Issue 1421843006: Add simple depends_on API. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Remove old expectation, move tests to their own folder. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « recipe_engine/doc.py ('k') | recipe_engine/loader.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Tests that recipes are on their best behavior. 6 """Tests that recipes are on their best behavior.
7 7
8 Checks that recipes only import modules from a whitelist. Imports are 8 Checks that recipes only import modules from a whitelist. Imports are
9 generally not safe in recipes if they depend on the platform, since 9 generally not safe in recipes if they depend on the platform, since
10 e.g. you can run a recipe simulation for a Windows recipe on Linux. 10 e.g. you can run a recipe simulation for a Windows recipe on Linux.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 module_name = val.__name__ 54 module_name = val.__name__
55 for pattern in whitelist: 55 for pattern in whitelist:
56 if pattern.match(val.__name__): 56 if pattern.match(val.__name__):
57 break 57 break
58 else: 58 else:
59 yield ('In %s:\n' 59 yield ('In %s:\n'
60 ' Non-whitelisted import of %s' % 60 ' Non-whitelisted import of %s' %
61 (recipe_path, module_name)) 61 (recipe_path, module_name))
62 62
63 63
64 def main(package_deps, whitelist=[]): 64 def main(universe, whitelist=[]):
65 from . import loader 65 from . import loader
66 from . import package 66 from . import package
67 67
68 whitelist = map(re.compile, MODULES_WHITELIST + whitelist) 68 whitelist = map(re.compile, MODULES_WHITELIST + whitelist)
69 universe = loader.RecipeUniverse(package_deps)
70 69
71 errors = [] 70 errors = []
72 for recipe_path, recipe_name in universe.loop_over_recipes(): 71 for recipe_path, recipe_name in universe.loop_over_recipes():
73 errors.extend(ImportsTest(recipe_path, recipe_name, whitelist, universe)) 72 errors.extend(ImportsTest(recipe_path, recipe_name, whitelist, universe))
74 73
75 if errors: 74 if errors:
76 raise TestFailure('\n'.join(map(str, errors))) 75 raise TestFailure('\n'.join(map(str, errors)))
77 76
OLDNEW
« no previous file with comments | « recipe_engine/doc.py ('k') | recipe_engine/loader.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698