Skip to content

Commit

Permalink
Only set config dict entry to None if not multi occurrence
Browse files Browse the repository at this point in the history
  • Loading branch information
Yngve S. Kristiansen committed Jul 17, 2023
1 parent 5c5979e commit 87cbd16
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/ert/parsing/lark_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,16 @@ def _tree_to_dict(
cwd = os.path.dirname(os.path.abspath(config_file))

for node in tree.children:
try:
args: List[FileContextToken]
kw: FileContextToken
kw, *args = node # type: ignore
args: List[FileContextToken]
kw: FileContextToken
kw, *args = node # type: ignore
if kw not in schema:
warnings.warn(f"Unknown keyword {kw!r}", category=ConfigWarning)
continue

if kw not in schema:
warnings.warn(f"Unknown keyword {kw!r}", category=ConfigWarning)
continue
constraints = schema[kw]
constraints = schema[kw]

try:
args = constraints.join_args(args)
args = _substitute_args(args, constraints, defines)
value_list = constraints.apply_constraints(args, kw, cwd)
Expand All @@ -227,7 +227,9 @@ def _tree_to_dict(
else:
config_dict[kw] = value_list
except ConfigValidationError as e:
config_dict[kw] = None
if not constraints.multi_occurrence:
config_dict[kw] = None

errors.append(e)

try:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_config_parsing/test_ert_config_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,3 +1136,24 @@ def run(self, *args):
ert_config = ErtConfig.from_file("config.ert")

assert ert_config is not None


@pytest.mark.usefixtures("use_tmpdir")
def test_that_missing_arglist_does_not_affect_subsequent_calls():
"""
Check that the summary without arglist causes a ConfigValidationError and
not an error from appending to None parsed from SUMMARY w/o arglist
"""
with open("config.ert", mode="w", encoding="utf-8") as fh:
fh.write(
dedent(
"""
NUM_REALIZATIONS 1
SUMMARY
SUMMARY B 2
"""
)
)

with pytest.raises(ConfigValidationError, match="must have at least"):
_ = lark_parse("config.ert", schema=init_user_config_schema())

0 comments on commit 87cbd16

Please sign in to comment.