From 9b5fb9d7f932da04bf565f8c1f403148e83aa1c4 Mon Sep 17 00:00:00 2001 From: Matthieu Cedou Date: Tue, 24 Mar 2026 11:45:24 -0400 Subject: [PATCH 1/4] transfer function get_emtpy uijson from geopy-qa --- geoapps_utils/base.py | 19 ++++++++++++++++--- tests/driver_test.py | 12 +++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/geoapps_utils/base.py b/geoapps_utils/base.py index 26515ce..1faac6b 100644 --- a/geoapps_utils/base.py +++ b/geoapps_utils/base.py @@ -21,7 +21,7 @@ from geoh5py.groups import UIJsonGroup from geoh5py.objects import ObjectBase from geoh5py.shared.utils import stringify -from geoh5py.ui_json import InputFile, monitored_directory_copy +from geoh5py.ui_json import InputFile, monitored_directory_copy, BaseUIJson from geoh5py.ui_json.utils import fetch_active_workspace from pydantic import BaseModel, ConfigDict, ValidationError @@ -107,7 +107,6 @@ def start(cls, filepath: str | Path | InputFile, mode="r+", **kwargs) -> Self: :param filepath: Path to valid ui.json file for the application driver. :param kwargs: Additional keyword arguments for InputFile read_ui_json. """ - ifile = ( cls.read_ui_json(filepath, **kwargs) if isinstance(filepath, str | Path) @@ -178,6 +177,21 @@ def get_default_ui_json(cls) -> Path | None: return cls._params_class.default_ui_json return None + @classmethod + def get_empty_ui_json(cls) -> BaseUIJson: + """ + Get an empty ui.json dictionary for the application. + + :return: Empty ui.json dictionary. + """ + ui_json_path = cls.get_default_ui_json() + + if ui_json_path is None: + raise ValueError(f"Driver {cls} does not have a default ui.json.") + + ui_json = BaseUIJson.read(ui_json_path) + return ui_json + class Options(BaseModel): """ @@ -264,7 +278,6 @@ def build(cls, input_data: InputFile | dict | None = None, **kwargs) -> Self: data.update(kwargs) options = cls.collect_input_from_dict(cls, data) # type: ignore - try: out = cls(**options) except ValidationError as errors: diff --git a/tests/driver_test.py b/tests/driver_test.py index ae19a77..94a51aa 100644 --- a/tests/driver_test.py +++ b/tests/driver_test.py @@ -20,7 +20,7 @@ from geoh5py import Workspace from geoh5py.groups import UIJsonGroup from geoh5py.objects import Points -from geoh5py.ui_json import InputFile +from geoh5py.ui_json import InputFile, BaseUIJson from geoh5py.ui_json.templates import group_parameter, object_parameter from geoapps_utils.base import Options, get_logger @@ -141,6 +141,16 @@ def test_base_options(tmp_path): assert json_dict.get("client", None) == "{" + str(pts.uid) + "}" +def test_get_empty_ui_json(): + # Driver with BaseParams has no default ui.json path + with pytest.raises(ValueError, match="does not have a default ui.json"): + TestParamsDriver.get_empty_ui_json() + + # Driver with Options subclass that has a default_ui_json returns a BaseUIJson + ui_json = TestOptionsDriver.get_empty_ui_json() + assert isinstance(ui_json, BaseUIJson) + + def test_params_errors(): with pytest.raises(TypeError, match="'input_data' must be "): BaseParams.build(input_data="bidon") # type: ignore From 05fe347df751d369d3d97494a3cf4d688f1984f5 Mon Sep 17 00:00:00 2001 From: Matthieu Cedou Date: Tue, 24 Mar 2026 11:48:30 -0400 Subject: [PATCH 2/4] pylint correct --- geoapps_utils/base.py | 2 +- tests/driver_test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/geoapps_utils/base.py b/geoapps_utils/base.py index 1faac6b..aa1548e 100644 --- a/geoapps_utils/base.py +++ b/geoapps_utils/base.py @@ -21,7 +21,7 @@ from geoh5py.groups import UIJsonGroup from geoh5py.objects import ObjectBase from geoh5py.shared.utils import stringify -from geoh5py.ui_json import InputFile, monitored_directory_copy, BaseUIJson +from geoh5py.ui_json import BaseUIJson, InputFile, monitored_directory_copy from geoh5py.ui_json.utils import fetch_active_workspace from pydantic import BaseModel, ConfigDict, ValidationError diff --git a/tests/driver_test.py b/tests/driver_test.py index 94a51aa..63ea371 100644 --- a/tests/driver_test.py +++ b/tests/driver_test.py @@ -20,7 +20,7 @@ from geoh5py import Workspace from geoh5py.groups import UIJsonGroup from geoh5py.objects import Points -from geoh5py.ui_json import InputFile, BaseUIJson +from geoh5py.ui_json import BaseUIJson, InputFile from geoh5py.ui_json.templates import group_parameter, object_parameter from geoapps_utils.base import Options, get_logger From 83c53b2a0a83511102b2e1e3e31bdf88559b19f3 Mon Sep 17 00:00:00 2001 From: Matthieu Cedou Date: Tue, 24 Mar 2026 11:54:18 -0400 Subject: [PATCH 3/4] correct strange pylint error --- tests/driver_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/driver_test.py b/tests/driver_test.py index 63ea371..cc0dc24 100644 --- a/tests/driver_test.py +++ b/tests/driver_test.py @@ -143,7 +143,7 @@ def test_base_options(tmp_path): def test_get_empty_ui_json(): # Driver with BaseParams has no default ui.json path - with pytest.raises(ValueError, match="does not have a default ui.json"): + with pytest.raises(ValueError, match="does not have a default"): TestParamsDriver.get_empty_ui_json() # Driver with Options subclass that has a default_ui_json returns a BaseUIJson From 3e01e2b995e980d34ccaf4e4b314940d73cce4a5 Mon Sep 17 00:00:00 2001 From: Matthieu Cedou Date: Wed, 25 Mar 2026 11:02:37 -0400 Subject: [PATCH 4/4] change the name of the function and check if the uijosn path exists --- geoapps_utils/base.py | 13 +++++++------ tests/driver_test.py | 8 ++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/geoapps_utils/base.py b/geoapps_utils/base.py index aa1548e..fa899d9 100644 --- a/geoapps_utils/base.py +++ b/geoapps_utils/base.py @@ -167,7 +167,7 @@ def update_monitoring_directory( ) @classmethod - def get_default_ui_json(cls) -> Path | None: + def get_default_ui_json_path(cls) -> Path | None: """ Get the default ui.json file path for the application. @@ -178,15 +178,16 @@ def get_default_ui_json(cls) -> Path | None: return None @classmethod - def get_empty_ui_json(cls) -> BaseUIJson: + def get_default_ui_json(cls) -> BaseUIJson: """ - Get an empty ui.json dictionary for the application. + Load the driver's default ui.json template from disk + with no parameters filled in. - :return: Empty ui.json dictionary. + :return: The default ui.json configuration. """ - ui_json_path = cls.get_default_ui_json() + ui_json_path = cls.get_default_ui_json_path() - if ui_json_path is None: + if ui_json_path is None or not ui_json_path.exists(): raise ValueError(f"Driver {cls} does not have a default ui.json.") ui_json = BaseUIJson.read(ui_json_path) diff --git a/tests/driver_test.py b/tests/driver_test.py index cc0dc24..947196b 100644 --- a/tests/driver_test.py +++ b/tests/driver_test.py @@ -66,7 +66,7 @@ def test_base_driver(tmp_path): driver = TestParamsDriver(params) - assert TestParamsDriver.get_default_ui_json() is None + assert TestParamsDriver.get_default_ui_json_path() is None driver.start(tmp_path / "test_ifile.ui.json") @@ -120,7 +120,7 @@ def test_base_options(tmp_path): driver = TestOptionsDriver(options) - assert TestOptionsDriver.get_default_ui_json().exists() # type: ignore + assert TestOptionsDriver.get_default_ui_json_path().exists() # type: ignore assert isinstance(driver.params, TestOptions) assert driver.params_class == TestOptions @@ -144,10 +144,10 @@ def test_base_options(tmp_path): def test_get_empty_ui_json(): # Driver with BaseParams has no default ui.json path with pytest.raises(ValueError, match="does not have a default"): - TestParamsDriver.get_empty_ui_json() + TestParamsDriver.get_default_ui_json() # Driver with Options subclass that has a default_ui_json returns a BaseUIJson - ui_json = TestOptionsDriver.get_empty_ui_json() + ui_json = TestOptionsDriver.get_default_ui_json() assert isinstance(ui_json, BaseUIJson)