Skip to content

Commit

Permalink
Parameter specification reference testing - conditionals with selects.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Jul 25, 2024
1 parent a26224b commit 9559f92
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/galaxy/tool_util/parameters/factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import (
Any,
cast,
Dict,
List,
Optional,
Expand Down Expand Up @@ -157,6 +158,12 @@ def _from_input_source_galaxy(input_source: InputSource) -> ToolParameterT:
default_value = object()
if isinstance(test_parameter, BooleanParameterModel):
default_value = test_parameter.value
elif isinstance(test_parameter, SelectParameterModel):
select_parameter = cast(SelectParameterModel, test_parameter)
select_default_value = select_parameter.default_value
if select_default_value is not None:
default_value = select_default_value

# TODO: handle select parameter model...
for value, case_inputs_sources in input_source.parse_when_input_sources():
if isinstance(test_parameter, BooleanParameterModel):
Expand Down
12 changes: 12 additions & 0 deletions lib/galaxy/tool_util/parameters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,18 @@ def pydantic_template(self, state_representation: StateRepresentationT) -> Dynam
def has_selected_static_option(self):
return self.options is not None and any(o.selected for o in self.options)

@property
def default_value(self) -> Optional[str]:
if self.options:
for option in self.options:
if option.selected:
return option.value
# single value pick up first value
if not self.optional:
return self.options[0].value

return None

@property
def request_requires_value(self) -> bool:
# API will allow an empty value and just grab the first static option
Expand Down
85 changes: 85 additions & 0 deletions test/functional/tools/parameters/gx_conditional_select.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<tool id="gx_conditional_select" name="gx_conditional_select" version="1.0.0">
<macros>
<import>macros.xml</import>
</macros>
<expand macro="common_conditional_tags" />
<inputs>
<conditional name="conditional_parameter">
<param name="test_parameter" type="select">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
</param>
<when value="a">
<param name="integer_parameter" type="integer" value="1" />
</when>
<when value="b">
<param name="boolean_parameter" type="boolean" />
</when>
<when value="c">
<param name="color_parameter" type="color" value="#aabbcc" />
</when>
</conditional>
</inputs>
<tests>
<test>
<expand macro="assert_output">
<has_line line="test: a" />
</expand>
<expand macro="assert_inputs_json">
<has_json_property_with_value property="test_parameter" value="&quot;a&quot;" />
<has_json_property_with_value property="integer_parameter" value="1" />
</expand>
</test>
<test>
<conditional name="conditional_parameter">
<param name="test_parameter" value="b" />
</conditional>
<expand macro="assert_output">
<has_line line="test: b" />
</expand>
<expand macro="assert_inputs_json">
<has_json_property_with_value property="test_parameter" value="&quot;b&quot;" />
<has_json_property_with_value property="boolean_parameter" value="false" />
</expand>
</test>
<test>
<conditional name="conditional_parameter">
<param name="test_parameter" value="a" />
</conditional>
<expand macro="assert_output">
<has_line line="test: a" />
</expand>
<expand macro="assert_inputs_json">
<has_json_property_with_value property="test_parameter" value="&quot;a&quot;" />
<has_json_property_with_value property="integer_parameter" value="1" />
</expand>
</test>
<test>
<conditional name="conditional_parameter">
<param name="test_parameter" value="a" />
<param name="integer_parameter" value="4" />
</conditional>
<expand macro="assert_output">
<has_line line="test: a" />
</expand>
<expand macro="assert_inputs_json">
<has_json_property_with_value property="test_parameter" value="&quot;a&quot;" />
<has_json_property_with_value property="integer_parameter" value="4" />
</expand>
</test>
<test>
<conditional name="conditional_parameter">
<param name="test_parameter" value="b" />
<param name="boolean_parameter" value="true" />
</conditional>
<expand macro="assert_output">
<has_line line="test: b" />
</expand>
<expand macro="assert_inputs_json">
<has_json_property_with_value property="test_parameter" value="&quot;b&quot;" />
<has_json_property_with_value property="boolean_parameter" value="true" />
</expand>
</test>
</tests>
</tool>
39 changes: 39 additions & 0 deletions test/unit/tool_util/parameter_specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,45 @@ gx_conditional_conditional_boolean:
inner_test_parameter: true
integer_parameter: true

gx_conditional_select:
request_valid:
- conditional_parameter:
test_parameter: a
integer_parameter: 1
- conditional_parameter:
test_parameter: a
integer_parameter: 2
- conditional_parameter:
test_parameter: b
boolean_parameter: true
# Test parameter has default and so does it "case" - so this should be fine
- {}
# # The boolean_parameter is optional so just setting a test_parameter is fine
# - conditional_parameter:
# test_parameter: b
# - conditional_parameter:
# test_parameter: a
# # if test parameter is missing, it should be 'a' in this case
# - conditional_parameter:
# integer_parameter: 4
# - conditional_parameter: {}
request_invalid:
- conditional_parameter:
test_parameter: b
integer_parameter: 1
- conditional_parameter:
test_parameter: null
- conditional_parameter:
test_parameter: a
integer_parameter: "1"
- conditional_parameter:
test_parameter: b
integer_parameter: null
# if test parameter is missing, it should be false in this case
# in that case having an integer_parameter is not acceptable.
- conditional_parameter:
boolean_parameter: true

gx_repeat_boolean:
request_valid:
- parameter:
Expand Down

0 comments on commit 9559f92

Please sign in to comment.