1919)
2020from fmu .settings import ProjectFMUDirectory
2121from fmu .settings ._fmu_dir import UserFMUDirectory
22- from fmu .settings ._init import init_fmu_directory , init_user_fmu_directory
22+ from fmu .settings ._init import (
23+ REQUIRED_FMU_PROJECT_SUBDIRS ,
24+ init_fmu_directory ,
25+ init_user_fmu_directory ,
26+ )
2327from pytest import MonkeyPatch
2428
2529from fmu_settings_api .__main__ import app
2933from fmu_settings_api .session import SessionManager , add_fmu_project_to_session
3034
3135
36+ @pytest .fixture
37+ def make_fmu_project_root () -> Callable [[Path ], Path ]:
38+ """Return a helper that prepares a valid FMU project root for a test path."""
39+
40+ def _make_fmu_project_root (path : Path ) -> Path :
41+ path .mkdir (parents = True , exist_ok = True )
42+ for dir_name in REQUIRED_FMU_PROJECT_SUBDIRS :
43+ (path / dir_name ).mkdir (parents = True , exist_ok = True )
44+ return path
45+
46+ return _make_fmu_project_root
47+
48+
49+ @pytest .fixture
50+ def init_project_fmu_directory (
51+ make_fmu_project_root : Callable [[Path ], Path ],
52+ ) -> Callable [[Path ], ProjectFMUDirectory ]:
53+ """Return a helper that initializes a valid project .fmu directory."""
54+
55+ def _init_project_fmu_directory (path : Path ) -> ProjectFMUDirectory :
56+ return init_fmu_directory (make_fmu_project_root (path ))
57+
58+ return _init_project_fmu_directory
59+
60+
3261@pytest .fixture
3362def create_stratigraphic_unit () -> Callable [..., StratigraphicUnit ]:
3463 """Fixture that returns a helper function to create StratigraphicUnit.
@@ -153,9 +182,11 @@ def mock_token() -> str:
153182
154183
155184@pytest .fixture
156- def fmu_dir (tmp_path : Path ) -> ProjectFMUDirectory :
185+ def fmu_dir (
186+ tmp_path : Path , make_fmu_project_root : Callable [[Path ], Path ]
187+ ) -> ProjectFMUDirectory :
157188 """Creates a .fmu directory in a tmp path."""
158- return init_fmu_directory (tmp_path )
189+ return init_fmu_directory (make_fmu_project_root ( tmp_path ) )
159190
160191
161192@pytest .fixture
@@ -193,7 +224,11 @@ def user_fmu_dir_no_permissions(fmu_dir_path: Path) -> Generator[Path]:
193224
194225
195226@pytest .fixture
196- def tmp_path_mocked_home (tmp_path : Path , monkeypatch : MonkeyPatch ) -> Generator [Path ]:
227+ def tmp_path_mocked_home (
228+ tmp_path : Path ,
229+ monkeypatch : MonkeyPatch ,
230+ make_fmu_project_root : Callable [[Path ], Path ],
231+ ) -> Generator [Path ]:
197232 """Mocks Path.home() for routes that depend on UserFMUDirectory.
198233
199234 This mocks the user .fmu into tmp_path/home/.fmu.
@@ -203,6 +238,7 @@ def tmp_path_mocked_home(tmp_path: Path, monkeypatch: MonkeyPatch) -> Generator[
203238 """
204239 mocked_user_home = tmp_path / "home"
205240 mocked_user_home .mkdir ()
241+ make_fmu_project_root (tmp_path )
206242 with patch ("pathlib.Path.home" , return_value = mocked_user_home ):
207243 monkeypatch .chdir (tmp_path )
208244 yield tmp_path
0 commit comments