From 639d4c38f46706d7f8169a96cf081ab96f69060b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20C=2E=20Riven=C3=A6s?= Date: Wed, 13 Oct 2021 15:13:44 +0200 Subject: [PATCH] Return the absolute path from export() instead --- src/fmu/dataio/_export_item.py | 3 ++- src/fmu/dataio/dataio.py | 11 +++-------- tests/test_fmu_dataio_cube.py | 34 +++++++++++++++----------------- tests/test_fmu_dataio_generic.py | 2 +- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/fmu/dataio/_export_item.py b/src/fmu/dataio/_export_item.py index 70c09b9dd..183e9c3b5 100644 --- a/src/fmu/dataio/_export_item.py +++ b/src/fmu/dataio/_export_item.py @@ -844,7 +844,7 @@ def _item_to_file(self): self._export_actual_object(outfile, metafile, relpath, abspath) - return fpath + return abspath def _construct_filename_fmustandard1(self): """Construct filename stem according to datatype (class) and fmu style 1. @@ -958,6 +958,7 @@ def _verify_path( relpath = abspath.relative_to(useroot) + path = path.absolute() # may contain "../.." in path (not resolved) logger.info("Full path to the actual file is: %s", path) logger.info("Full path to the actual file is (resolved): %s", abspath) logger.info("Full path to the metadata file (if used) is: %s", metapath) diff --git a/src/fmu/dataio/dataio.py b/src/fmu/dataio/dataio.py index a3939ab58..1e4ea47aa 100644 --- a/src/fmu/dataio/dataio.py +++ b/src/fmu/dataio/dataio.py @@ -690,7 +690,7 @@ def export( be included. For backward compatibilty, ``ìndex`` also supported. Returns: - String path, relative to RUNPATH for exported file. + String: full path to exported item. """ if kwargs.get("index", False) is True: # backward compatibility include_index = True @@ -709,13 +709,8 @@ def export( include_index=include_index, ) - filepath = pathlib.Path(exporter.save_to_file()) - logger.info("Filepath (saving to file) is %s", filepath) - logger.info("Current PWD (dataio._pwd)is %s", self._pwd) - logger.info("Current RUNPATH is %s", self._runpath) - relpath = str(filepath.relative_to(self._runpath)) - logger.info("Returning relative path as string: %s", relpath) - return relpath + # will return the absolute (resolved) path for exported file + return exporter.save_to_file() @deprecation.deprecated( deprecated_in="0.5", diff --git a/tests/test_fmu_dataio_cube.py b/tests/test_fmu_dataio_cube.py index fa0c21638..2dded7e62 100644 --- a/tests/test_fmu_dataio_cube.py +++ b/tests/test_fmu_dataio_cube.py @@ -1,5 +1,4 @@ """Test dataio for cube (most often seismic cube).""" - import json import logging import shutil @@ -140,21 +139,20 @@ def test_cube_io_larger_case_ertrun(tmp_path): metadataout = out / ".volantis--what_descr.segy.yml" + assert metadataout.is_file() is True -# assert metadataout.is_file() is True - -# now read the metadata file and test some key entries: -# with open(metadataout, "r") as mstream: -# meta = yaml.safe_load(mstream) -# assert ( -# meta["file"]["relative_path"] -# == "realization-0/iter-0/share/results/cubes/volantis--what_descr.segy" -# ) -# assert meta["fmu"]["model"]["name"] == "ff" -# assert meta["fmu"]["iteration"]["name"] == "iter-0" -# assert meta["fmu"]["realization"]["name"] == "realization-0" -# assert meta["data"]["stratigraphic"] is False -# assert meta["data"]["bbox"]["xmin"] == 0.0 -# assert meta["data"]["bbox"]["xmax"] == 550.0 - -# logger.info("\n%s", json.dumps(meta, indent=2)) + # now read the metadata file and test some key entries: + with open(metadataout, "r") as mstream: + meta = yaml.safe_load(mstream) + assert ( + meta["file"]["relative_path"] + == "realization-0/iter-0/share/results/cubes/volantis--what_descr.segy" + ) + assert meta["fmu"]["model"]["name"] == "ff" + assert meta["fmu"]["iteration"]["name"] == "iter-0" + assert meta["fmu"]["realization"]["name"] == "realization-0" + assert meta["data"]["stratigraphic"] is False + assert meta["data"]["bbox"]["xmin"] == 0.0 + assert meta["data"]["bbox"]["xmax"] == 550.0 + + logger.info("\n%s", json.dumps(meta, indent=2)) diff --git a/tests/test_fmu_dataio_generic.py b/tests/test_fmu_dataio_generic.py index 63e802f5c..dd6a0f102 100644 --- a/tests/test_fmu_dataio_generic.py +++ b/tests/test_fmu_dataio_generic.py @@ -246,7 +246,7 @@ def test_file_block(tmp_path): values=0, name="TopVolantis", ) - assert exp.export(srf, verbosity="INFO") == "share/results/maps" + assert exp.export(srf, verbosity="INFO") == str(out / "topvolantis--what_descr.gri") metadataout = out / ".topvolantis--what_descr.gri.yml" assert metadataout.is_file() is True