diff --git a/src/ert/config/ert_config.py b/src/ert/config/ert_config.py index f5a1366747c..0aa1bbeb982 100644 --- a/src/ert/config/ert_config.py +++ b/src/ert/config/ert_config.py @@ -408,12 +408,6 @@ def _validate_dict( ) -> List[Union[ErrorInfo, ConfigValidationError]]: errors = [] - gen_kws = config_dict.get("GEN_KW", []) - for gen_kw in gen_kws: - file_path = Path(gen_kw[1]) - if file_path.stat().st_size == 0: - raise ConfigValidationError(f"No parameters specified in {file_path}") - if ConfigKeys.SUMMARY in config_dict and ConfigKeys.ECLBASE not in config_dict: errors.append( ErrorInfo( diff --git a/src/ert/config/gen_kw_config.py b/src/ert/config/gen_kw_config.py index d11d37419fd..90adf951ed3 100644 --- a/src/ert/config/gen_kw_config.py +++ b/src/ert/config/gen_kw_config.py @@ -105,12 +105,13 @@ def from_config_list(cls, gen_kw: List[str]) -> Self: if len(positional_args) == 2: parameter_file = _get_abs_path(positional_args[1]) + parameter_file_context = positional_args[1] template_file = None output_file = None elif len(positional_args) == 4: output_file = positional_args[2] parameter_file = _get_abs_path(positional_args[3]) - + parameter_file_context = positional_args[3] template_file = _get_abs_path(positional_args[1]) if not os.path.isfile(template_file): errors.append( @@ -125,7 +126,14 @@ def from_config_list(cls, gen_kw: List[str]) -> Self: if not os.path.isfile(parameter_file): errors.append( ConfigValidationError.with_context( - f"No such parameter file: {parameter_file}", positional_args[3] + f"No such parameter file: {parameter_file}", parameter_file_context + ) + ) + elif Path(parameter_file).stat().st_size == 0: + errors.append( + ConfigValidationError.with_context( + f"No parameters specified in {parameter_file}", + parameter_file_context, ) ) diff --git a/tests/unit_tests/config/test_ensemble_config.py b/tests/unit_tests/config/test_ensemble_config.py index 3efeee91c78..2717bf3cb71 100644 --- a/tests/unit_tests/config/test_ensemble_config.py +++ b/tests/unit_tests/config/test_ensemble_config.py @@ -112,7 +112,7 @@ def test_that_files_for_refcase_exists(existing_suffix, expected_suffix): @pytest.mark.usefixtures("use_tmpdir") def test_ensemble_config_duplicate_node_names(): duplicate_name = "Test_name" - Path("MULTFLT.TXT").write_text("", encoding="utf-8") + Path("MULTFLT.TXT").write_text("a UNIFORM 0 1", encoding="utf-8") Path("FAULT_TEMPLATE").write_text("", encoding="utf-8") config_dict = { ConfigKeys.GEN_DATA: [ diff --git a/tests/unit_tests/config/test_ert_config.py b/tests/unit_tests/config/test_ert_config.py index a471fb7cc97..bc7f9b6f421 100644 --- a/tests/unit_tests/config/test_ert_config.py +++ b/tests/unit_tests/config/test_ert_config.py @@ -1618,12 +1618,15 @@ def test_using_relative_path_to_eclbase_sets_jobname_to_basename(tmp_path): ) -def test_that_empty_params_file_gives_reasonable_error(tmpdir): +@pytest.mark.parametrize( + "param_config", ["coeffs_priors", "template.txt output.txt coeffs_priors"] +) +def test_that_empty_params_file_gives_reasonable_error(tmpdir, param_config): with tmpdir.as_cwd(): config = """ NUM_REALIZATIONS 1 - GEN_KW COEFFS coeffs_priors - """ + GEN_KW COEFFS """ + config += param_config with open("config.ert", mode="w", encoding="utf-8") as fh: fh.writelines(config) @@ -1632,5 +1635,9 @@ def test_that_empty_params_file_gives_reasonable_error(tmpdir): with open("coeffs_priors", mode="w", encoding="utf-8") as fh: pass + # Create an empty file named 'template.txt' + with open("template.txt", mode="w", encoding="utf-8") as fh: + pass + with pytest.raises(ConfigValidationError, match="No parameters specified in"): ErtConfig.from_file("config.ert")