Skip to content

Commit 8b31850

Browse files
committed
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.
1 parent 8fb6dcc commit 8b31850

File tree

3 files changed

+77
-5
lines changed

3 files changed

+77
-5
lines changed

planemo_ext/galaxy/tools/linters/inputs.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ def lint_inputs(tool_xml, lint_ctx):
2424
if param_type == "data":
2525
if "format" not in param_attrib:
2626
lint_ctx.warn("Param input [%s] with no format specified - 'data' format will be assumed.", param_name)
27+
28+
if param_type == "select":
29+
select_name = param.get("name", None) or param.get("argument", None)
30+
dynamic_options = param.get("dynamic_options", None)
31+
if dynamic_options is None:
32+
dynamic_options = param.find("options")
33+
34+
select_options = _find_with_attribute(param, 'option', 'value')
35+
if any(['value' not in option.attrib for option in select_options]):
36+
lint_ctx.error("Option without value")
37+
38+
select_option_ids = [option.attrib.get('value', None) for option in select_options]
39+
40+
if dynamic_options is None and len(select_options) == 0:
41+
message = "No options defined for select [%s]" % select_name
42+
lint_ctx.warn(message)
43+
2744
# TODO: Validate type, much more...
2845

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

3855
for select in selects:
3956
select_options = select.findall(select, 'option', 'value')
40-
if any(['value' not in option.attrib for option in select_options]):
41-
lint_ctx.error("Option without value")
42-
4357
select_option_ids = [option.attrib.get('value', None) for option in select_options]
4458

4559
for boolean in booleans:
@@ -89,9 +103,9 @@ def lint_repeats(tool_xml, lint_ctx):
89103
def _find_with_attribute(element, tag, attribute, test_value=None):
90104
rval = []
91105
for el in (element.findall('./%s' % tag) or []):
92-
if attribute not in el.attribute:
106+
if attribute not in el.attrib:
93107
continue
94-
value = el.attribute[attribute]
108+
value = el.attrib[attribute]
95109
if test_value is not None:
96110
if value == test_value:
97111
rval.append(el)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<tool id="fail_select_param" name="fail_select_param" version="1.0">
2+
<description>select param</description>
3+
<command>
4+
echo "$select_opt" > $output
5+
</command>
6+
<inputs>
7+
<param name="select_opt" type="select" label="Option"/>
8+
</inputs>
9+
<outputs>
10+
<data name="output" format="txt"/>
11+
</outputs>
12+
<tests>
13+
<test>
14+
<param name="select_opt" value="Hello World!" />
15+
<output name="output">
16+
<assert_contents>
17+
<has_line line="Hello World!" />
18+
</assert_contents>
19+
</output>
20+
</test>
21+
</tests>
22+
<help>
23+
Some Awesome Help!
24+
</help>
25+
<citations>
26+
<citation type="doi">10.1101/014043</citation>
27+
</citations>
28+
</tool>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<tool id="ok_select_param" name="ok_select_param" version="1.0">
2+
<description>select param</description>
3+
<command>
4+
echo "$select_opt" > $output
5+
</command>
6+
<inputs>
7+
<param name="select_opt" type="select" label="Option">
8+
<option value="moo">Cow</option>
9+
</param>
10+
</inputs>
11+
<outputs>
12+
<data name="output" format="txt"/>
13+
</outputs>
14+
<tests>
15+
<test>
16+
<param name="select_opt" value="Hello World!" />
17+
<output name="output">
18+
<assert_contents>
19+
<has_line line="Hello World!" />
20+
</assert_contents>
21+
</output>
22+
</test>
23+
</tests>
24+
<help>
25+
Some Awesome Help!
26+
</help>
27+
<citations>
28+
<citation type="doi">10.1101/014043</citation>
29+
</citations>
30+
</tool>

0 commit comments

Comments
 (0)