Skip to content

Commit

Permalink
Raise ConfigValidationError with_context
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Oct 31, 2023
1 parent 80a141e commit 844a1cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
29 changes: 17 additions & 12 deletions src/ert/config/queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ert import _clib

from .parsing import ConfigDict, ConfigValidationError
from .parsing import ConfigDict, ConfigValidationError, ContextString
from .queue_system import QueueSystem

GENERIC_QUEUE_OPTIONS: List[str] = ["MAX_RUNNING"]
Expand Down Expand Up @@ -196,7 +196,7 @@ def generate_dict(option_list: List[Tuple[str, str]]) -> Dict[str, List[str]]:


def _validate_queue_driver_settings(
queue_system_options: List[Tuple[str, str]], queue_type: str
queue_system_options: List[Tuple[ContextString, ContextString]], queue_type: str
) -> None:
for option_strings in queue_system_options:
option_name = option_strings[0]
Expand All @@ -207,31 +207,35 @@ def _validate_queue_driver_settings(
option_name in memory_options[queue_type]
and re.match("[0-9]+[mg]b", option_value) is None
):
raise ConfigValidationError(
raise ConfigValidationError.with_context(
f"'{option_value}' for {option_name} is not a valid format "
f"for {queue_type} QUEUE. It must be of "
"the format '<integer>mb' or '<integer>gb'."
"the format '<integer>mb' or '<integer>gb'.",
option_value.token,

Check failure on line 214 in src/ert/config/queue_config.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"ContextString" has no attribute "token"
)
if option_name in string_options[queue_type] and not isinstance(
option_value, str
):
raise ConfigValidationError(
raise ConfigValidationError.with_context(
f"'{option_value}' for {option_name} is not a valid string type "
f"for the {queue_type} QUEUE."
f"for the {queue_type} QUEUE.",
option_value.token,
)
if option_name in positive_number_options[queue_type] and (
re.match(r"^\d+(\.\d+)?$", option_value) is None
):
raise ConfigValidationError(
raise ConfigValidationError.with_context(
f"'{option_value}' for {option_name} is not a valid integer or float"
f" for the {queue_type} QUEUE."
f" for the {queue_type} QUEUE.",
option_value.token,

Check failure on line 230 in src/ert/config/queue_config.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"ContextString" has no attribute "token"
)
if option_name in positive_int_options[queue_type] and (
re.match(r"^\d+$", option_value) is None
):
raise ConfigValidationError(
raise ConfigValidationError.with_context(
f"'{option_value}' for {option_name} is not a valid positive integer"
f" for the {queue_type} QUEUE."
f" for the {queue_type} QUEUE.",
option_value.token,

Check failure on line 238 in src/ert/config/queue_config.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"ContextString" has no attribute "token"
)
if option_name in bool_options[queue_type] and not option_value in [
"TRUE",
Expand All @@ -241,7 +245,8 @@ def _validate_queue_driver_settings(
"T",
"F",
]:
raise ConfigValidationError(
raise ConfigValidationError.with_context(
f"The '{option_value}' for {option_name} must be one of TRUE, FALSE, T, F, 1, 0 "
f" for the {queue_type}."
f" for the {queue_type}.",
option_value.token,

Check failure on line 251 in src/ert/config/queue_config.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

"ContextString" has no attribute "token"
)
6 changes: 3 additions & 3 deletions tests/unit_tests/config/test_parser_error_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,14 @@ def test_queue_option_max_running_non_int():
"""
NUM_REALIZATIONS 1
QUEUE_SYSTEM LOCAL
QUEUE_OPTION LOCAL MAX_RUNNING ert
QUEUE_OPTION LOCAL MAX_RUNNING s
"""
),
expected_error=ExpectedErrorInfo(
line=4,
column=32,
end_column=35,
match="not an integer",
match=r"'ert' for MAX_RUNNING is not a valid positive integer for the LOCAL QUEUE.",
),
)

Expand Down Expand Up @@ -675,7 +675,7 @@ def test_queue_option_max_running_negative():
line=4,
column=32,
end_column=34,
match="negative",
match="is not a valid positive integer",
),
)

Expand Down

0 comments on commit 844a1cc

Please sign in to comment.