Skip to content

Commit 79437b2

Browse files
committed
🧪 Add test against recursion when config search
1 parent 2e24ac0 commit 79437b2

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

‎tests/functional/test_utilities.py‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ def test_calculate_hash(is_file: bool, hash: str) -> None:
2929
"user_area", (True, False),
3030
ids=("permitted_dir", "out_of_user_area")
3131
)
32-
def test_find_first_file(user_area: bool, monkeypatch: pytest.MonkeyPatch, mocker: MockerFixture) -> None:
32+
def test_find_first_file_search(user_area: bool, monkeypatch: pytest.MonkeyPatch, mocker: MockerFixture) -> None:
3333
# Deactivate the server checks for this test
3434
monkeypatch.setenv("SIMVUE_NO_SERVER_CHECK", "True")
3535
monkeypatch.delenv("SIMVUE_TOKEN", False)
3636
monkeypatch.delenv("SIMVUE_URL", False)
3737

38-
3938
with tempfile.TemporaryDirectory() as temp_d:
4039
_path = pathlib.Path(temp_d)
4140
_path_sub = _path.joinpath("level_0")
@@ -57,3 +56,32 @@ def test_find_first_file(user_area: bool, monkeypatch: pytest.MonkeyPatch, mocke
5756
_path.chmod(stat.S_IRWXU)
5857
assert _result
5958

59+
@pytest.mark.config
60+
def test_find_first_file_at_root(monkeypatch: pytest.MonkeyPatch, mocker: MockerFixture) -> None:
61+
# Deactivate the server checks for this test
62+
monkeypatch.setenv("SIMVUE_NO_SERVER_CHECK", "True")
63+
monkeypatch.delenv("SIMVUE_TOKEN", False)
64+
monkeypatch.delenv("SIMVUE_URL", False)
65+
66+
_orig_func = pathlib.Path.parent
67+
68+
@property
69+
def _returns_self(self):
70+
return self
71+
72+
73+
with tempfile.TemporaryDirectory() as temp_d:
74+
_path = pathlib.Path(temp_d)
75+
_path_sub = _path.joinpath("level_0")
76+
_path_sub.mkdir()
77+
_path.joinpath("level_0").joinpath("simvue.toml").touch()
78+
79+
for i in range(1, 5):
80+
_path_sub = _path_sub.joinpath(f"level_{i}")
81+
_path_sub.mkdir()
82+
mocker.patch("pathlib.Path.parent", _returns_self)
83+
mocker.patch("pathlib.Path.cwd", lambda *_: _path_sub)
84+
85+
assert not sv_util.find_first_instance_of_file("simvue.toml", check_user_space=False)
86+
87+

0 commit comments

Comments
 (0)