Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
HakonSohoel committed Oct 28, 2024
1 parent 8cb4b65 commit d9defc5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/ert/config/gen_data_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,10 @@ def from_config_dict(cls, config_dict: ConfigDict) -> Optional[Self]:
_report_steps
)
except ValueError as e:
report_steps_context = next(
x for x in gen_data if x.startswith("REPORT_STEPS:")
)
raise ConfigValidationError.with_context(
f"The REPORT_STEPS setting: {_report_steps} is invalid"
" - must be a valid range string: e.g.: \"0-1, 4-6, 8\"",
report_steps_context
gen_data
) from e

_report_steps = sorted(_report_steps) if _report_steps else None
Expand Down
42 changes: 42 additions & 0 deletions tests/ert/unit_tests/config/test_gen_data_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,48 @@ def test_malformed_or_missing_gen_data_result_file(result_file, error_message):
GenDataConfig.from_config_dict({"GEN_DATA": [config_line.split()]})


@pytest.mark.parametrize(
"report_step_arg, error_message",
[
pytest.param(
"H",
"must be a valid range string",
id="Invalid REPORT_STEPS argument",
),
pytest.param(
"H,1-3",
"must be a valid range string",
id="Invalid REPORT_STEPS argument",
),
pytest.param(
"invalid-range-argument",
"must be a valid range string",
id="Invalid REPORT_STEPS argument",
),
pytest.param(
"1-2,5-8",
None,
id="This should not fail",
),
pytest.param(
"1",
None,
id="This should not fail",
),
],
)
def test_malformed_report_step_argument(report_step_arg, error_message):
config_line = f"POLY_RES RESULT_FILE:poly_%d.out REPORT_STEPS:{report_step_arg}"
if error_message:
with pytest.raises(
ConfigValidationError,
match=error_message,
):
GenDataConfig.from_config_dict({"GEN_DATA": [config_line.split()]})
else:
GenDataConfig.from_config_dict({"GEN_DATA": [config_line.split()]})


def test_that_invalid_gendata_outfile_error_propagates(tmp_path):
(tmp_path / "poly.out").write_text("""
4.910405046410615,4.910405046410615
Expand Down

0 comments on commit d9defc5

Please sign in to comment.