Skip to content

Commit

Permalink
FIX: Support giving in arguments on export for preprocessed data (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnatt authored Jun 11, 2024
1 parent 2099e77 commit 9b765ff
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/fmu/dataio/dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,8 @@ def generate_metadata(
self._update_check_settings(kwargs)

if isinstance(obj, (str, Path)):
assert self.casepath is not None
if self.casepath is None:
raise TypeError("No 'casepath' argument provided")
_future_warning_preprocessed()
return ExportPreprocessedData(
config=self.config,
Expand Down Expand Up @@ -804,7 +805,9 @@ def export(
"The return_symlink option is deprecated and can safely be removed."
)
if isinstance(obj, (str, Path)):
assert self.casepath is not None
self._update_check_settings(kwargs)
if self.casepath is None:
raise TypeError("No 'casepath' argument provided")
_future_warning_preprocessed()
return ExportPreprocessedData(
config=self.config,
Expand Down
47 changes: 47 additions & 0 deletions tests/test_units/test_preprocessed.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,50 @@ def test_export_preprocessed_file_exportdata_futurewarning(
assert filepath.exists()
metafile = filepath.parent / f".{filepath.name}.yml"
assert metafile.exists()


def test_export_preprocessed_file_exportdata_casepath_on_export(
fmurun_prehook, rmsglobalconfig, regsurf, monkeypatch
):
"""
Test that using the ExportData class to export preprocessed files
works also if arguments have been given on the export/generate_metadata methods
"""
# mock being outside of FMU
remove_ert_env(monkeypatch)
surfacepath, _ = export_preprocessed_surface(rmsglobalconfig, regsurf)

# mock being inside of FMU
set_ert_env_prehook(monkeypatch)

# Use the ExportData class instead of the ExportPreprocessedData
edata = dataio.ExportData(config=rmsglobalconfig)

# test that error is thrown when missing casepath
with pytest.raises(TypeError, match="No 'casepath' argument provided"):
edata.export(surfacepath, is_observation=True)

# test that export() works if casepath is provided
with pytest.warns(FutureWarning, match="no longer supported"):
filepath = Path(
edata.export(surfacepath, is_observation=True, casepath=fmurun_prehook)
)
assert filepath.exists()
metafile = filepath.parent / f".{filepath.name}.yml"
assert metafile.exists()

# Use the ExportData class instead of the ExportPreprocessedData
edata = dataio.ExportData(config=rmsglobalconfig)

# test that error is thrown when missing casepath
with pytest.raises(TypeError, match="No 'casepath' argument provided"):
edata.generate_metadata(surfacepath, is_observation=True)

# test that generate_metadata() works if casepath is provided
with pytest.warns(FutureWarning, match="no longer supported"):
meta = edata.generate_metadata(
surfacepath, is_observation=True, casepath=fmurun_prehook
)

assert "fmu" in meta
assert "merged" in meta["tracklog"][-1]["event"]

0 comments on commit 9b765ff

Please sign in to comment.