From b9594d043d45e2c6d7c62c6af63014843c0f5a79 Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Mon, 17 Jun 2024 15:22:13 +0200 Subject: [PATCH] Fix bug where uninitialized ensemble crashes gui --- src/ert/gui/ertwidgets/storage_info_widget.py | 10 +++++++--- ...vaidatedialog.py => test_validatedialog.py} | 0 .../unit_tests/gui/tools/test_ensemble_tool.py | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) rename tests/unit_tests/gui/ertwidgets/{test_vaidatedialog.py => test_validatedialog.py} (100%) diff --git a/src/ert/gui/ertwidgets/storage_info_widget.py b/src/ert/gui/ertwidgets/storage_info_widget.py index 8ca06bfeb36..b10a376c951 100644 --- a/src/ert/gui/ertwidgets/storage_info_widget.py +++ b/src/ert/gui/ertwidgets/storage_info_widget.py @@ -4,6 +4,7 @@ import numpy as np import seaborn as sns +import xarray as xr import yaml from matplotlib.backends.backend_qt5agg import FigureCanvas # type: ignore from matplotlib.figure import Figure @@ -193,9 +194,12 @@ def _currentItemChanged( observation_name ) observation_ds = ensemble.experiment.get_single_obs_ds(observation_name) - response_ds = ensemble.load_responses( - response_name, - ) + try: + response_ds = ensemble.load_responses( + response_name, + ) + except KeyError: + response_ds = xr.Dataset() # check if the response is empty if bool(response_ds.dims): diff --git a/tests/unit_tests/gui/ertwidgets/test_vaidatedialog.py b/tests/unit_tests/gui/ertwidgets/test_validatedialog.py similarity index 100% rename from tests/unit_tests/gui/ertwidgets/test_vaidatedialog.py rename to tests/unit_tests/gui/ertwidgets/test_validatedialog.py diff --git a/tests/unit_tests/gui/tools/test_ensemble_tool.py b/tests/unit_tests/gui/tools/test_ensemble_tool.py index e2476b2ef43..f140cd59907 100644 --- a/tests/unit_tests/gui/tools/test_ensemble_tool.py +++ b/tests/unit_tests/gui/tools/test_ensemble_tool.py @@ -4,7 +4,7 @@ from ert.config import ErtConfig from ert.gui.ertnotifier import ErtNotifier -from ert.gui.ertwidgets.storage_info_widget import _EnsembleWidget +from ert.gui.ertwidgets.storage_info_widget import _EnsembleWidget, _EnsembleWidgetTabs from ert.gui.ertwidgets.storage_widget import StorageWidget from ert.gui.tools.manage_experiments.ensemble_init_configuration import ( EnsembleInitializationConfigurationPanel, @@ -53,6 +53,7 @@ def test_that_init_updates_the_info_tab(qtbot, storage): ensemble = storage.create_experiment( parameters=config.ensemble_config.parameter_configuration, responses=config.ensemble_config.response_configuration, + observations=config.observations.datasets, name="my-experiment", ).create_ensemble( ensemble_size=config.model_config.num_realizations, name="default" @@ -93,3 +94,18 @@ def test_that_init_updates_the_info_tab(qtbot, storage): ensemble_widget._currentTabChanged(1) assert "INITIALIZED" in html_edit.toPlainText() assert not "RealizationStorageState.INITIALIZED" in html_edit.toPlainText() + + # select the observation + storage_info_widget = tool._storage_info_widget + storage_info_widget._ensemble_widget._tab_widget.setCurrentIndex( + _EnsembleWidgetTabs.OBSERVATIONS_TAB + ) + observation_tree = storage_info_widget._ensemble_widget._observations_tree_widget + model_index = observation_tree.model().index( + 0, 0, observation_tree.model().index(0, 0) + ) + observation_tree.setCurrentIndex(model_index) + assert ( + storage_info_widget._ensemble_widget._figure.axes[0].title.get_text() + == "POLY_OBS" + )