Skip to content

Commit

Permalink
fixup: make skipped tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
valentin-krasontovitsch committed Aug 29, 2023
1 parent 822b37c commit ba5697e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/ert/run_models/base_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,6 @@ async def _evaluate(
experiment_logger.debug("_evaluate")
loop = asyncio.get_running_loop()
experiment_logger.debug("building...")
# why do we use _build_ensemble here, while in mda.py we use
# _storage.create_ensemble???
ensemble = self._build_ensemble(run_context)
self._iter_map[run_context.iteration] = ensemble.id_
experiment_logger.debug("built")
Expand Down
47 changes: 36 additions & 11 deletions tests/unit_tests/ensemble_evaluator/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
import os
import stat
from dataclasses import dataclass
from pathlib import Path
from unittest.mock import MagicMock, Mock
from types import SimpleNamespace
from unittest.mock import Mock

import pytest

Expand All @@ -13,10 +13,19 @@
from ert.ensemble_evaluator.evaluator import EnsembleEvaluator
from ert.ensemble_evaluator.snapshot import SnapshotBuilder
from ert.load_status import LoadStatus
from ert.run_arg import RunArg

from .ensemble_evaluator_utils import TestEnsemble


def dummy_success_callback(*_):
return (LoadStatus.LOAD_SUCCESSFUL, "")


def dummy_fail_callback(*_):
return (LoadStatus.LOAD_FAILURE, "")


@pytest.fixture
def snapshot():
return (
Expand Down Expand Up @@ -64,6 +73,27 @@ def queue_config_fixture():
)


def dummy_ensemble_storage():
ensemble_storage = SimpleNamespace()
ensemble_storage.mount_point = ""
ensemble_storage.storage = SimpleNamespace()
ensemble_storage.storage.path = ""
ensemble_storage.state_map = {}

return ensemble_storage


def make_run_arg(iens: int) -> RunArg:
return RunArg(
iens=iens,
ensemble_storage=dummy_ensemble_storage(),
runpath="",
itr=0,
job_name="jobjobjob",
run_id="runrunrun",
)


@pytest.fixture
def make_ensemble_builder(queue_config):
def _make_ensemble_builder(tmpdir, num_reals, num_jobs, job_sleep=0):
Expand Down Expand Up @@ -96,11 +126,6 @@ def _make_ensemble_builder(tmpdir, num_reals, num_jobs, job_sleep=0):
)
)

@dataclass
class RunArg:
iens: int
ensemble_storage = MagicMock()

for iens in range(0, num_reals):
run_path = Path(tmpdir / f"real_{iens}")
os.mkdir(run_path)
Expand All @@ -122,12 +147,12 @@ class RunArg:
.set_job_name("job dispatch")
.set_job_script("job_dispatch.py")
.set_max_runtime(10000)
.set_run_arg(Mock(iens=iens))
.set_done_callback(lambda _, _b: (LoadStatus.LOAD_SUCCESSFUL, ""))
.set_exit_callback(lambda _, _b: (LoadStatus.LOAD_FAILURE, ""))
.set_run_arg(make_run_arg(iens))
.set_done_callback(dummy_success_callback)
.set_exit_callback(dummy_fail_callback)
# the first callback_argument is expected to be a run_arg
# from the run_arg, the queue wants to access the iens prop
.set_callback_arguments((RunArg(iens), None))
.set_callback_arguments((make_run_arg(iens), {}))
.set_run_path(run_path)
.set_num_cpu(1)
.set_name("dummy step")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ async def _handler(websocket, path):
return events


@pytest.mark.skip(reason="TODO response_configs is None - too much mocking?")
@pytest.mark.asyncio
@pytest.mark.timeout(60)
async def test_happy_path(
Expand Down
3 changes: 1 addition & 2 deletions tests/unit_tests/ensemble_evaluator/test_ensemble_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from ert.ensemble_evaluator.monitor import Monitor


@pytest.mark.skip(reason="TODO response configs has no values, too much mocking?")
@pytest.mark.timeout(60)
def test_run_legacy_ensemble(tmpdir, make_ensemble_builder):
num_reals = 2
Expand Down Expand Up @@ -39,7 +38,7 @@ def test_run_legacy_ensemble(tmpdir, make_ensemble_builder):
assert evaluator._ensemble.status == state.ENSEMBLE_STATE_STOPPED
assert evaluator._ensemble.get_successful_realizations() == num_reals

# realisations should finish, each creating a status-file
# side effect of test job, to see that it actually ran successfully
for i in range(num_reals):
assert os.path.isfile(f"real_{i}/status.txt")

Expand Down

0 comments on commit ba5697e

Please sign in to comment.