diff --git a/src/ert/_c_wrappers/enkf/ensemble_config.py b/src/ert/_c_wrappers/enkf/ensemble_config.py index c3e46877350..433951479d3 100644 --- a/src/ert/_c_wrappers/enkf/ensemble_config.py +++ b/src/ert/_c_wrappers/enkf/ensemble_config.py @@ -22,7 +22,6 @@ from ert._c_wrappers.enkf.config.surface_config import SurfaceConfig from ert._c_wrappers.enkf.config_keys import ConfigKeys from ert.parsing import ConfigValidationError, ConfigWarning, ErrorInfo -from ert.parsing.context_values import ContextList, ContextValue from ert.storage.field_utils.field_utils import Shape, get_shape logger = logging.getLogger(__name__) @@ -242,7 +241,7 @@ def __init__( self.addNode(self.get_field_node(field, grid_file, dims)) @staticmethod - def gen_data_node(gen_data: ContextList[ContextValue]) -> Optional[GenDataConfig]: + def gen_data_node(gen_data: List[str]) -> Optional[GenDataConfig]: options = _option_dict(gen_data, 1) name = gen_data[0] res_file = options.get(ConfigKeys.RESULT_FILE) @@ -255,25 +254,17 @@ def gen_data_node(gen_data: ContextList[ContextValue]) -> Optional[GenDataConfig report_steps = rangestring_to_list(options.get(ConfigKeys.REPORT_STEPS, "")) if os.path.isabs(res_file) or "%d" not in res_file: - result_file_context: ContextValue = next( - x for x in gen_data if x.startswith("RESULT_FILE:") - ) - raise ConfigValidationError.from_info( - ErrorInfo( - filename=result_file_context.token.filename, - message=f"The RESULT_FILE:{res_file} setting for {name} is " - f"invalid - must have an embedded %d and be a relative path", - ).set_context(result_file_context) + raise ConfigValidationError( + f"The RESULT_FILE:{res_file} setting for {name} is " + f"invalid - must have an embedded %d and be a relative path" ) if not report_steps: - raise ConfigValidationError.from_info( - ErrorInfo( - filename=gen_data.keyword_token.filename, - message="The GEN_DATA keywords must have REPORT_STEPS:xxxx" - " defined. Several report steps separated with ',' " - "and ranges with '-' can be listed", - ).set_context_keyword(gen_data.keyword_token) + raise ConfigValidationError( + "The GEN_DATA keywords must have " + "REPORT_STEPS:xxxx defined. Several " + "report steps separated with ',' " + "and ranges with '-' can be listed" ) gdc = GenDataConfig(name=name, input_file=res_file, report_steps=report_steps) diff --git a/tests/test_config_parsing/test_parser_error_collection.py b/tests/test_config_parsing/test_parser_error_collection.py index a2002cd069c..d5f4ce0f383 100644 --- a/tests/test_config_parsing/test_parser_error_collection.py +++ b/tests/test_config_parsing/test_parser_error_collection.py @@ -1069,43 +1069,39 @@ def test_that_deprecations_are_handled(contents, expected_errors): ) +@pytest.mark.parametrize("use_new_parser", [True, False]) @pytest.mark.usefixtures("use_tmpdir") -def test_that_invalid_ensemble_result_file_errors(): - assert_that_config_leads_to_error( - config_file_contents=dedent( - """ +def test_that_invalid_ensemble_result_file_errors(use_new_parser): + write_files( + { + "test.ert": """ NUM_REALIZATIONS 1 GEN_DATA RFT_3-1_R_DATA INPUT_FORMAT:ASCII REPORT_STEPS:100 RESULT_FILE:RFT_3-1_R_ """ - ), - expected_error=ExpectedErrorInfo( - match="must have an embedded %d", - line=3, - column=61, - end_column=89, - ), - ) + } + ), + + with pytest.raises(ConfigValidationError, match="must have an embedded %d"): + _ = ErtConfig.from_file("test.ert", use_new_parser=use_new_parser) +@pytest.mark.parametrize("use_new_parser", [True, False]) @pytest.mark.usefixtures("use_tmpdir") -def test_that_missing_report_steps_errors(): - assert_that_config_leads_to_error( - config_file_contents=dedent( - """ +def test_that_missing_report_steps_errors(use_new_parser): + write_files( + { + "test.ert": """ NUM_REALIZATIONS 1 GEN_DATA RFT_3-1_R_DATA INPUT_FORMAT:ASCII RESULT_FILE:RFT_3-1_R%d """ - ), - expected_error=ExpectedErrorInfo( - match="REPORT_STEPS", - line=3, - column=1, - end_column=9, - ), + } ) + with pytest.raises(ConfigValidationError, match="REPORT_STEPS"): + _ = ErtConfig.from_file("test.ert", use_new_parser=use_new_parser) + @pytest.mark.usefixtures("use_tmpdir") def test_that_valid_gen_data_does_not_error():