Skip to content

Commit

Permalink
Add run_dialog label test
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el committed Oct 4, 2024
1 parent e88d5ff commit fd360c8
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ert/gui/model/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def _add_snapshot(self, snapshot: EnsembleSnapshot, iter_: str) -> None:
data=RealNodeData(
status=real.get("status"),
active=real.get("active"),
exec_hosts=real.get("exec_hosts"),
fm_step_status_color_by_id=metadata.get(
"aggr_fm_step_status_colors", defaultdict(None)
)[real_id],
Expand Down
1 change: 1 addition & 0 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def __init__(
self._snapshot_model.rowsInserted.connect(self.on_snapshot_new_iteration)

self._fm_step_label = QLabel(self)
self._fm_step_label.setObjectName("fm_step_label")
self._fm_step_overview = FMStepOverview(self._snapshot_model, self)

self.running_time = QLabel("")
Expand Down
2 changes: 2 additions & 0 deletions tests/ert/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def build(
self,
real_ids: Sequence[str],
status: Optional[str],
exec_hosts: Optional[str] = None,
start_time: Optional[datetime] = None,
end_time: Optional[datetime] = None,
) -> EnsembleSnapshot:
Expand All @@ -49,6 +50,7 @@ def build(
fm_steps=deepcopy(self.fm_steps),
start_time=start_time,
end_time=end_time,
exec_hosts=exec_hosts,
status=status,
),
)
Expand Down
101 changes: 100 additions & 1 deletion tests/ert/unit_tests/gui/simulation/test_run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
from pytestqt.qtbot import QtBot
from qtpy import QtWidgets
from qtpy.QtCore import Qt, QTimer
from qtpy.QtWidgets import QApplication, QComboBox, QPushButton, QToolButton, QWidget
from qtpy.QtWidgets import (
QApplication,
QComboBox,
QLabel,
QPushButton,
QToolButton,
QWidget,
)

import ert
from ert.config import ErtConfig
Expand Down Expand Up @@ -459,6 +466,98 @@ def test_run_dialog_memory_usage_showing(
assert max_memory_value == "60.00 KB"


@pytest.mark.parametrize(
"events, tab_widget_count, expected_host_info",
[
pytest.param(
[
FullSnapshotEvent(
snapshot=(
SnapshotBuilder()
.add_fm_step(
fm_step_id="0",
index="0",
name="fm_step_0",
status=state.FORWARD_MODEL_STATE_START,
)
.build(
["0"],
status=state.REALIZATION_STATE_UNKNOWN,
exec_hosts="COMP_01",
)
),
iteration_label="Foo",
current_iteration=0,
total_iterations=1,
progress=0.25,
realization_count=4,
status_count={"Finished": 1, "Pending": 1, "Unknown": 2},
iteration=0,
),
EndEvent(failed=False, msg=""),
],
1,
", assigned to host: COMP_01",
id="Simulation where exec_host present",
),
pytest.param(
[
FullSnapshotEvent(
snapshot=(
SnapshotBuilder()
.add_fm_step(
fm_step_id="0",
index="0",
name="fm_step_0",
status=state.FORWARD_MODEL_STATE_START,
)
.build(["0"], status=state.REALIZATION_STATE_UNKNOWN)
),
iteration_label="Foo",
current_iteration=0,
total_iterations=1,
progress=0.25,
realization_count=4,
status_count={"Finished": 1, "Pending": 1, "Unknown": 2},
iteration=0,
),
EndEvent(failed=False, msg=""),
],
1,
"",
id="Simulation where exec_host not present",
),
],
)
def test_run_dialog_fm_label_show_correct_info(
events, tab_widget_count, expected_host_info, qtbot: QtBot, event_queue, run_dialog
):
run_dialog.run_experiment()
for event in events:
event_queue.put(event)

qtbot.waitUntil(
lambda: run_dialog._tab_widget.count() == tab_widget_count, timeout=5000
)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=5000)

# This is the container of realization boxes
realization_box = run_dialog._tab_widget.widget(0)
assert type(realization_box) == RealizationWidget
# Click the first realization box
qtbot.mouseClick(realization_box, Qt.LeftButton)
fm_step_model = run_dialog._fm_step_overview.model()
assert fm_step_model._real == 0

fm_step_label = run_dialog.findChild(QLabel, name="fm_step_label")
assert not fm_step_label.text()

realization_box._item_clicked(run_dialog._fm_step_overview.model().index(0, 0))
assert (
fm_step_label.text() == f"Realization id 0 in iteration 0{expected_host_info}"
)


@pytest.mark.integration_test
@pytest.mark.usefixtures("use_tmpdir")
def test_that_exception_in_base_run_model_is_handled(qtbot: QtBot, storage):
Expand Down

0 comments on commit fd360c8

Please sign in to comment.