Skip to content

Commit

Permalink
Refine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Jan 10, 2025
1 parent 6e9c8d0 commit 1a0ba33
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 13 deletions.
20 changes: 19 additions & 1 deletion src/everest/config/server_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
import os
from typing import Any

from pydantic import BaseModel, ConfigDict, Field, field_validator
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator

from ert.config.queue_config import (
LocalQueueOptions,
Expand Down Expand Up @@ -57,6 +58,23 @@ def default_local_queue(cls, v):
v["activate_script"] = ErtPluginManager().activate_script()
return v

@model_validator(mode="before")
@classmethod
def check_old_config(cls, data: Any) -> Any:
if isinstance(data, dict):
queue_system = data.get("queue_system")
queue_systems = {
"lsf": LsfQueueOptions,
"torque": TorqueQueueOptions,
"slurm": SlurmQueueOptions,
"local": LocalQueueOptions,
}
if isinstance(queue_system, str) and queue_system in queue_systems:
raise ValueError(
f"Queue system configuration has changed, valid options for {queue_system} are: {list(queue_systems[queue_system].__dataclass_fields__.keys())}"
)
return data

@staticmethod
def get_server_url(output_dir: str) -> str:
"""Return the url of the server.
Expand Down
28 changes: 27 additions & 1 deletion src/everest/config/simulator_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
from pydantic import BaseModel, Field, NonNegativeInt, PositiveInt, field_validator
from typing import Any

from pydantic import (
BaseModel,
Field,
NonNegativeInt,
PositiveInt,
field_validator,
model_validator,
)

from ert.config.queue_config import (
LocalQueueOptions,
Expand Down Expand Up @@ -78,3 +87,20 @@ def default_local_queue(cls, v):
elif "activate_script" not in v and ErtPluginManager().activate_script():
v["activate_script"] = ErtPluginManager().activate_script()
return v

@model_validator(mode="before")
@classmethod
def check_old_config(cls, data: Any) -> Any:
if isinstance(data, dict):
queue_system = data.get("queue_system")
queue_systems = {
"lsf": LsfQueueOptions,
"torque": TorqueQueueOptions,
"slurm": SlurmQueueOptions,
"local": LocalQueueOptions,
}
if isinstance(queue_system, str) and queue_system in queue_systems:
raise ValueError(
f"Queue system configuration has changed, valid options for {queue_system} are: {list(queue_systems[queue_system].__dataclass_fields__.keys())}"
)
return data
12 changes: 11 additions & 1 deletion tests/everest/test_everest_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import logging
from pathlib import Path

from everest.config import EverestConfig
import pytest

from everest.config import EverestConfig, ServerConfig, SimulatorConfig
from everest.config.control_config import ControlConfig
from everest.config.control_variable_config import ControlVariableConfig
from everest.config.cvar_config import CVaRConfig
Expand Down Expand Up @@ -283,3 +285,11 @@ def test_that_log_level_property_is_consistent_with_environment_log_level():
config.logging_level = lvl_str
assert config.environment.log_level == lvl_str
assert config.logging_level == lvl_int


@pytest.mark.parametrize("config_class", [SimulatorConfig, ServerConfig])
@pytest.mark.parametrize("queue_system", ["lsf", "torque", "slurm", "local"])
def test_removed_queue_options_init(queue_system, config_class):
config = {"queue_system": queue_system}
with pytest.raises(ValueError, match=f"valid options for {queue_system} are"):
config_class(**config)
41 changes: 31 additions & 10 deletions tests/everest/test_res_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@
"config, expected",
[
[
{
"name": "local",
"max_running": 0,
"submit_sleep": 0.0,
"project_code": "",
"activate_script": "activate_script",
},
{
"name": "torque",
"queue": "permanent_8",
"qsub_cmd": "qsub",
"qstat_cmd": "qstat",
"qdel_cmd": "qdel",
"keep_qsub_output": 1,
"submit_sleep": 0.5,
"project_code": "snake_oil_pc",
"num_cpus_per_node": 3,
"queue": "queue",
"cluster_label": "cluster_label",
"job_prefix": "job_prefix",
"keep_qsub_output": False,
},
{
"project_code": "snake_oil_pc",
Expand All @@ -50,9 +56,16 @@
[
{
"name": "slurm",
"partition": "default-queue",
"exclude_host": "host1,host2,host3,host4",
"include_host": "host5,host6,host7,host8",
"sbatch": "sbatch",
"scancel": "scancel",
"scontrol": "scontrol",
"sacct": "sacct",
"squeue": "squeue",
"exclude_host": "exclude_host",
"include_host": "include_host",
"partition": "some_partition",
"squeue_timeout": 2.0,
"max_runtime": 10,
},
{
"exclude_hosts": "host1,host2,host3,host4",
Expand All @@ -69,8 +82,13 @@
[
{
"name": "lsf",
"lsf_queue": "mr",
"lsf_resource": "span = 1 && select[x86 and GNU/Linux]",
"bhist_cmd": "bhist",
"bjobs_cmd": "bjobs",
"bkill_cmd": "bkill",
"bsub_cmd": "bsub",
"exclude_host": "",
"lsf_queue": "lsf_queue",
"lsf_resource": "",
},
{
"queue_name": "mr",
Expand All @@ -80,6 +98,9 @@
],
)
def test_everest_to_ert_queue_config(config, expected):
"""Note that these objects are used directly in the Everest
config, and if you have to make changes to this test, it is likely
that it is a breaking change to Everest"""
general_queue_options = {"max_running": 10}
general_options = {"resubmit_limit": 7}

Expand Down

0 comments on commit 1a0ba33

Please sign in to comment.