diff options
Diffstat (limited to 'test/units/config/manager/test_find_ini_config_file.py')
-rw-r--r-- | test/units/config/manager/test_find_ini_config_file.py | 67 |
1 files changed, 27 insertions, 40 deletions
diff --git a/test/units/config/manager/test_find_ini_config_file.py b/test/units/config/manager/test_find_ini_config_file.py index df411388..e67eecd9 100644 --- a/test/units/config/manager/test_find_ini_config_file.py +++ b/test/units/config/manager/test_find_ini_config_file.py @@ -13,7 +13,7 @@ import stat import pytest from ansible.config.manager import find_ini_config_file -from ansible.module_utils._text import to_text +from ansible.module_utils.common.text.converters import to_text real_exists = os.path.exists real_isdir = os.path.isdir @@ -28,22 +28,17 @@ cfg_in_homedir = os.path.expanduser('~/.ansible.cfg') @pytest.fixture -def setup_env(request): +def setup_env(request, monkeypatch): cur_config = os.environ.get('ANSIBLE_CONFIG', None) cfg_path = request.param[0] if cfg_path is None and cur_config: - del os.environ['ANSIBLE_CONFIG'] + monkeypatch.delenv('ANSIBLE_CONFIG') else: - os.environ['ANSIBLE_CONFIG'] = request.param[0] + monkeypatch.setenv('ANSIBLE_CONFIG', request.param[0]) yield - if cur_config is None and cfg_path: - del os.environ['ANSIBLE_CONFIG'] - else: - os.environ['ANSIBLE_CONFIG'] = cur_config - @pytest.fixture def setup_existing_files(request, monkeypatch): @@ -54,10 +49,8 @@ def setup_existing_files(request, monkeypatch): return False def _os_access(path, access): - if to_text(path) in (request.param[0]): - return True - else: - return False + assert to_text(path) in (request.param[0]) + return True # Enable user and system dirs so that we know cwd takes precedence monkeypatch.setattr("os.path.exists", _os_path_exists) @@ -162,13 +155,11 @@ class TestFindIniFile: real_stat = os.stat def _os_stat(path): - if path == working_dir: - from posix import stat_result - stat_info = list(real_stat(path)) - stat_info[stat.ST_MODE] |= stat.S_IWOTH - return stat_result(stat_info) - else: - return real_stat(path) + assert path == working_dir + from posix import stat_result + stat_info = list(real_stat(path)) + stat_info[stat.ST_MODE] |= stat.S_IWOTH + return stat_result(stat_info) monkeypatch.setattr('os.stat', _os_stat) @@ -187,13 +178,11 @@ class TestFindIniFile: real_stat = os.stat def _os_stat(path): - if path == working_dir: - from posix import stat_result - stat_info = list(real_stat(path)) - stat_info[stat.ST_MODE] |= stat.S_IWOTH - return stat_result(stat_info) - else: - return real_stat(path) + assert path == working_dir + from posix import stat_result + stat_info = list(real_stat(path)) + stat_info[stat.ST_MODE] |= stat.S_IWOTH + return stat_result(stat_info) monkeypatch.setattr('os.stat', _os_stat) @@ -215,14 +204,14 @@ class TestFindIniFile: real_stat = os.stat def _os_stat(path): - if path == working_dir: - from posix import stat_result - stat_info = list(real_stat(path)) - stat_info[stat.ST_MODE] |= stat.S_IWOTH - return stat_result(stat_info) - else: + if path != working_dir: return real_stat(path) + from posix import stat_result + stat_info = list(real_stat(path)) + stat_info[stat.ST_MODE] |= stat.S_IWOTH + return stat_result(stat_info) + monkeypatch.setattr('os.stat', _os_stat) warnings = set() @@ -240,13 +229,11 @@ class TestFindIniFile: real_stat = os.stat def _os_stat(path): - if path == working_dir: - from posix import stat_result - stat_info = list(real_stat(path)) - stat_info[stat.ST_MODE] |= stat.S_IWOTH - return stat_result(stat_info) - else: - return real_stat(path) + assert path == working_dir + from posix import stat_result + stat_info = list(real_stat(path)) + stat_info[stat.ST_MODE] |= stat.S_IWOTH + return stat_result(stat_info) monkeypatch.setattr('os.stat', _os_stat) |