Skip to content

Commit

Permalink
ansible-test - Fix traceback in validate-modules test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclay committed Dec 6, 2021
1 parent 33a8d06 commit 41ee4a5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
@@ -0,0 +1,2 @@
bugfixes:
- ansible-test - Fix traceback in the ``validate-modules`` sanity test when testing an Ansible module without any callables.
@@ -0,0 +1,23 @@
#!/usr/bin/python
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type

DOCUMENTATION = '''
module: no_callable
short_description: No callale test module
description: No callable test module.
author:
- Ansible Core Team
'''

EXAMPLES = '''#'''
RETURN = ''''''

from ansible.module_utils.basic import AnsibleModule


if __name__ == '__main__':
module = AnsibleModule(argument_spec=dict())
module.exit_json()
Expand Up @@ -606,7 +606,7 @@ def _get_first_callable(self):
if isinstance(child, (ast.FunctionDef, ast.ClassDef)):
linenos.append(child.lineno)

return min(linenos)
return min(linenos) if linenos else None

def _find_has_import(self):
for child in self.ast.body:
Expand Down Expand Up @@ -2179,7 +2179,7 @@ def validate(self):
self._find_rejectlist_imports()
self._find_module_utils()
self._find_has_import()
first_callable = self._get_first_callable()
first_callable = self._get_first_callable() or 1000000 # use a bogus "high" line number if no callable exists
self._ensure_imports_below_docs(doc_info, first_callable)
self._check_for_subprocess()
self._check_for_os_call()
Expand Down

0 comments on commit 41ee4a5

Please sign in to comment.