Skip to content

Commit

Permalink
Add validation of gen kw from runpath
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Oct 11, 2023
1 parent c9205fb commit 01ccecd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ert/config/gen_kw_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ def _values_from_file(
# internal order of sub-parameters:
df = df.set_index(df.columns[0])
return df.reindex(keys).values.flatten()
if not np.issubdtype(df.values.dtype, np.number):
raise ValueError(
f"The file {file_name} did not contain numbers, got {df.values.dtype}"
)
return df.values.flatten()

@staticmethod
Expand Down
17 changes: 17 additions & 0 deletions tests/unit_tests/config/test_gen_kw_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,3 +542,20 @@ def test_gen_kw_config_validation():
],
}
)


def test_incorrect_values_in_forward_init_file_fails(tmp_path):
(tmp_path / "forward_init_1").write_text("incorrect", encoding="utf-8")
with pytest.raises(
ValueError,
match=f"{tmp_path / 'forward_init_1'} did not contain numbers, got object",
):
GenKwConfig(
"GEN_KW",
True,
None,
None,
[],
str(tmp_path / "forward_init_%d"),
None,
).read_from_runpath(tmp_path, 1)

0 comments on commit 01ccecd

Please sign in to comment.