Skip to content

Commit

Permalink
Add deprecation for INVERSION with number
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Feb 1, 2024
1 parent 66412cf commit ffe3c32
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ert/config/analysis_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,19 @@ def __init__(
continue
if var_name in ["INVERSION", "IES_INVERSION"]:
if value in inversion_str_map[module_name]:
value = inversion_str_map[module_name][value]
new_value = inversion_str_map[module_name][value]
if var_name == "IES_INVERSION":
ConfigWarning.ert_context_warn(
"IES_INVERSION is deprecated, please use INVERSION instead:\n"
f"ANALYSIS_SET_VAR {module_name} INVERSION {value.upper()}"
f"ANALYSIS_SET_VAR {module_name} INVERSION {new_value.upper()}"
)
else:
ConfigWarning.ert_context_warn(
f"Using {value} is deprecated, use:\n"
f"ANALYSIS_SET_VAR {module_name} INVERSION {new_value.upper()}"
)
value = new_value

var_name = "inversion"
key = var_name.lower()
options[module_name][key] = value
Expand Down
24 changes: 24 additions & 0 deletions tests/unit_tests/config/test_analysis_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from textwrap import dedent

import hypothesis.strategies as st
Expand Down Expand Up @@ -283,3 +284,26 @@ def test_num_realizations_0_means_all():
).minimum_required_realizations
== 100
)


@pytest.mark.parametrize(
"config, expected",
[
(
["STD_ENKF", "INVERSION", "1"],
"Using 1 is deprecated, use:\nANALYSIS_SET_VAR STD_ENKF INVERSION SUBSPACE",
),
(
["STD_ENKF", "IES_INVERSION", "1"],
"IES_INVERSION is deprecated, please use INVERSION instead",
),
],
)
def test_incorrect_variable_deprecation_warning(config, expected):
with warnings.catch_warnings(record=True) as all_warnings:
_ = AnalysisConfig.from_dict(
{
ConfigKeys.ANALYSIS_SET_VAR: [config],
}
)
assert expected in [str(warning.message) for warning in all_warnings]

0 comments on commit ffe3c32

Please sign in to comment.