Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: Check required inplace volumes columns #940

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/fmu/dataio/export/_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,35 @@ def index_columns() -> list[str]:
"""Returns a list of the index columns."""
return [k.value for k in InplaceVolumes.TableIndexColumns]

@staticmethod
def required_index_columns() -> list[str]:
return [
InplaceVolumes.TableIndexColumns.FLUID.value,
InplaceVolumes.TableIndexColumns.ZONE.value,
]

@staticmethod
def value_columns() -> list[str]:
"""Returns a list of the value columns."""
return [k.value for k in InplaceVolumes.VolumetricColumns]

@staticmethod
def required_value_columns() -> list[str]:
"""Returns a list of the value columns."""
return [
InplaceVolumes.VolumetricColumns.BULK.value,
InplaceVolumes.VolumetricColumns.PORV.value,
InplaceVolumes.VolumetricColumns.HCPV.value,
]

@staticmethod
def required_columns() -> list[str]:
"""Returns a list of the columns required at export."""
return (
InplaceVolumes.required_index_columns()
+ InplaceVolumes.required_value_columns()
)
Comment on lines +67 to +73
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is becoming a kind of verbose "enum". I think it's OK for now, but I can see that the current module/subpackage layout will need adjustment for the next one. It's probably a bit too early to see how that should look now


@staticmethod
def table_columns() -> list[str]:
"""Returns a list of all table columns."""
Expand Down
6 changes: 1 addition & 5 deletions src/fmu/dataio/export/rms/inplace_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,7 @@ def _validate_table(self) -> None:

# create list of missing or non-defined required columns
missing_calculations = []
for col in [
_VolumetricColumns.BULK.value,
_VolumetricColumns.PORV.value,
_VolumetricColumns.HCPV.value,
]:
for col in _enums.InplaceVolumes.required_value_columns():
if self._is_column_missing_in_table(col):
missing_calculations.append(col)

Expand Down
11 changes: 11 additions & 0 deletions tests/test_export_rms/test_export_rms_volumetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,14 @@ def test_inplace_volumes_export_and_result_columns_are_the_same(
assert _enums.InplaceVolumes.table_columns() == list(
InplaceVolumesResultRow.model_fields.keys()
)


def test_that_required_columns_one_to_one_in_enums_and_schema() -> None:
# It's valid for HCPV to be None for water, but nobody should be exporting only
# water, therefore despite it being optional in the schema it will always be a
# column.
schema_required_fields = ["HCPV"]
for field_name, field_info in InplaceVolumesResultRow.model_fields.items():
if field_info.is_required():
schema_required_fields.append(field_name)
assert set(_enums.InplaceVolumes.required_columns()) == set(schema_required_fields)
Loading