Skip to content

Commit

Permalink
Allow forcefolder for preprocessed unless abs path
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrivenaes committed Jan 3, 2023
1 parent 4bd1e0a commit 90db726
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/fmu/dataio/_filedata_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
29 changes: 24 additions & 5 deletions tests/test_units/test_prerealization_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"]

0 comments on commit 90db726

Please sign in to comment.