Skip to content

Commit

Permalink
Fix bug where all ensembles would show
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Apr 3, 2024
1 parent 2b1bf73 commit d441394
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ert/gui/ertwidgets/ensembleselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _ensemble_list(self) -> Iterable[Ensemble]:
ensemble_list = (
x
for x in self.notifier.storage.ensembles
if x.is_initalized and not x.has_data()
if x.is_initalized() and not x.has_data()
)
elif self._show_only_undefined:
ensemble_list = (
Expand Down
41 changes: 40 additions & 1 deletion tests/unit_tests/gui/ertwidgets/test_ensembleselector.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import pytest

from ert.config import ErtConfig
from ert.config import ErtConfig, GenDataConfig, GenKwConfig
from ert.gui.ertnotifier import ErtNotifier
from ert.gui.ertwidgets.ensembleselector import EnsembleSelector


@pytest.fixture
def uniform_parameter():
return GenKwConfig(
name="parameter",
forward_init=False,
template_file="",
transfer_function_definitions=[
"KEY1 UNIFORM 0 1",
],
output_file="kw.txt",
update=True,
)


@pytest.fixture
def response():
return GenDataConfig(name="response")


@pytest.fixture
def notifier():
return ErtNotifier(ErtConfig())
Expand Down Expand Up @@ -75,3 +94,23 @@ def test_changing_ensemble(qtbot, notifier, storage):
assert notifier.current_ensemble == ensemble_a
assert widget_a.currentData() == ensemble_a
assert widget_b.currentData() == ensemble_a


@pytest.mark.parametrize("flag, expected", [(True, []), (False, ["default"])])
def test_only_show_initialized(
qtbot, notifier, storage, uniform_parameter, response, flag, expected
):
ensemble = storage.create_experiment(
parameters=[uniform_parameter], responses=[response]
).create_ensemble(name="default", ensemble_size=1)
notifier.set_storage(storage)
notifier.set_current_ensemble(ensemble)

widget = EnsembleSelector(notifier, show_only_initialized=flag)
qtbot.addWidget(widget)
assert [widget.itemText(i) for i in range(widget.count())] == expected
ensemble.save_parameters(
uniform_parameter.name, 0, uniform_parameter.sample_or_load(0, 1, 1)
)
notifier.emitErtChange()
assert widget.count() == 1

0 comments on commit d441394

Please sign in to comment.