You've already forked community.general
mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-27 20:21:52 +03:00
Unit tests: make set_module_args() a context manager, and remove copies of it in some tests (#9838)
Make set_module_args() a context manager, and remove copies of set_module_args(). Prepares for Data Tagging.
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import contextlib as _contextlib
|
||||
import json
|
||||
|
||||
from ansible_collections.community.general.tests.unit.compat import unittest
|
||||
@ -13,14 +14,16 @@ from ansible.module_utils import basic
|
||||
from ansible.module_utils.common.text.converters import to_bytes
|
||||
|
||||
|
||||
@_contextlib.contextmanager
|
||||
def set_module_args(args):
|
||||
if '_ansible_remote_tmp' not in args:
|
||||
args['_ansible_remote_tmp'] = '/tmp'
|
||||
if '_ansible_keep_remote_files' not in args:
|
||||
args['_ansible_keep_remote_files'] = False
|
||||
|
||||
args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
|
||||
basic._ANSIBLE_ARGS = to_bytes(args)
|
||||
serialized_args = to_bytes(json.dumps({'ANSIBLE_MODULE_ARGS': args}))
|
||||
with patch.object(basic, '_ANSIBLE_ARGS', serialized_args):
|
||||
yield
|
||||
|
||||
|
||||
class AnsibleExitJson(Exception):
|
||||
|
Reference in New Issue
Block a user