Skip to content

Commit

Permalink
Use min_config in place of modifying min_config from test-dat/everest
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava committed Dec 17, 2024
1 parent b3bb31e commit 6176c18
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
22 changes: 22 additions & 0 deletions tests/everest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
from collections.abc import Callable, Iterator
from copy import deepcopy
from pathlib import Path
from textwrap import dedent

import pytest
import yaml

from ert.config import QueueSystem
from ert.ensemble_evaluator import EvaluatorServerConfig
Expand Down Expand Up @@ -189,3 +191,23 @@ def run_config(test_data_case: str):
return copied_path, config_file, optimal_result_json

return run_config


@pytest.fixture
def min_config():
yield yaml.safe_load(
dedent("""
model: {"realizations": [0]}
controls:
-
name: my_control
type: well_control
min: 0
max: 0.1
variables:
- { name: test, initial_guess: 0.1 }
objective_functions:
- {name: my_objective}
config_path: .
""")
)
20 changes: 0 additions & 20 deletions tests/everest/test_everlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,6 @@
from tests.everest.utils import relpath


@pytest.fixture
def min_config():
yield yaml.safe_load(
dedent("""
model: {"realizations": [0]}
controls:
-
name: my_control
type: well_control
min: 0
max: 0.1
variables:
- { name: test, initial_guess: 0.1 }
objective_functions:
- {name: my_objective}
config_path: .
""")
)


@pytest.mark.parametrize(
"required_key",
(
Expand Down
41 changes: 20 additions & 21 deletions tests/everest/test_everserver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import ssl
import stat
from functools import partial
from pathlib import Path
from unittest.mock import patch
Expand Down Expand Up @@ -52,14 +53,6 @@ def set_shared_status(*args, progress, shared_data):
}


def _add_snippet(file_path, snippet, position):
with open(file_path, encoding="utf-8") as file:
lines = file.readlines()
lines.insert(position - 1, snippet + "\n")
with open(file_path, "w", encoding="utf-8") as file:
file.writelines(lines)


def test_certificate_generation(copy_math_func_test_data_to_tmp):
config = EverestConfig.load_file("config_minimal.yml")
cert, key, pw = everserver._generate_certificate(
Expand Down Expand Up @@ -297,22 +290,28 @@ def test_everserver_status_max_batch_num(
@patch("everest.detached.jobs.everserver._write_hostfile")
@patch("everest.detached.jobs.everserver._everserver_thread")
def test_everserver_status_contains_max_runtime_failure(
_1, _2, _3, _4, _5, _6, copy_math_func_test_data_to_tmp
_1, _2, _3, _4, _5, _6, change_to_tmpdir, min_config
):
config_file = "config_minimal.yml"
# Add sleep to distance3 job
_add_snippet(
file_path="jobs/distance3.py",
snippet=" import time\n time.sleep(5)\n",
position=21,

# Add sleep job
Path("sleep.py").write_text(
"#!/usr/bin/env python\nimport time\ntime.sleep(5)", encoding="utf-8"
)
# Add 1 second max runtime
_add_snippet(
file_path="config_minimal.yml",
snippet="\nsimulator:\n max_runtime: 2\n",
position=1,
st = os.stat("sleep.py")
os.chmod("sleep.py", st.st_mode | stat.S_IEXEC)
Path("SLEEP").write_text(
"EXECUTABLE sleep.py\n\nMIN_ARG 0\nMAX_ARG 6", encoding="utf-8"
)
config = EverestConfig.load_file(config_file)

# 2 second max runtime
min_config["simulator"] = {"max_runtime": 2}
min_config["forward_model"] = ["sleep"]
min_config["install_jobs"] = [{"name": "sleep", "source": "SLEEP"}]

config = EverestConfig(**min_config)
config.dump(config_file)

everserver.main()
status = everserver_status(
ServerConfig.get_everserver_status_path(config.output_dir)
Expand All @@ -321,6 +320,6 @@ def test_everserver_status_contains_max_runtime_failure(
assert status["status"] == ServerStatus.failed
print(status["message"])
assert (
"distance3 Failed with: The run is cancelled due to reaching MAX_RUNTIME"
"sleep Failed with: The run is cancelled due to reaching MAX_RUNTIME"
in status["message"]
)

0 comments on commit 6176c18

Please sign in to comment.