17
17
from pathlib import Path
18
18
19
19
20
- ARGS = Namespace (
21
- isolation_mode = "cfg" ,
22
- log_append = False ,
23
- log_file = "/dev/null" ,
24
- log_level = "warning" ,
25
- verbose = 0 ,
26
- )
27
-
28
-
29
20
@pytest .fixture (name = "cli" )
30
21
def init_cli (tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> Cli :
31
22
"""Fixture to mock the CLI for testing.
@@ -47,8 +38,16 @@ def init_cli(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Cli:
47
38
monkeypatch .chdir (cwd )
48
39
monkeypatch .delenv ("ANSIBLE_CONFIG" , raising = False )
49
40
41
+ args = Namespace (
42
+ isolation_mode = "cfg" ,
43
+ log_append = False ,
44
+ log_file = "/dev/null" ,
45
+ log_level = "warning" ,
46
+ verbose = 0 ,
47
+ )
48
+
50
49
cli = Cli ()
51
- cli .args = ARGS
50
+ cli .args = args
52
51
cli .acfg_cwd = AnsibleCfg (path = cwd / "ansible.cfg" )
53
52
cli .acfg_home = AnsibleCfg (path = home / "ansible.cfg" )
54
53
cli .acfg_system = AnsibleCfg (path = system / "ansible.cfg" )
@@ -123,6 +122,9 @@ def test_acfg_home_modified(cli: Cli) -> None:
123
122
assert cli .isolation_check () is True
124
123
assert test_path .read_text () == expected
125
124
assert cli .acfg_trusted == test_path
125
+ stat = cli .acfg_trusted .stat ().st_mtime
126
+ assert cli .isolation_check () is True
127
+ assert cli .acfg_trusted .stat ().st_mtime == stat
126
128
127
129
128
130
def test_acfg_system_ok (cli : Cli ) -> None :
@@ -162,21 +164,14 @@ def test_invalid_isolation_mode(cli: Cli) -> None:
162
164
assert cli .acfg_trusted is None
163
165
164
166
165
- def test_isolation_cfg_with_env_var (
166
- monkeypatch : pytest .MonkeyPatch ,
167
- tmp_path : Path ,
168
- ) -> None :
167
+ def test_isolation_cfg_with_env_var (cli : Cli , monkeypatch : pytest .MonkeyPatch ) -> None :
169
168
"""Test isolation_cfg method with ANSIBLE_CONFIG environment variable.
170
169
171
170
Args:
171
+ cli: A Cli instance from a fixture
172
172
monkeypatch: Pytest fixture for monkey patching.
173
- tmp_path: Pytest fixture for temporary file paths.
174
173
"""
175
- cli = Cli ()
176
- cli .args = ARGS
177
- cli .init_output ()
178
-
179
- monkeypatch .setenv ("ANSIBLE_CONFIG" , str (tmp_path / "ansible.cfg" ))
174
+ monkeypatch .setenv ("ANSIBLE_CONFIG" , str (cli .acfg_cwd .path ))
180
175
181
176
assert cli .isolation_check () is False
182
177
assert cli .acfg_trusted is None
0 commit comments