Skip to content

Commit

Permalink
Add resinsight test case for well trajectory, fix small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
verveerpj committed Jul 4, 2024
1 parent 36ff78d commit c31e2ba
Show file tree
Hide file tree
Showing 45 changed files with 7,293 additions and 22 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repos:
- id: end-of-file-fixer
exclude: tests/testdata
- id: trailing-whitespace
exclude: tests/testdata/well_trajectory/spe1case1/expected
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.2
hooks:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,5 @@ ignore = [
"E501", # line too long, handled by black
"B008", # do not perform function calls in argument defaults
"C901", # too complex
"W191", # not to be used in combination with a formatter
]
5 changes: 2 additions & 3 deletions src/everest_models/jobs/fm_well_trajectory/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ def _validate_wells(
cls, wells: Tuple[WellConfig, ...], values: ValidationInfo
) -> Tuple[WellConfig, ...]:
for well in wells:
if getattr(cls, "_platforms", None) is None:
cls._platforms = [item.name for item in values.data["platforms"]]
if well.platform is not None and well.platform not in cls._platforms:
_platforms = [item.name for item in values.data["platforms"]]
if well.platform is not None and well.platform not in _platforms:
raise ValueError(
f"Platform '{well.platform}' for well '{well.name}' not defined"
)
Expand Down
4 changes: 0 additions & 4 deletions src/everest_models/jobs/fm_well_trajectory/resinsight.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ def create_well(
logger.info(
f"Calling 'export_well_paths' on the resinsight project" f"\ncwd = {Path.cwd()}"
)
# This log is deceving, it assumes that rips.Project().export_well_paths()
# exports the file to current workig dircetory (cwd) which is not true.
# pytest changes the working directory to '/tmp' but '.export_well_paths`
# keeps exporting the file to the project root directory
project.export_well_paths(well_paths=None, md_step_size=measured_depth_step)

return project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from contextlib import contextmanager
from pathlib import Path
from typing import Dict
from typing import Dict, Optional

import rips

Expand Down Expand Up @@ -53,8 +53,10 @@ def well_trajectory_resinsight(
config: ConfigSchema,
eclipse_model: Path,
guide_points: Dict[str, Trajectory],
project_path: Path = Path.cwd(),
project_path: Optional[Path] = None,
) -> None:
if project_path is None:
project_path = Path.cwd()
with ResInsight(
"" if config.resinsight_binary is None else str(config.resinsight_binary)
) as resinsight:
Expand Down
18 changes: 10 additions & 8 deletions tests/jobs/well_trajectory/test_well_trajectory_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import copy
from pathlib import Path

import pytest
from everest_models.jobs.fm_well_trajectory.models.config import ConfigSchema
Expand All @@ -7,17 +7,19 @@
from sub_testdata import WELL_TRAJECTORY as TEST_DATA


@pytest.fixture(scope="module")
def well_trajectory_config(path_test_data):
return load_yaml(path_test_data / TEST_DATA / "config.yml")
def test_parameters_config_simple(path_test_data):
config = load_yaml(path_test_data / TEST_DATA / "simple" / "config.yml")
ConfigSchema.model_validate(config)


def test_parameters_config(well_trajectory_config):
ConfigSchema.model_validate(well_trajectory_config)
def test_parameters_config_resinsight(copy_testdata_tmpdir):
copy_testdata_tmpdir(Path(TEST_DATA) / "spe1case1")
config = load_yaml("config.yml")
ConfigSchema.model_validate(config)


def test_parameters_invalid_platform(well_trajectory_config):
config = copy.deepcopy(well_trajectory_config)
def test_parameters_invalid_platform(path_test_data):
config = load_yaml(path_test_data / TEST_DATA / "simple" / "config.yml")
config["wells"][0]["platform"] = "platform0"
with pytest.raises(
ValidationError, match="Platform 'platform0' for well 'WI_1' not defined"
Expand Down
43 changes: 43 additions & 0 deletions tests/jobs/well_trajectory/test_well_trajectory_resinsight.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import logging
from pathlib import Path

import pytest
from everest_models.jobs.fm_well_trajectory.cli import main_entry_point
from everest_models.jobs.fm_well_trajectory.well_trajectory_resinsight import ResInsight
from sub_testdata import WELL_TRAJECTORY as TEST_DATA


@pytest.fixture(scope="module")
def well_trajectory_arguments():
return ("-c config.yml -E SPE1CASE1").split()


@pytest.fixture(scope="module")
def well_trajectory_output_files():
return (
"well_geometry.txt",
"wellpaths/INJ.dev",
"wellpaths/PROD.dev",
"INJ.SCH",
"PROD.SCH",
"guide_points.json",
)


@pytest.mark.resinsight
Expand All @@ -21,3 +41,26 @@ def test_start_resinsight(caplog):
with ResInsight() as ri:
assert ri.project.cases() == []
assert "Launching ResInsight..." in caplog.text


@pytest.mark.resinsight
def test_well_trajectory_resinsight_main_entry_point(
well_trajectory_arguments, well_trajectory_output_files, copy_testdata_tmpdir
):
copy_testdata_tmpdir(Path(TEST_DATA) / "spe1case1")
main_entry_point(well_trajectory_arguments)
assert all(
path.read_bytes() == (Path("expected") / path).read_bytes()
for path in map(Path, well_trajectory_output_files)
)


@pytest.mark.resinsight
def test_well_trajectory_resinsight_main_entry_point_lint(
well_trajectory_arguments, well_trajectory_output_files, copy_testdata_tmpdir
):
copy_testdata_tmpdir(Path(TEST_DATA) / "spe1case1")
with pytest.raises(SystemExit):
main_entry_point([*well_trajectory_arguments, "--lint"])

assert not any(path.exists() for path in map(Path, well_trajectory_output_files))
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ def well_trajectory_output_files():
)


def test_well_trajectory_main_entry_point(
def test_well_trajectory_simple_main_entry_point(
well_trajectory_arguments, well_trajectory_output_files, copy_testdata_tmpdir
):
copy_testdata_tmpdir(TEST_DATA)
copy_testdata_tmpdir(Path(TEST_DATA) / "simple")
main_entry_point(well_trajectory_arguments)

assert all(
path.read_bytes() == path.with_suffix(f"{path.suffix}.expected").read_bytes()
path.read_bytes() == (Path("expected") / path).read_bytes()
for path in map(Path, well_trajectory_output_files)
)


def test_well_trajectory_main_entry_point_lint(
def test_well_trajectory_simple_main_entry_point_lint(
well_trajectory_arguments, well_trajectory_output_files, copy_testdata_tmpdir
):
copy_testdata_tmpdir(TEST_DATA)
copy_testdata_tmpdir(Path(TEST_DATA) / "simple")
with pytest.raises(SystemExit):
main_entry_point([*well_trajectory_arguments, "--lint"])

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit c31e2ba

Please sign in to comment.