Skip to content

Commit

Permalink
Move run_args and run_paths fixtures to unit_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Sep 17, 2024
1 parent 2dafc86 commit 8401331
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
39 changes: 1 addition & 38 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
import sys
from argparse import ArgumentParser
from pathlib import Path
from typing import List, Optional
from unittest.mock import MagicMock

from qtpy.QtWidgets import QApplication

from _ert.threading import set_signal_handler
from ert.run_arg import RunArg, create_run_arguments
from ert.runpaths import Runpaths

if sys.version_info >= (3, 9):
from importlib.resources import files
Expand All @@ -32,7 +29,7 @@
from ert.ensemble_evaluator.config import EvaluatorServerConfig
from ert.mode_definitions import ENSEMBLE_EXPERIMENT_MODE, ES_MDA_MODE
from ert.services import StorageService
from ert.storage import Ensemble, open_storage
from ert.storage import open_storage

from .utils import SOURCE_DIR

Expand Down Expand Up @@ -480,37 +477,3 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

monkeypatch.setattr("ert.cli.main.EvaluatorServerConfig", MockESConfig)


@pytest.fixture
def run_paths():
def func(ert_config: ErtConfig):
return Runpaths(
jobname_format=ert_config.model_config.jobname_format_string,
runpath_format=ert_config.model_config.runpath_format_string,
filename=str(ert_config.runpath_file),
substitution_list=ert_config.substitution_list,
)

yield func


@pytest.fixture
def run_args(run_paths):
def func(
ert_config: ErtConfig,
ensemble: Ensemble,
active_realizations: Optional[int] = None,
) -> List[RunArg]:
active_realizations = (
ert_config.model_config.num_realizations
if active_realizations is None
else active_realizations
)
return create_run_arguments(
run_paths(ert_config),
[True] * active_realizations,
ensemble,
)

yield func
40 changes: 40 additions & 0 deletions tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import os
import sys
from typing import List, Optional

import pytest

from ert.config import ErtConfig
from ert.run_arg import RunArg, create_run_arguments
from ert.runpaths import Runpaths
from ert.storage import Ensemble


@pytest.fixture(scope="session", autouse=True)
def ensure_bin_in_path():
Expand All @@ -26,3 +32,37 @@ def snake_oil_field_example(setup_case):
def prior_ensemble(storage):
experiment_id = storage.create_experiment()
return storage.create_ensemble(experiment_id, name="prior", ensemble_size=100)


@pytest.fixture
def run_paths():
def func(ert_config: ErtConfig):
return Runpaths(
jobname_format=ert_config.model_config.jobname_format_string,
runpath_format=ert_config.model_config.runpath_format_string,
filename=str(ert_config.runpath_file),
substitution_list=ert_config.substitution_list,
)

yield func


@pytest.fixture
def run_args(run_paths):
def func(
ert_config: ErtConfig,
ensemble: Ensemble,
active_realizations: Optional[int] = None,
) -> List[RunArg]:
active_realizations = (
ert_config.model_config.num_realizations
if active_realizations is None
else active_realizations
)
return create_run_arguments(
run_paths(ert_config),
[True] * active_realizations,
ensemble,
)

yield func

0 comments on commit 8401331

Please sign in to comment.