From b6b58c4a1a4ed29092298ce150ae242bb75d0e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20C=2E=20Riven=C3=A6s?= Date: Wed, 1 Jun 2022 11:21:10 +0200 Subject: [PATCH] Adjust settings in InitalizeCase --- src/fmu/dataio/dataio.py | 14 ++++++++++---- tests/test_units/test_initialize_case.py | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/fmu/dataio/dataio.py b/src/fmu/dataio/dataio.py index 5042cc022..f56f71654 100644 --- a/src/fmu/dataio/dataio.py +++ b/src/fmu/dataio/dataio.py @@ -724,8 +724,9 @@ class InitializeCase: # pylint: disable=too-few-public-methods FMU_GLOBAL_CONFIG pointing to a file is provided, then it will attempt to parse that file instead. rootfolder: To override the automatic and actual ``rootpath``. Absolute path to - the case root. If not provided (which is not recommended), the rootpath - will be attempted parsed from the file structure or by other means. + the case root, including case name. If not provided (which is not + recommended), the rootpath will be attempted parsed from the file structure + or by other means. casename: Name of case (experiment) caseuser: Username provided restart_from: ID of eventual restart @@ -778,8 +779,8 @@ def _establish_pwd_casepath(self): """ self._pwd = Path().absolute() - if self.rootfolder and self.casename: - self._casepath = self.rootfolder / self.casename + if self.rootfolder: + self._casepath = Path(self.rootfolder) else: logger.info("Emit UserWarning") warn( @@ -793,6 +794,11 @@ def _establish_pwd_casepath(self): logger.info("Set rootpath (case): %s", str(self._casepath)) def _check_already_metadata_or_create_folder(self, force=False) -> bool: + + if not self._casepath.exists(): + self._casepath.mkdir(parents=True, exist_ok=True) + logger.info("Created rootpath (case) %s", self._casepath) + metadata_path = self._casepath / "share/metadata" self._metafile = metadata_path / "fmu_case.yml" logger.info("The requested metafile is %s", self._metafile) diff --git a/tests/test_units/test_initialize_case.py b/tests/test_units/test_initialize_case.py index 3f56a6fd3..a415280a9 100644 --- a/tests/test_units/test_initialize_case.py +++ b/tests/test_units/test_initialize_case.py @@ -50,7 +50,7 @@ def test_inicase_pwd_basepath_explicit(fmurun, globalconfig2): logger.info("Casepath is %s", icase._casepath) - assert icase._casepath == myroot / "mycase" + assert icase._casepath == myroot assert icase._pwd == fmurun @@ -136,7 +136,7 @@ def test_inicase_generate_case_metadata_exists_but_force( icase = InitializeCase(globalconfig2, verbosity="INFO") icase.export( - rootfolder=casemetafolder.parent, + rootfolder=casemetafolder, force=True, casename="ertrun1", caseuser="guffen",