From 8a754e0858d922e955e71b253c139e071ecec432 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 18:04:21 +0200 Subject: Adding upstream version 2.14.3. Signed-off-by: Daniel Baumann --- test/units/test_constants.py | 94 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 test/units/test_constants.py (limited to 'test/units/test_constants.py') diff --git a/test/units/test_constants.py b/test/units/test_constants.py new file mode 100644 index 0000000..a206d23 --- /dev/null +++ b/test/units/test_constants.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- +# (c) 2017 Toshio Kuratomi +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import pwd +import os + +import pytest + +from ansible import constants +from ansible.module_utils.six import StringIO +from ansible.module_utils.six.moves import configparser +from ansible.module_utils._text import to_text + + +@pytest.fixture +def cfgparser(): + CFGDATA = StringIO(""" +[defaults] +defaults_one = 'data_defaults_one' + +[level1] +level1_one = 'data_level1_one' + """) + p = configparser.ConfigParser() + p.readfp(CFGDATA) + return p + + +@pytest.fixture +def user(): + user = {} + user['uid'] = os.geteuid() + + pwd_entry = pwd.getpwuid(user['uid']) + user['username'] = pwd_entry.pw_name + user['home'] = pwd_entry.pw_dir + + return user + + +@pytest.fixture +def cfg_file(): + data = '/ansible/test/cfg/path' + old_cfg_file = constants.CONFIG_FILE + constants.CONFIG_FILE = os.path.join(data, 'ansible.cfg') + yield data + + constants.CONFIG_FILE = old_cfg_file + + +@pytest.fixture +def null_cfg_file(): + old_cfg_file = constants.CONFIG_FILE + del constants.CONFIG_FILE + yield + + constants.CONFIG_FILE = old_cfg_file + + +@pytest.fixture +def cwd(): + data = '/ansible/test/cwd/' + old_cwd = os.getcwd + os.getcwd = lambda: data + + old_cwdu = None + if hasattr(os, 'getcwdu'): + old_cwdu = os.getcwdu + os.getcwdu = lambda: to_text(data) + + yield data + + os.getcwd = old_cwd + if hasattr(os, 'getcwdu'): + os.getcwdu = old_cwdu -- cgit v1.2.3