Debian Codegraph @

ansible_collections/amazon/aws/tests/unit/plugins/modules/conftest.py

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