Debian Codegraph @

ansible_collections/community/vmware/tests/unit/modules/conftest.py

raw
1 # Copyright (c) 2017 Ansible Project
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3
4 from __future__ import absolute_import, division, print_function
5 __metaclass__ = type
6
7 import json
8
9 import pytest
10
11 from ansible.module_utils.common.text.converters import to_bytes
12 from collections.abc import MutableMapping
13
14
15 @pytest.fixture
16 def patch_ansible_module(request, mocker):
17 if isinstance(request.param, str):
18 args = request.param
19 elif isinstance(request.param, MutableMapping):
20 if 'ANSIBLE_MODULE_ARGS' not in request.param:
21 request.param = {'ANSIBLE_MODULE_ARGS': request.param}
22 if '_ansible_remote_tmp' not in request.param['ANSIBLE_MODULE_ARGS']:
23 request.param['ANSIBLE_MODULE_ARGS']['_ansible_remote_tmp'] = '/tmp'
24 if '_ansible_keep_remote_files' not in request.param['ANSIBLE_MODULE_ARGS']:
25 request.param['ANSIBLE_MODULE_ARGS']['_ansible_keep_remote_files'] = False
26 args = json.dumps(request.param)
27 else:
28 raise Exception('Malformed data to the patch_ansible_module pytest fixture')
29
30 mocker.patch('ansible.module_utils.basic._ANSIBLE_ARGS', to_bytes(args))