Skip to content

Commit

Permalink
Catch return_code=1 properly from eclrun
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Jan 25, 2024
1 parent 220728e commit 527f844
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ert/shared/share/ert/forward-models/res/script/ecl_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from resdata.summary import Summary


def await_process_tee(process, *out_files):
def await_process_tee(process, *out_files) -> int:
"""Wait for process to finish, "tee"-ing the subprocess' stdout into all the
given file objects.
Expand Down Expand Up @@ -316,7 +316,7 @@ def _get_log_name(self, eclrun_config=None):
logname_extension = "LOG"
return f"{self.base_name}.{logname_extension}"

def execEclipse(self, eclrun_config=None):
def execEclipse(self, eclrun_config=None) -> int:
use_eclrun = eclrun_config is not None
log_name = self._get_log_name(eclrun_config=eclrun_config)

Expand Down Expand Up @@ -358,7 +358,12 @@ def runEclipse(self, eclrun_config=None, retries_left=2, backoff_sleep=None):
f.write("ECLIPSE simulation complete - NOT checked for errors.")
else:
if return_code != 0:
raise subprocess.CalledProcessError(return_code, self.sim.executable)
command = (
self._get_run_command(eclrun_config)
if self.sim is None
else self._get_legacy_run_command()
)
raise subprocess.CalledProcessError(return_code, command)

try:
self.assertECLEND()
Expand Down
9 changes: 9 additions & 0 deletions tests/unit_tests/shared/share/test_ecl_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,15 @@ def test_run_nonzero_exit_code(init_ecl100_config, source_root):
erun.runEclipse()


@pytest.mark.requires_eclipse
def test_non_existing_eclipse_version(init_ecl100_config, source_root):
Path("FOO.DATA").write_text("", encoding="utf-8")
econfig = ecl_config.Ecl100Config()

with pytest.raises(KeyError, match="2079.3"):
econfig.sim("2079.3")


@pytest.mark.requires_eclipse
def test_run_api(init_ecl100_config, source_root):
shutil.copy(
Expand Down
16 changes: 16 additions & 0 deletions tests/unit_tests/shared/share/test_ecl_run_new_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import re
import shutil
import stat
import subprocess
from pathlib import Path
from unittest import mock

import pytest
Expand Down Expand Up @@ -178,6 +180,20 @@ def test_failed_run(source_root):
erun.runEclipse(eclrun_config=eclrun_config)


@pytest.mark.requires_eclipse
@pytest.mark.usefixtures("use_tmpdir", "init_eclrun_config")
def test_failed_run_nonzero_returncode(monkeypatch):
Path("FOO.DATA").write_text("")
econfig = ecl_config.Ecl100Config()
eclrun_config = ecl_config.EclrunConfig(econfig, "2021.3")
erun = ecl_run.EclRun("FOO.DATA", None)
monkeypatch.setattr("ecl_run.EclRun.execEclipse", mock.MagicMock(return_value=1))
with pytest.raises(
subprocess.CalledProcessError, match="Command .*eclrun.* non-zero exit status 1"
):
erun.runEclipse(eclrun_config=eclrun_config)


@pytest.mark.requires_eclipse
@pytest.mark.usefixtures("use_tmpdir", "init_eclrun_config")
def test_failed_run_OK(source_root):
Expand Down

0 comments on commit 527f844

Please sign in to comment.