Skip to content

Commit

Permalink
Allow fm step configuration values to be empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Dec 19, 2024
1 parent a509da2 commit 50df0fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def filter_env_dict(self, d):
new_value = self.substitute(value)
if new_value is None:
result[new_key] = None
elif not new_value:
result[new_key] = ""
elif not (new_value[0] == "<" and new_value[-1] == ">"):
# Remove values containing "<XXX>". These are expected to be
# replaced by substitute, but were not.
Expand Down
12 changes: 8 additions & 4 deletions tests/ert/unit_tests/config/test_ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from unittest.mock import MagicMock

import pytest
from hypothesis import assume, example, given, settings
from hypothesis import HealthCheck, assume, example, given, settings
from hypothesis import strategies as st
from pydantic import RootModel, TypeAdapter

Expand Down Expand Up @@ -838,12 +838,16 @@ def test_that_include_statements_with_multiple_values_raises_error():
)


@pytest.mark.integration_test
@settings(suppress_health_check=[HealthCheck.function_scoped_fixture])
@pytest.mark.usefixtures("use_tmpdir")
def test_fm_step_config_via_plugin_ends_up_json_data(monkeypatch):
@given(anystring=st.text())
def test_fm_step_config_via_plugin_ends_up_json_data(monkeypatch, anystring):
assume(not (anystring and anystring[0] == "<" and anystring[-1] == ">"))
monkeypatch.setattr(
ErtPluginManager,
"get_forward_model_configuration",
MagicMock(return_value={"SOME_STEP": {"FOO": "bar"}}),
MagicMock(return_value={"SOME_STEP": {"FOO": anystring}}),
)
Path("SOME_STEP").write_text("EXECUTABLE /bin/ls", encoding="utf-8")
Path("config.ert").write_text(
Expand All @@ -864,7 +868,7 @@ def test_fm_step_config_via_plugin_ends_up_json_data(monkeypatch):
env_pr_fm_step=ert_config.env_pr_fm_step,
run_id=None,
)
assert step_json["jobList"][0]["environment"]["FOO"] == "bar"
assert step_json["jobList"][0]["environment"]["FOO"] == anystring


@pytest.mark.usefixtures("use_tmpdir")
Expand Down
11 changes: 11 additions & 0 deletions tests/ert/unit_tests/plugins/test_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ def forward_model_configuration():
)


def test_fm_config_with_empty_string_for_step():
class SomePlugin:
@plugin(name="foo")
def forward_model_configuration():
return {"foo": {"com": ""}}

assert ErtPluginManager(plugins=[SomePlugin]).get_forward_model_configuration() == {
"foo": {"com": ""}
}


def test_fm_config_merges_data_for_step():
class SomePlugin:
@plugin(name="foo")
Expand Down

0 comments on commit 50df0fb

Please sign in to comment.