| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |