Debian Codegraph @

ansible_collections/cisco/nxos/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 from __future__ import absolute_import, division, print_function
4
5
6 __metaclass__ = type
7
8 import json
9
10 import pytest
11
12 from ansible.module_utils._text import to_bytes
13 from ansible.module_utils.common._collections_compat import MutableMapping
14
15
16 string_types = (str,)
17
18
19 @pytest.fixture
20 def patch_ansible_module(request, mocker):
21 if isinstance(request.param, string_types):
22 args = request.param
23 elif isinstance(request.param, MutableMapping):
24 if "ANSIBLE_MODULE_ARGS" not in request.param:
25 request.param = {"ANSIBLE_MODULE_ARGS": request.param}
26 if "_ansible_remote_tmp" not in request.param["ANSIBLE_MODULE_ARGS"]:
27 request.param["ANSIBLE_MODULE_ARGS"]["_ansible_remote_tmp"] = "/tmp"
28 if "_ansible_keep_remote_files" not in request.param["ANSIBLE_MODULE_ARGS"]:
29 request.param["ANSIBLE_MODULE_ARGS"]["_ansible_keep_remote_files"] = False
30 args = json.dumps(request.param)
31 else:
32 raise Exception("Malformed data to the patch_ansible_module pytest fixture")
33
34 mocker.patch("ansible.module_utils.basic._ANSIBLE_ARGS", to_bytes(args))