diff --git a/src/fmu/dataio/dataio.py b/src/fmu/dataio/dataio.py index 3a8eccc51..2d02a13d3 100644 --- a/src/fmu/dataio/dataio.py +++ b/src/fmu/dataio/dataio.py @@ -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, @@ -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, diff --git a/tests/test_units/test_preprocessed.py b/tests/test_units/test_preprocessed.py index ac4bb18c7..733d873da 100644 --- a/tests/test_units/test_preprocessed.py +++ b/tests/test_units/test_preprocessed.py @@ -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"]