Debian Codegraph @

ansible_collections/cisco/ios/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 @pytest.fixture
17 def patch_ansible_module(request, mocker):
18 if isinstance(request.param, str):
19 args = request.param
20 elif isinstance(request.param, MutableMapping):
21 if "ANSIBLE_MODULE_ARGS" not in request.param:
22 request.param = {"ANSIBLE_MODULE_ARGS": request.param}
23 if "_ansible_remote_tmp" not in request.param["ANSIBLE_MODULE_ARGS"]:
24 request.param["ANSIBLE_MODULE_ARGS"]["_ansible_remote_tmp"] = "/tmp"
25 if "_ansible_keep_remote_files" not in request.param["ANSIBLE_MODULE_ARGS"]:
26 request.param["ANSIBLE_MODULE_ARGS"]["_ansible_keep_remote_files"] = False
27 args = json.dumps(request.param)
28 else:
29 raise Exception("Malformed data to the patch_ansible_module pytest fixture")
30
31 mocker.patch("ansible.module_utils.basic._ANSIBLE_ARGS", to_bytes(args))