From 0a35a4f4701e8ffc6455574ffcd0b13f2f1e56a9 Mon Sep 17 00:00:00 2001 From: benjamink Date: Mon, 27 Oct 2025 10:54:24 -0700 Subject: [PATCH 1/2] switch GeoAppsError -> ValueError inside any validators --- simpeg_drivers/joint/joint_surveys/options.py | 2 +- simpeg_drivers/options.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/simpeg_drivers/joint/joint_surveys/options.py b/simpeg_drivers/joint/joint_surveys/options.py index ac06aa3b..037c9ab2 100644 --- a/simpeg_drivers/joint/joint_surveys/options.py +++ b/simpeg_drivers/joint/joint_surveys/options.py @@ -39,7 +39,7 @@ class JointSurveysOptions(BaseJointOptions): def all_groups_same_physical_property(self): physical_properties = [k.options["physical_property"] for k in self.groups] if len(list(set(physical_properties))) > 1: - raise GeoAppsError( + raise ValueError( "All physical properties must be the same. " f"Provided SimPEG groups for {physical_properties}." ) diff --git a/simpeg_drivers/options.py b/simpeg_drivers/options.py index ad91e7ce..93554e9e 100644 --- a/simpeg_drivers/options.py +++ b/simpeg_drivers/options.py @@ -89,7 +89,7 @@ class ActiveCellsOptions(BaseModel): @classmethod def at_least_one(cls, data): if all(v is None for v in data.values()): - raise GeoAppsError("Must provide either topography or active model.") + raise ValueError("Must provide either topography or active model.") return data @model_serializer(mode="wrap") @@ -208,7 +208,7 @@ def _component_name(self, component: str) -> str: @classmethod def mesh_cannot_be_rotated(cls, value: Octree): if isinstance(value, Octree) and value.rotation not in [0.0, None]: - raise GeoAppsError( + raise ValueError( "Rotated meshes are not supported. Please use a mesh with an angle of 0.0." ) return value @@ -491,13 +491,13 @@ class LineSelectionOptions(BaseModel): @classmethod def validate_cell_association(cls, value): if value.association is not DataAssociationEnum.CELL: - raise GeoAppsError("Line identifier must be associated with cells.") + raise ValueError("Line identifier must be associated with cells.") return value @model_validator(mode="after") def line_id_referenced(self): if self.line_id not in self.line_object.values: - raise GeoAppsError("Line id isn't referenced in the line object.") + raise ValueError("Line id isn't referenced in the line object.") return self From cf9e672e50d7789ea94b300966366b84a07a6d36 Mon Sep 17 00:00:00 2001 From: benjamink Date: Mon, 27 Oct 2025 12:54:08 -0700 Subject: [PATCH 2/2] Add unit test --- tests/validations_test.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/validations_test.py diff --git a/tests/validations_test.py b/tests/validations_test.py new file mode 100644 index 00000000..c01beeae --- /dev/null +++ b/tests/validations_test.py @@ -0,0 +1,25 @@ +# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +# Copyright (c) 2025 Mira Geoscience Ltd. ' +# ' +# This file is part of simpeg-drivers package. ' +# ' +# simpeg-drivers is distributed under the terms and conditions of the MIT License ' +# (see LICENSE file at the root of this source code package). ' +# ' +# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +import pytest +from geoapps_utils.utils.importing import GeoAppsError +from geoh5py import Workspace + +from simpeg_drivers.options import CoreOptions + + +def test_topo_or_active_validation(tmp_path): + with Workspace(tmp_path / "test.geoh5") as workspace: + data = { + "geoh5": workspace, + "inversion_type": "mvi", + } + with pytest.raises(GeoAppsError, match="active_cells: Value error, Must"): + CoreOptions.build(data)