Skip to content

Commit

Permalink
Use display_name when explicitly provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
perolavsvendsen committed Jan 4, 2024
1 parent 0ae9856 commit 975c21c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/fmu/dataio/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,13 @@ def _populate_meta_access(self):
def _populate_meta_display(self):
"""Populate the display block."""

self.meta_display = {"name": self.objdata.name}
# display.name
if self.dataio.display_name is not None:
display_name = self.dataio.display_name
else:
display_name = self.objdata.name

self.meta_display = {"name": display_name}

def _populate_meta_xpreprocessed(self):
"""Populate a few necessary 'tmp' metadata needed for preprocessed data."""
Expand Down
1 change: 1 addition & 0 deletions src/fmu/dataio/dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ class ExportData:
content: Union[dict, str, None] = None
depth_reference: str = "msl"
description: Union[str, list] = ""
display_name: Optional[str] = None
fmu_context: str = "realization"
forcefolder: str = ""
grid_model: Optional[str] = None
Expand Down
20 changes: 20 additions & 0 deletions tests/test_units/test_dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,26 @@ def test_content_deprecated_seismic_offset(regsurf, globalconfig2):
}


def test_set_display_name(regsurf, globalconfig2):
"""Test that giving the display_name argument sets display.name."""
eobj = ExportData(
config=globalconfig2,
name="MyName",
display_name="MyDisplayName",
content="depth",
)
mymeta = eobj.generate_metadata(regsurf)

assert mymeta["data"]["name"] == "MyName"
assert mymeta["display"]["name"] == "MyDisplayName"

# also test when setting directly in the method call
mymeta = eobj.generate_metadata(regsurf, display_name="MyOtherDisplayName")

assert mymeta["data"]["name"] == "MyName"
assert mymeta["display"]["name"] == "MyOtherDisplayName"


def test_global_config_from_env(globalconfig_asfile):
"""Testing getting global config from a file"""
os.environ["FMU_GLOBAL_CONFIG"] = globalconfig_asfile
Expand Down
12 changes: 12 additions & 0 deletions tests/test_units/test_metadata_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,18 @@ def test_metadata_display_name_not_given(regsurf, edataobj2):
assert mymeta.meta_display["name"] == mymeta.objdata.name


def test_metadata_display_name_given(regsurf, edataobj2):
"""Test that display.name is set when explicitly given."""

mymeta = _MetaData(regsurf, edataobj2)
edataobj2.display_name = "My Display Name"
mymeta._populate_meta_objectdata()
mymeta._populate_meta_display()

assert mymeta.meta_display["name"] == "My Display Name"
assert mymeta.objdata.name == mymeta.meta_objectdata["name"] == "VOLANTIS GP. Top"


# --------------------------------------------------------------------------------------
# The GENERATE method
# --------------------------------------------------------------------------------------
Expand Down

0 comments on commit 975c21c

Please sign in to comment.