mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-20 09:21:24 -07:00
[stable-9] Unit tests: make set_module_args() a context manager, and remove copies of it in some tests (#9840)
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.
(cherry picked from commit a1781d09dd
)
This commit is contained in:
parent
9a6bd80613
commit
013fb9c006
80 changed files with 3745 additions and 3977 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue