From 46670598aac52af2ce3972830412a439991613f5 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 18 May 2015 15:30:58 -0500 Subject: [PATCH] Add interpreter check. Fixes #1 --- ansible_testing/modules.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ansible_testing/modules.py b/ansible_testing/modules.py index e86e01ff828..cca54d26324 100644 --- a/ansible_testing/modules.py +++ b/ansible_testing/modules.py @@ -72,10 +72,10 @@ class ModuleValidator(Validator): self.name, _ = os.path.splitext(self.basename) with open(path) as f: - text = f.read() - self.length = len(text.splitlines()) + self.text = f.read() + self.length = len(self.text.splitlines()) try: - self.ast = ast.parse(text) + self.ast = ast.parse(self.text) except: self.ast = None @@ -99,6 +99,10 @@ class ModuleValidator(Validator): return False return True + def _check_interpreter(self): + if not self.text.startswith('#!/usr/bin/python'): + self.errors.append('Interpreter line is not "#!/usr/bin/python"') + def _find_module_utils(self): linenos = [] for child in self.ast.body: @@ -208,6 +212,7 @@ class ModuleValidator(Validator): self.warnings.append('No RETURN provided') if not self._just_docs(): + self._check_interpreter() module_utils = self._find_module_utils() main = self._find_main_call() for mu in module_utils: