From 90db726e0cc48a48ddcfc0efe78e072d09935157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20C=2E=20Riven=C3=A6s?= Date: Tue, 3 Jan 2023 14:42:06 +0100 Subject: [PATCH] Allow forcefolder for preprocessed unless abs path --- src/fmu/dataio/_filedata_provider.py | 4 +-- .../test_prerealization_surfaces.py | 29 +++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/fmu/dataio/_filedata_provider.py b/src/fmu/dataio/_filedata_provider.py index dc4c27788..f5b8c2614 100644 --- a/src/fmu/dataio/_filedata_provider.py +++ b/src/fmu/dataio/_filedata_provider.py @@ -189,9 +189,9 @@ def _get_path_generic(self, mode="realization", allow_forcefolder=True, info="") if mode == "preprocessed": outroot = outroot / "preprocessed" - if self.dataio.forcefolder: + if self.dataio.forcefolder and self.dataio.forcefolder.startswith("/"): raise ValueError( - "Cannot use 'forcefolder' option with preprocessed data" + "Cannot use absolute path to 'forcefolder' with preprocessed data" ) if mode != "preprocessed": diff --git a/tests/test_units/test_prerealization_surfaces.py b/tests/test_units/test_prerealization_surfaces.py index 7e538c8f6..8c5fada72 100644 --- a/tests/test_units/test_prerealization_surfaces.py +++ b/tests/test_units/test_prerealization_surfaces.py @@ -318,8 +318,10 @@ def _run_case_fmu(fmurun_w_casemetadata, rmsglobalconfig, surfacepath, subf=None @inside_rms -def test_preprocessed_with_forcefolder_shall_fail(rmssetup, rmsglobalconfig, regsurf): - """Run an export of a preprocessed surface inside RMS.""" +def test_preprocessed_with_abs_forcefolder_shall_fail( + rmssetup, rmsglobalconfig, regsurf +): + """Run an export of a preprocessed surface inside RMS, with absolute forcefolder.""" logger.info("Active folder is %s", rmssetup) os.chdir(rmssetup) @@ -332,7 +334,24 @@ def test_preprocessed_with_forcefolder_shall_fail(rmssetup, rmsglobalconfig, reg forcefolder="/tmp", ) - with pytest.raises( - ValueError, match="Cannot use 'forcefolder' option with preprocessed data" - ): + with pytest.raises(ValueError, match="Cannot use absolute path to 'forcefolder'"): edata.generate_metadata(regsurf) + + +@inside_rms +def test_preprocessed_with_rel_forcefolder_ok(rmssetup, rmsglobalconfig, regsurf): + """Run an export of a preprocessed surface inside RMS, with forcefolder.""" + logger.info("Active folder is %s", rmssetup) + + os.chdir(rmssetup) + edata = dataio.ExportData( + config=rmsglobalconfig, # read from global config + fmu_context="preprocessed", + name="some", + is_observation=True, + timedata=[[20240802, "moni"], [20200909, "base"]], + forcefolder="tmp", + ) + + meta = edata.generate_metadata(regsurf) + assert "preprocessed/tmp" in meta["file"]["relative_path"]