Expanding unit tests for module_utils/basic.py

This commit is contained in:
James Cammarata 2016-03-01 13:52:50 -05:00
parent 70e7be0346
commit e011f52557
3 changed files with 348 additions and 38 deletions

View file

@ -185,7 +185,7 @@ except ImportError:
pass
try:
from ast import literal_eval as _literal_eval
from ast import literal_eval
except ImportError:
# a replacement for literal_eval that works with python 2.4. from:
# https://mail.python.org/pipermail/python-list/2009-September/551880.html
@ -193,7 +193,7 @@ except ImportError:
# ast.py
from compiler import ast, parse
def _literal_eval(node_or_string):
def literal_eval(node_or_string):
"""
Safely evaluate an expression node or a string containing a Python
expression. The string or node provided may only consist of the following
@ -223,6 +223,7 @@ except ImportError:
raise ValueError('malformed string')
return _convert(node_or_string)
_literal_eval = literal_eval
FILE_COMMON_ARGUMENTS=dict(
src = dict(),
@ -1254,9 +1255,9 @@ class AnsibleModule(object):
try:
result = None
if not locals:
result = _literal_eval(str)
result = literal_eval(str)
else:
result = _literal_eval(str, None, locals)
result = literal_eval(str, None, locals)
if include_exceptions:
return (result, None)
else:
@ -1749,7 +1750,7 @@ class AnsibleModule(object):
prefix=".ansible_tmp", dir=dest_dir, suffix=dest_file)
except (OSError, IOError):
e = get_exception()
self.fail_json(msg='The destination directory (%s) is not writable by the current user.' % dest_dir)
self.fail_json(msg='The destination directory (%s) is not writable by the current user. Error was: %s' % (dest_dir, e))
try: # leaves tmp file behind when sudo and not root
if switched_user and os.getuid() != 0: