diff --git a/lib/galaxy/tool_util/lint.py b/lib/galaxy/tool_util/lint.py index 60fe25c03667..44ab28b9790e 100644 --- a/lib/galaxy/tool_util/lint.py +++ b/lib/galaxy/tool_util/lint.py @@ -83,10 +83,13 @@ def __init__(self, level: str, message: str, **kwargs): def __eq__(self, other) -> bool: """ add equal operator to easy lookup of a message in a - List[LintMessage] which is usefull in tests + List[LintMessage] which is useful in tests. + + If the other object is a string, it is loosely checked if the + string is contained in the message. """ if isinstance(other, str): - return self.message == other + return other in self.message if isinstance(other, LintMessage): return self.message == other.message return False diff --git a/lib/galaxy/tool_util/linters/inputs.py b/lib/galaxy/tool_util/linters/inputs.py index 0540856be567..0c619e49095f 100644 --- a/lib/galaxy/tool_util/linters/inputs.py +++ b/lib/galaxy/tool_util/linters/inputs.py @@ -1,4 +1,5 @@ """This module contains a linting functions for tool inputs.""" +import ast import re from typing import TYPE_CHECKING @@ -395,14 +396,17 @@ def lint_inputs(tool_source: "ToolSource", lint_ctx: "LintContext"): f"Parameter [{param_name}]: attribute '{attrib}' is incompatible with validator of type '{vtype}'", node=validator, ) - if vtype == "expression": + if vtype in ["expression", "regex"]: if validator.text is None: lint_ctx.error( - f"Parameter [{param_name}]: expression validators are expected to contain text", node=validator + f"Parameter [{param_name}]: {vtype} validators are expected to contain text", node=validator ) else: try: - re.compile(validator.text) + if vtype == "regex": + re.compile(validator.text) + else: + ast.parse(validator.text, mode="eval") except Exception as e: lint_ctx.error( f"Parameter [{param_name}]: '{validator.text}' is no valid regular expression: {str(e)}", diff --git a/test/unit/tool_util/test_tool_linters.py b/test/unit/tool_util/test_tool_linters.py index bd5f3a3160e6..7b2f134192a9 100644 --- a/test/unit/tool_util/test_tool_linters.py +++ b/test/unit/tool_util/test_tool_linters.py @@ -410,7 +410,9 @@ TEXT - [ + [ + ( + value and "," not in value @@ -1384,10 +1386,12 @@ def test_inputs_validator_incompatibilities(lint_ctx): in lint_ctx.error_messages ) assert "Parameter [param_name]: expression validators are expected to contain text" in lint_ctx.error_messages + assert "Parameter [param_name]: regex validators are expected to contain text" in lint_ctx.error_messages assert ( "Parameter [param_name]: '[' is no valid regular expression: unterminated character set at position 0" in lint_ctx.error_messages ) + assert "Parameter [param_name]: '(' is no valid regular expression" in lint_ctx.error_messages assert ( "Parameter [another_param_name]: 'metadata' validators need to define the 'check' or 'skip' attribute(s)" in lint_ctx.error_messages @@ -1407,7 +1411,7 @@ def test_inputs_validator_incompatibilities(lint_ctx): assert len(lint_ctx.info_messages) == 1 assert not lint_ctx.valid_messages assert len(lint_ctx.warn_messages) == 1 - assert len(lint_ctx.error_messages) == 9 + assert len(lint_ctx.error_messages) == 11 def test_inputs_validator_correct(lint_ctx):