Permalink
Browse files

Revise select linting.

Lint that options are specified somehow (either dynamic_options, an options tag, or individual option elements). Fixes #373.

Fix bug introduced in c444855.

More testing.
  • Loading branch information...
jmchilton committed Nov 10, 2015
1 parent 8fb6dcc commit 8b31850bf8c719412ba145276770eacdee95a559
@@ -24,6 +24,23 @@ def lint_inputs(tool_xml, lint_ctx):
if param_type == "data":
if "format" not in param_attrib:
lint_ctx.warn("Param input [%s] with no format specified - 'data' format will be assumed.", param_name)

if param_type == "select":
select_name = param.get("name", None) or param.get("argument", None)
dynamic_options = param.get("dynamic_options", None)
if dynamic_options is None:
dynamic_options = param.find("options")

select_options = _find_with_attribute(param, 'option', 'value')
if any(['value' not in option.attrib for option in select_options]):
lint_ctx.error("Option without value")

select_option_ids = [option.attrib.get('value', None) for option in select_options]

if dynamic_options is None and len(select_options) == 0:
message = "No options defined for select [%s]" % select_name
lint_ctx.warn(message)

# TODO: Validate type, much more...

conditional_selects = tool_xml.findall("./inputs//conditional")
@@ -37,9 +54,6 @@ def lint_inputs(tool_xml, lint_ctx):

for select in selects:
select_options = select.findall(select, 'option', 'value')
if any(['value' not in option.attrib for option in select_options]):
lint_ctx.error("Option without value")

select_option_ids = [option.attrib.get('value', None) for option in select_options]

for boolean in booleans:
@@ -89,9 +103,9 @@ def lint_repeats(tool_xml, lint_ctx):
def _find_with_attribute(element, tag, attribute, test_value=None):
rval = []
for el in (element.findall('./%s' % tag) or []):
if attribute not in el.attribute:
if attribute not in el.attrib:
continue
value = el.attribute[attribute]
value = el.attrib[attribute]
if test_value is not None:
if value == test_value:
rval.append(el)
@@ -0,0 +1,28 @@
<tool id="fail_select_param" name="fail_select_param" version="1.0">
<description>select param</description>
<command>
echo "$select_opt" > $output
</command>
<inputs>
<param name="select_opt" type="select" label="Option"/>
</inputs>
<outputs>
<data name="output" format="txt"/>
</outputs>
<tests>
<test>
<param name="select_opt" value="Hello World!" />
<output name="output">
<assert_contents>
<has_line line="Hello World!" />
</assert_contents>
</output>
</test>
</tests>
<help>
Some Awesome Help!
</help>
<citations>
<citation type="doi">10.1101/014043</citation>
</citations>
</tool>
@@ -0,0 +1,30 @@
<tool id="ok_select_param" name="ok_select_param" version="1.0">
<description>select param</description>
<command>
echo "$select_opt" > $output
</command>
<inputs>
<param name="select_opt" type="select" label="Option">
<option value="moo">Cow</option>
</param>
</inputs>
<outputs>
<data name="output" format="txt"/>
</outputs>
<tests>
<test>
<param name="select_opt" value="Hello World!" />
<output name="output">
<assert_contents>
<has_line line="Hello World!" />
</assert_contents>
</output>
</test>
</tests>
<help>
Some Awesome Help!
</help>
<citations>
<citation type="doi">10.1101/014043</citation>
</citations>
</tool>

0 comments on commit 8b31850

Please sign in to comment.