11import pytest
22import tempfile
33import os .path
4+ import pathlib
5+ import stat
6+
7+ from pytest_mock import MockerFixture
48
59import simvue .utilities as sv_util
610
@@ -19,3 +23,37 @@ def test_calculate_hash(is_file: bool, hash: str) -> None:
1923 assert sv_util .calculate_sha256 (filename = out_file , is_file = is_file ) == hash
2024 else :
2125 assert sv_util .calculate_sha256 (filename = "temp.txt" , is_file = is_file ) == hash
26+
27+ @pytest .mark .config
28+ @pytest .mark .parametrize (
29+ "user_area" , (True , False ),
30+ ids = ("permitted_dir" , "out_of_user_area" )
31+ )
32+ def test_find_first_file (user_area : bool , monkeypatch : pytest .MonkeyPatch , mocker : MockerFixture ) -> None :
33+ # Deactivate the server checks for this test
34+ monkeypatch .setenv ("SIMVUE_NO_SERVER_CHECK" , "True" )
35+ monkeypatch .delenv ("SIMVUE_TOKEN" , False )
36+ monkeypatch .delenv ("SIMVUE_URL" , False )
37+
38+
39+ with tempfile .TemporaryDirectory () as temp_d :
40+ _path = pathlib .Path (temp_d )
41+ _path_sub = _path .joinpath ("level_0" )
42+ _path_sub .mkdir ()
43+
44+ for i in range (1 , 5 ):
45+ _path_sub = _path_sub .joinpath (f"level_{ i } " )
46+ _path_sub .mkdir ()
47+ mocker .patch ("pathlib.Path.cwd" , lambda * _ : _path_sub )
48+
49+ if user_area :
50+ _path .joinpath ("level_0" ).joinpath ("simvue.toml" ).touch ()
51+ _path .chmod (stat .S_IXUSR )
52+ _result = sv_util .find_first_instance_of_file ("simvue.toml" , check_user_space = False )
53+ else :
54+ _path .chmod (stat .S_IXUSR )
55+ _result = sv_util .find_first_instance_of_file ("simvue.toml" , check_user_space = False ) is None
56+
57+ _path .chmod (stat .S_IRWXU )
58+ assert _result
59+
0 commit comments