Commit 3ed87bff authored by Matthias Bernt's avatar Matthias Bernt
Browse files

linter: allow options elements in data params

linting of valid childs for params has been added here:
https://github.com/galaxyproject/galaxy/pull/12232

options for data params has been forgotten

in addition also checks for valid attribs and filter types
has been added to linting
parent 70b2ea42
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ PARAMETER_VALIDATOR_TYPE_COMPATIBILITY = {
}

PARAM_TYPE_CHILD_COMBINATIONS = [
    ("./options", ["select", "drill_down"]),
    ("./options", ["data", "select", "drill_down"]),
    ("./options/option", ["drill_down"]),
    ("./column", ["data_column"]),
]
@@ -167,6 +167,23 @@ def lint_inputs(tool_xml, lint_ctx):
                lint_ctx.warn(
                    f"Param input [{param_name}] with no format specified - 'data' format will be assumed.", node=param
                )
            options = param.findall("./options")
            if len(options) == 1:
                if len(options[0].attrib) > 0:
                    lint_ctx.error(
                        f"Data parameter [{param_name}] uses invalid attributes: {options[0].attrib}", node=param
                    )
            elif len(options) > 1:
                lint_ctx.error(f"Data parameter [{param_name}] contains multiple options elements.", node=options[1])
            # for data params only filters with key='build' of type='data_meta' are allowed
            filters = param.findall("./options/filter")
            for f in filters:
                if f.get("key") != "dbkey" or f.get("type") != "data_meta":
                    lint_ctx.error(
                        f'Data parameter [{param_name}] for filters only type="data_meta" and key="dbkey" are allowed, found type="{f.get("type")}" and key="{f.get("key")}"',
                        node=f,
                    )

        elif param_type == "select":
            # get dynamic/statically defined options
            dynamic_options = param.get("dynamic_options", None)
+51 −1
Original line number Diff line number Diff line
@@ -190,6 +190,31 @@ INPUTS_DATA_PARAM = """
</tool>
"""

INPUTS_DATA_PARAM_OPTIONS = """
<tool>
    <inputs>
        <param name="valid_name" type="data" format="txt">
            <options>
                <filter type="data_meta" key="dbkey"/>
            </options>
        </param>
    </inputs>
</tool>
"""

INPUTS_DATA_PARAM_INVALIDOPTIONS = """
<tool>
    <inputs>
        <param name="valid_name" type="data" format="txt">
            <options/>
            <options from_file="blah">
                <filter type="expression"/>
            </options>
        </param>
    </inputs>
</tool>
"""

INPUTS_CONDITIONAL = """
<tool>
    <inputs>
@@ -1012,6 +1037,31 @@ def test_inputs_data_param(lint_ctx):
    assert not lint_ctx.error_messages


def test_inputs_data_param_options(lint_ctx):
    tool_source = get_xml_tool_source(INPUTS_DATA_PARAM_OPTIONS)
    run_lint(lint_ctx, inputs.lint_inputs, tool_source)
    assert not lint_ctx.valid_messages
    assert "Found 1 input parameters." in lint_ctx.info_messages
    assert len(lint_ctx.info_messages) == 1
    assert not lint_ctx.warn_messages
    assert not lint_ctx.error_messages


def test_inputs_data_param_invalidoptions(lint_ctx):
    tool_source = get_xml_tool_source(INPUTS_DATA_PARAM_INVALIDOPTIONS)
    run_lint(lint_ctx, inputs.lint_inputs, tool_source)
    assert not lint_ctx.valid_messages
    assert "Found 1 input parameters." in lint_ctx.info_messages
    assert len(lint_ctx.info_messages) == 1
    assert not lint_ctx.warn_messages
    assert "Data parameter [valid_name] contains multiple options elements." in lint_ctx.error_messages
    assert (
        'Data parameter [valid_name] for filters only type="data_meta" and key="dbkey" are allowed, found type="expression" and key="None"'
        in lint_ctx.error_messages
    )
    assert len(lint_ctx.error_messages) == 2


def test_inputs_conditional(lint_ctx):
    tool_source = get_xml_tool_source(INPUTS_CONDITIONAL)
    run_lint(lint_ctx, inputs.lint_inputs, tool_source)
@@ -1197,7 +1247,7 @@ def test_inputs_type_child_combinations(lint_ctx):
    assert not lint_ctx.valid_messages
    assert not lint_ctx.warn_messages
    assert (
        "Parameter [text_param] './options' tags are only allowed for parameters of type ['select', 'drill_down']"
        "Parameter [text_param] './options' tags are only allowed for parameters of type ['data', 'select', 'drill_down']"
        in lint_ctx.error_messages
    )
    assert (