Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Jan 25, 2024
1 parent aaf536e commit 50d9c25
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
22 changes: 11 additions & 11 deletions tests/integration_tests/status/test_tracking_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from argparse import ArgumentParser
from datetime import datetime
from pathlib import Path
from queue import SimpleQueue
from textwrap import dedent

import pytest
Expand Down Expand Up @@ -40,7 +41,7 @@ def __init__(self):
def __iter__(self):
yield from self.events

def on_event(self, event):
def put(self, event):
self.events.append(event)
self.environment.append(os.environ.copy())

Expand Down Expand Up @@ -201,12 +202,13 @@ def test_tracking(
responses=ert_config.ensemble_config.response_configuration,
observations=ert_config.observations,
)

queue = SimpleQueue()
model = create_model(
ert_config,
storage,
parsed,
experiment_id,
queue,
)

evaluator_server_config = EvaluatorServerConfig(
Expand All @@ -225,11 +227,10 @@ def test_tracking(

snapshots = {}

events = Events()
model.add_send_event_callback(events.on_event)
thread.join()

for event in events:
while not queue.empty():
event = queue.get()
if isinstance(event, FullSnapshotEvent):
snapshots[event.iteration] = event.snapshot
if (
Expand Down Expand Up @@ -321,11 +322,13 @@ def test_setting_env_context_during_run(
ert_config.ensemble_config.parameter_configuration
)

queue = Events()
model = create_model(
ert_config,
storage,
parsed,
experiment_id,
queue,
)

evaluator_server_config = EvaluatorServerConfig(
Expand All @@ -341,12 +344,10 @@ def test_setting_env_context_during_run(
args=(evaluator_server_config,),
)
thread.start()
events = Events()
model.add_send_event_callback(events.on_event)
thread.join()

expected = ["_ERT_SIMULATION_MODE", "_ERT_EXPERIMENT_ID", "_ERT_ENSEMBLE_ID"]
for event, environment in zip(events.events, events.environment):
for event, environment in zip(queue.events, queue.environment):
if isinstance(event, (FullSnapshotEvent, SnapshotUpdateEvent)):
for key in expected:
assert key in environment
Expand Down Expand Up @@ -405,7 +406,7 @@ def test_tracking_missing_ecl(

ert_config = ErtConfig.from_file(parsed.config)
os.chdir(ert_config.config_path)

events = Events()
model = create_model(
ert_config,
storage,
Expand All @@ -414,6 +415,7 @@ def test_tracking_missing_ecl(
parameters=ert_config.ensemble_config.parameter_configuration,
responses=ert_config.ensemble_config.response_configuration,
),
events,
)

evaluator_server_config = EvaluatorServerConfig(
Expand All @@ -430,8 +432,6 @@ def test_tracking_missing_ecl(
)
with caplog.at_level(logging.ERROR):
thread.start()
events = Events()
model.add_send_event_callback(events.on_event)
thread.join()
failures = []

Expand Down
37 changes: 16 additions & 21 deletions tests/unit_tests/gui/simulation/test_run_dialog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from pathlib import Path
from queue import SimpleQueue
from unittest.mock import MagicMock, Mock

import pytest
Expand All @@ -25,21 +26,15 @@
from tests.unit_tests.gui.simulation.test_run_path_dialog import handle_run_path_dialog


class RunModelMock(MagicMock):
def add_send_event_callback(self, callback):
self.callback = callback


def test_success(qtbot: QtBot):
notifier = Mock()
run_model_mock = RunModelMock()

widget = RunDialog("mock.ert", run_model_mock, notifier)
queue = SimpleQueue()
widget = RunDialog("mock.ert", MagicMock(), queue, notifier)
widget.show()
qtbot.addWidget(widget)

widget.startSimulation()
run_model_mock.callback(EndEvent(failed=False, failed_msg=""))
queue.put(EndEvent(failed=False, failed_msg=""))

with qtbot.waitExposed(widget, timeout=30000):
qtbot.waitUntil(lambda: widget._total_progress_bar.value() == 100)
Expand All @@ -49,13 +44,13 @@ def test_success(qtbot: QtBot):

def test_kill_simulations(qtbot: QtBot):
notifier = Mock()
run_model_mock = RunModelMock()
widget = RunDialog("mock.ert", run_model_mock, notifier)
queue = SimpleQueue()
widget = RunDialog("mock.ert", MagicMock(), queue, notifier)
widget.show()
qtbot.addWidget(widget)

widget.startSimulation()
run_model_mock.callback(EndEvent(failed=False, failed_msg=""))
queue.put(EndEvent(failed=False, failed_msg=""))

with qtbot.waitSignal(widget.finished, timeout=30000):

Expand Down Expand Up @@ -86,8 +81,8 @@ def handle_dialog():

def test_large_snapshot(large_snapshot, qtbot: QtBot, timeout_per_iter=5000):
notifier = Mock()
run_model_mock = RunModelMock()
widget = RunDialog("mock.ert", run_model_mock, notifier)
queue = SimpleQueue()
widget = RunDialog("mock.ert", MagicMock(), queue, notifier)
widget.show()
qtbot.addWidget(widget)

Expand Down Expand Up @@ -115,7 +110,7 @@ def test_large_snapshot(large_snapshot, qtbot: QtBot, timeout_per_iter=5000):

widget.startSimulation()
for event in events:
run_model_mock.callback(event)
queue.put(event)

with qtbot.waitExposed(widget, timeout=timeout_per_iter * 6):
qtbot.waitUntil(
Expand Down Expand Up @@ -326,14 +321,14 @@ def test_large_snapshot(large_snapshot, qtbot: QtBot, timeout_per_iter=5000):
)
def test_run_dialog(events, tab_widget_count, qtbot: QtBot):
notifier = Mock()
run_model_mock = RunModelMock()
widget = RunDialog("mock.ert", run_model_mock, notifier)
queue = SimpleQueue()
widget = RunDialog("mock.ert", MagicMock(), queue, notifier)
widget.show()
qtbot.addWidget(widget)

widget.startSimulation()
for event in events:
run_model_mock.callback(event)
queue.put(event)

with qtbot.waitExposed(widget, timeout=30000):
qtbot.mouseClick(widget.show_details_button, Qt.LeftButton)
Expand Down Expand Up @@ -487,14 +482,14 @@ def handle_dialog():
)
def test_run_dialog_memory_usage_showing(events, tab_widget_count, qtbot: QtBot):
notifier = Mock()
run_model_mock = RunModelMock()
widget = RunDialog("poly.ert", run_model_mock, notifier)
queue = SimpleQueue()
widget = RunDialog("poly.ert", MagicMock(), queue, notifier)
widget.show()
qtbot.addWidget(widget)

widget.startSimulation()
for event in events:
run_model_mock.callback(event)
queue.put(event)

with qtbot.waitExposed(widget, timeout=30000):
qtbot.mouseClick(widget.show_details_button, Qt.LeftButton)
Expand Down

0 comments on commit 50d9c25

Please sign in to comment.