|
| 1 | +from PyQt6.QtCore import Qt |
| 2 | +from pytestqt.qtbot import QtBot |
| 3 | + |
| 4 | +from ert.config.analysis_config import AnalysisConfig |
| 5 | +from ert.gui.ertnotifier import ErtNotifier |
| 6 | +from ert.gui.ertwidgets.ensembleselector import EnsembleSelector |
| 7 | +from ert.gui.ertwidgets.stringbox import StringBox |
| 8 | +from ert.gui.simulation.manual_update_panel import ManualUpdatePanel |
| 9 | + |
| 10 | +from .conftest import ( |
| 11 | + REALIZATION_FINISHED_SUCCESSFULLY, |
| 12 | + REALIZATION_UNDEFINED, |
| 13 | + MockStorage, |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +def test_that_active_realizations_selector_validates_with_ensemble_size_from_prior( |
| 18 | + qtbot: QtBot, |
| 19 | +) -> None: |
| 20 | + """This is a test that makes sure that the active realizations field is |
| 21 | + validated against the ensemble size from the prior ensemble, and not |
| 22 | + the ensemble size from config. |
| 23 | + """ |
| 24 | + notifier = ErtNotifier() |
| 25 | + notifier._storage = MockStorage() |
| 26 | + config_ensemble_size = 2 |
| 27 | + notifier._storage._setup_mocked_run( |
| 28 | + "mock_ensemble0", |
| 29 | + "mock_experiment0", |
| 30 | + [ |
| 31 | + REALIZATION_UNDEFINED, |
| 32 | + REALIZATION_FINISHED_SUCCESSFULLY, |
| 33 | + REALIZATION_FINISHED_SUCCESSFULLY, |
| 34 | + REALIZATION_FINISHED_SUCCESSFULLY, |
| 35 | + REALIZATION_UNDEFINED, |
| 36 | + REALIZATION_FINISHED_SUCCESSFULLY, |
| 37 | + REALIZATION_FINISHED_SUCCESSFULLY, |
| 38 | + REALIZATION_FINISHED_SUCCESSFULLY, |
| 39 | + ], |
| 40 | + ) |
| 41 | + notifier._storage._setup_mocked_run( |
| 42 | + "mock_ensemble1", |
| 43 | + "mock_experiment1", |
| 44 | + [ |
| 45 | + REALIZATION_UNDEFINED, |
| 46 | + REALIZATION_UNDEFINED, |
| 47 | + REALIZATION_FINISHED_SUCCESSFULLY, |
| 48 | + REALIZATION_FINISHED_SUCCESSFULLY, |
| 49 | + REALIZATION_UNDEFINED, |
| 50 | + REALIZATION_FINISHED_SUCCESSFULLY, |
| 51 | + ], |
| 52 | + ) |
| 53 | + panel = ManualUpdatePanel( |
| 54 | + ensemble_size=config_ensemble_size, |
| 55 | + analysis_config=AnalysisConfig(minimum_required_realizations=1), |
| 56 | + run_path="", |
| 57 | + notifier=notifier, |
| 58 | + ) |
| 59 | + qtbot.addWidget(panel) |
| 60 | + |
| 61 | + prior_ensemble0_ensemble_size = 8 |
| 62 | + prior_ensemble1_ensemble_size = 6 |
| 63 | + |
| 64 | + realization_selector = panel.findChild(StringBox, "active_realizations_box") |
| 65 | + assert realization_selector is not None |
| 66 | + ensemble_selector = panel.findChild(EnsembleSelector) |
| 67 | + assert ensemble_selector.isEnabled() |
| 68 | + |
| 69 | + index = ensemble_selector.findText("mock_ensemble0", Qt.MatchFlag.MatchContains) |
| 70 | + ensemble_selector.setCurrentIndex(index) |
| 71 | + assert ensemble_selector.currentText() == "mock_experiment0 : mock_ensemble0" |
| 72 | + assert ( |
| 73 | + panel._number_of_realizations_label.text() |
| 74 | + == f"<b>{prior_ensemble0_ensemble_size}</b>" |
| 75 | + ) |
| 76 | + |
| 77 | + # Only these realizations in prior have RealizationStorageState.RESPONSES_LOADED |
| 78 | + assert realization_selector.text() == "1-3, 5-7" |
| 79 | + assert realization_selector.isValid(), ( |
| 80 | + realization_selector._validation._validation_message |
| 81 | + ) |
| 82 | + assert panel.isConfigurationValid() |
| 83 | + assert ( |
| 84 | + panel.get_experiment_arguments().ensemble_size == prior_ensemble0_ensemble_size |
| 85 | + ) |
| 86 | + |
| 87 | + # We try running a realization that does not have RESPONSES_LOADED |
| 88 | + realization_selector.setText("4-7") |
| 89 | + assert not panel.isConfigurationValid() |
| 90 | + index = ensemble_selector.findText("mock_ensemble1", Qt.MatchFlag.MatchContains) |
| 91 | + ensemble_selector.setCurrentIndex(index) |
| 92 | + assert ensemble_selector.currentText() == "mock_experiment1 : mock_ensemble1" |
| 93 | + |
| 94 | + # The active realizations field should auto-populate with a valid value |
| 95 | + assert panel.isConfigurationValid() |
| 96 | + assert ( |
| 97 | + panel.get_experiment_arguments().ensemble_size == prior_ensemble1_ensemble_size |
| 98 | + ) |
| 99 | + assert ( |
| 100 | + panel._number_of_realizations_label.text() |
| 101 | + == f"<b>{prior_ensemble1_ensemble_size}</b>" |
| 102 | + ) |
| 103 | + assert realization_selector.text() == "2-3, 5" |
| 104 | + |
| 105 | + |
| 106 | +def test_that_manual_update_ensemble_selector_only_shows_ensembles_with_data( |
| 107 | + qtbot: QtBot, |
| 108 | +) -> None: |
| 109 | + """This is a test that makes sure that ensembles without data are not available |
| 110 | + for selection in the ensemble_selector. This will be ensembles that were just |
| 111 | + created by ManageExperiment or by ManualUpdate. |
| 112 | + """ |
| 113 | + notifier = ErtNotifier() |
| 114 | + notifier._storage = MockStorage() |
| 115 | + config_ensemble_size = 2 |
| 116 | + notifier._storage._setup_mocked_run( |
| 117 | + "mock_ensemble_no_data", |
| 118 | + "mock_experiment2", |
| 119 | + [REALIZATION_UNDEFINED, REALIZATION_UNDEFINED, REALIZATION_UNDEFINED], |
| 120 | + ) |
| 121 | + |
| 122 | + panel = ManualUpdatePanel( |
| 123 | + ensemble_size=config_ensemble_size, |
| 124 | + analysis_config=AnalysisConfig(minimum_required_realizations=1), |
| 125 | + run_path="", |
| 126 | + notifier=notifier, |
| 127 | + ) |
| 128 | + qtbot.addWidget(panel) |
| 129 | + ensemble_selector = panel.findChild(EnsembleSelector) |
| 130 | + assert not ensemble_selector.isEnabled() |
| 131 | + |
| 132 | + index = ensemble_selector.findText( |
| 133 | + "mock_ensemble_no_data", Qt.MatchFlag.MatchContains |
| 134 | + ) |
| 135 | + assert index == -1 # Invalid index, because it is not available |
| 136 | + ensemble_selector.setCurrentIndex(index) |
| 137 | + assert not ensemble_selector.currentText() |
| 138 | + assert not panel.isConfigurationValid() |
0 commit comments