adapt linter to check also for options_filter_attribute

This commit is contained in:
Matthias Bernt
2022-09-19 10:24:49 +02:00
parent 6ebfa1ca66
commit 1cb1ac3dfd
2 changed files with 45 additions and 8 deletions
+20 -6
View File
@@ -168,21 +168,35 @@ def lint_inputs(tool_xml, lint_ctx):
f"Param input [{param_name}] with no format specified - 'data' format will be assumed.", node=param
)
options = param.findall("./options")
has_options_filter_attribute = False
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
)
for oa in options[0].attrib:
if oa == "options_filter_attribute":
has_options_filter_attribute = True
else:
lint_ctx.error(f"Data parameter [{param_name}] uses invalid attribute: {oa}", 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":
if not f.get("ref"):
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")}"',
f"Data parameter [{param_name}] filter needs to define a ref attribute",
node=f,
)
if has_options_filter_attribute:
if f.get("type") != "data_meta":
lint_ctx.error(
f'Data parameter [{param_name}] for filters only type="data_meta" is allowed, found type="{f.get("type")}"',
node=f,
)
else:
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
+25 -2
View File
@@ -195,7 +195,19 @@ INPUTS_DATA_PARAM_OPTIONS = """
<inputs>
<param name="valid_name" type="data" format="txt">
<options>
<filter type="data_meta" key="dbkey"/>
<filter type="data_meta" key="dbkey" ref="input"/>
</options>
</param>
</inputs>
</tool>
"""
INPUTS_DATA_PARAM_OPTIONS_FILTER_ATTRIBUTE = """
<tool>
<inputs>
<param name="valid_name" type="data" format="txt">
<options options_filter_attribute="metadata.foo">
<filter type="data_meta" key="foo" ref="input"/>
</options>
</param>
</inputs>
@@ -1047,6 +1059,16 @@ def test_inputs_data_param_options(lint_ctx):
assert not lint_ctx.error_messages
def test_inputs_data_param_options_filter_attribute(lint_ctx):
tool_source = get_xml_tool_source(INPUTS_DATA_PARAM_OPTIONS_FILTER_ATTRIBUTE)
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)
@@ -1055,11 +1077,12 @@ def test_inputs_data_param_invalidoptions(lint_ctx):
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] filter needs to define a ref attribute" 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
assert len(lint_ctx.error_messages) == 3
def test_inputs_conditional(lint_ctx):