Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another round of parameter model enhancements and tool tests #18678

Merged
merged 6 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/galaxy/tool_util/parameters/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,20 @@ def _from_input_source_galaxy(input_source: InputSource) -> ToolParameterT:
options=static_options,
)
elif param_type == "data_column":
multiple = input_source.get_bool("multiple", False)
optional = input_source.parse_optional()
return DataColumnParameterModel(
name=input_source.parse_name(),
multiple=multiple,
optional=optional,
)
elif param_type == "group_tag":
multiple = input_source.get_bool("multiple", False)
optional = input_source.parse_optional()
return GroupTagParameterModel(
name=input_source.parse_name(),
optional=optional,
multiple=multiple,
)
elif param_type == "baseurl":
return BaseUrlParameterModel(
Expand Down
16 changes: 12 additions & 4 deletions lib/galaxy/tool_util/parameters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,32 +603,40 @@ def any_drill_down_options_selected(options: List[DrillDownOptionsDict]) -> bool

class DataColumnParameterModel(BaseGalaxyToolParameterModelDefinition):
parameter_type: Literal["gx_data_column"] = "gx_data_column"
multiple: bool

@property
def py_type(self) -> Type:
return StrictInt
py_type: Type = StrictInt
if self.multiple:
py_type = list_type(py_type)
return optional_if_needed(py_type, self.optional)

def pydantic_template(self, state_representation: StateRepresentationT) -> DynamicModelInformation:
return dynamic_model_information_from_py_type(self, self.py_type)

@property
def request_requires_value(self) -> bool:
return False
return self.multiple and not self.optional


class GroupTagParameterModel(BaseGalaxyToolParameterModelDefinition):
parameter_type: Literal["gx_group_tag"] = "gx_group_tag"
multiple: bool

@property
def py_type(self) -> Type:
return StrictStr
py_type: Type = StrictStr
if self.multiple:
py_type = list_type(py_type)
return optional_if_needed(py_type, self.optional)

def pydantic_template(self, state_representation: StateRepresentationT) -> DynamicModelInformation:
return dynamic_model_information_from_py_type(self, self.py_type)

@property
def request_requires_value(self) -> bool:
return True
return not self.optional


class BaseUrlParameterModel(BaseGalaxyToolParameterModelDefinition):
Expand Down
4 changes: 4 additions & 0 deletions lib/tool_shed/webapp/frontend/src/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ export interface components {
is_dynamic?: boolean
/** Label */
label?: string | null
/** Multiple */
multiple: boolean
/** Name */
name: string
/**
Expand Down Expand Up @@ -1068,6 +1070,8 @@ export interface components {
is_dynamic?: boolean
/** Label */
label?: string | null
/** Multiple */
multiple: boolean
/** Name */
name: string
/**
Expand Down
28 changes: 28 additions & 0 deletions test/functional/tools/parameters/data_column_multiple_optional.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<tool id="gx_data_column_multiple_optional" name="gx_data_column_multiple_optional" version="1.0.0">
<macros>
<import>macros.xml</import>
</macros>
<command><![CDATA[
echo 'parameter: $parameter' >> '$output'
]]></command>
<inputs>
<param name="ref_parameter" type="data" format="tabular" />
<param name="parameter" type="data_column" data_ref="ref_parameter" multiple="true" optional="true" />
</inputs>
<expand macro="simple_text_output" />
<tests>
<test>
<param name="ref_parameter" value="2.tabular" />
<param name="parameter" value="1,2,3" />
<expand macro="assert_output">
<has_line line="parameter: 1,2,3"/>
</expand>
</test>
<test>
<param name="ref_parameter" value="2.tabular" />
<expand macro="assert_output">
<has_line line="parameter: None"/>
</expand>
</test>
</tests>
</tool>
36 changes: 36 additions & 0 deletions test/functional/tools/parameters/gx_data_column_multiple.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<tool id="gx_data_column_multiple" name="gx_data_column_multiple" version="1.0.0">
<macros>
<import>macros.xml</import>
</macros>
<command><![CDATA[
echo 'parameter: $parameter' >> '$output'
]]></command>
<inputs>
<param name="ref_parameter" type="data" format="tabular" />
<param name="parameter" type="data_column" data_ref="ref_parameter" multiple="true" />
</inputs>
<expand macro="simple_text_output" />
<tests>
<test>
<param name="ref_parameter" value="2.tabular" />
<param name="parameter" value="1" />
<expand macro="assert_output">
<has_line line="parameter: 1"/>
</expand>
</test>
<test>
<param name="ref_parameter" value="2.tabular" />
<param name="parameter" value="1,2,3" />
<expand macro="assert_output">
<has_line line="parameter: 1,2,3"/>
</expand>
</test>
<!-- these parameters are not implicitly optional! -->
<test expect_failure="true">
<param name="ref_parameter" value="2.tabular" />
<expand macro="assert_output">
<has_line line="parameter: 1"/>
</expand>
</test>
</tests>
</tool>
28 changes: 28 additions & 0 deletions test/functional/tools/parameters/gx_data_column_optional.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<tool id="gx_data_column_optional" name="gx_data_column_optional" version="1.0.0">
<macros>
<import>macros.xml</import>
</macros>
<command><![CDATA[
echo 'parameter: $parameter' >> '$output'
]]></command>
<inputs>
<param name="ref_parameter" type="data" format="tabular" />
<param name="parameter" type="data_column" data_ref="ref_parameter" optional="true" />
</inputs>
<expand macro="simple_text_output" />
<tests>
<test>
<param name="ref_parameter" value="2.tabular" />
<param name="parameter" value="1" />
<expand macro="assert_output">
<has_line line="parameter: 1"/>
</expand>
</test>
<test>
<param name="ref_parameter" value="2.tabular" />
<expand macro="assert_output">
<has_line line="parameter: None"/>
</expand>
</test>
</tests>
</tool>
39 changes: 39 additions & 0 deletions test/functional/tools/parameters/gx_group_tag_multiple.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<tool id="gx_group_tag_multiple" name="gx_group_tag_multiple" version="1.0.0">
<macros>
<import>macros.xml</import>
</macros>
<command><![CDATA[
echo "parameter: $parameter" > '$output'
]]></command>
<inputs>
<param name="ref_parameter" type="data_collection" format="tabular" />
<param name="parameter" type="group_tag" data_ref="ref_parameter" multiple="true" />
</inputs>
<expand macro="simple_text_output" />
<tests>
<test>
<param name="ref_parameter">
<collection type="paired">
<element name="forward" value="simple_line.txt" tags="group:type:single" />
<element name="reverse" value="simple_line_alternative.txt" tags="group:type:split" />
</collection>
</param>
<param name="parameter" value="type:single,type:split" />
<expand macro="assert_output">
<has_line line="parameter: type:single,type:split"/>
</expand>
</test>
<test expect_failure="true">
<!-- interesting... this fails here but multi-selects don't -->
<param name="ref_parameter">
<collection type="paired">
<element name="forward" value="simple_line.txt" tags="group:type:single" />
<element name="reverse" value="simple_line_alternative.txt" tags="group:type:split" />
</collection>
</param>
<expand macro="assert_output">
<has_line line="parameter: None"/>
</expand>
</test>
</tests>
</tool>
38 changes: 38 additions & 0 deletions test/functional/tools/parameters/gx_group_tag_optional.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<tool id="gx_group_tag_optional" name="gx_group_tag_optional" version="1.0.0">
<macros>
<import>macros.xml</import>
</macros>
<command><![CDATA[
echo "parameter: $parameter" > '$output'
]]></command>
<inputs>
<param name="ref_parameter" type="data_collection" format="tabular" />
<param name="parameter" type="group_tag" data_ref="ref_parameter" optional="true" />
</inputs>
<expand macro="simple_text_output" />
<tests>
<test>
<param name="ref_parameter">
<collection type="paired">
<element name="forward" value="simple_line.txt" tags="group:type:single" />
<element name="reverse" value="simple_line_alternative.txt" tags="group:type:split" />
</collection>
</param>
<param name="parameter" value="type:single" />
<expand macro="assert_output">
<has_line line="parameter: type:single"/>
</expand>
</test>
<test>
<param name="ref_parameter">
<collection type="paired">
<element name="forward" value="simple_line.txt" tags="group:type:single" />
<element name="reverse" value="simple_line_alternative.txt" tags="group:type:split" />
</collection>
</param>
<expand macro="assert_output">
<has_line line="parameter: None"/>
</expand>
</test>
</tests>
</tool>
8 changes: 8 additions & 0 deletions test/functional/tools/parameters/gx_select_multiple.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@ echo '$parameter' >> '$output'
</assert_contents>
</output>
</test>
<test>
<!-- these parameters are not implicitly optional and don't select top option -->
<output name="output">
<assert_contents>
<has_line line="None" />
</assert_contents>
</output>
</test>
</tests>
</tool>
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@ echo '$parameter' >> '$output'
</assert_contents>
</output>
</test>
<test>
<output name="output">
<assert_contents>
<has_line line="None" />
</assert_contents>
</output>
</test>
</tests>
</tool>
60 changes: 60 additions & 0 deletions test/unit/tool_util/parameter_specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,37 @@ gx_data_column:
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: 0 }
request_invalid:
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: "0" }
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: [ 0 ] }
request_internal_valid:
- { ref_parameter: {src: hda, id: 123}, parameter: 0 }
request_internal_invalid:
- { ref_parameter: {src: hda, id: 123}, parameter: "0" }

gx_data_column_optional:
request_valid:
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: 0 }
- { ref_parameter: {src: hda, id: abcdabcd} }
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: null }
request_invalid:
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: "0" }
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: [ 0 ] }
request_internal_valid:
- { ref_parameter: {src: hda, id: 123}, parameter: 0 }
request_internal_invalid:
- { ref_parameter: {src: hda, id: 123}, parameter: "0" }

gx_data_column_multiple:
request_valid:
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: [0] }
request_invalid:
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: "0" }
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: ["0"] }
request_internal_valid:
- { ref_parameter: {src: hda, id: 123}, parameter: [0] }
request_internal_invalid:
- { ref_parameter: {src: hda, id: 123}, parameter: "0" }
- { ref_parameter: {src: hda, id: 123}, parameter: 0 }

gx_group_tag:
request_valid:
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: 'type:matched' }
Expand All @@ -726,6 +752,40 @@ gx_group_tag:
request_internal_invalid:
- { ref_parameter: {src: hdca, id: 123}, parameter: null }

gx_group_tag_optional:
request_valid:
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: 'type:matched' }
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: 'matched' }
- { ref_parameter: { src: hdca, id: abcdabcd} }
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: null }
request_invalid:
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: 7 }
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: true }
request_internal_valid:
- { ref_parameter: {src: hdca, id: 123}, parameter: 'type: matched' }
- { ref_parameter: {src: hdca, id: 123}, parameter: null }
request_internal_invalid:
- { ref_parameter: {src: hdca, id: 123}, parameter: 8 }


gx_group_tag_multiple:
request_valid:
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: ['type:matched'] }
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: ['matched'] }
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: ['matched'] }
request_invalid:
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: 'matched' }
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: 7 }
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: true }
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: null }
- { ref_parameter: { src: hdca, id: abcdabcd} }
request_internal_valid:
- { ref_parameter: {src: hdca, id: 123}, parameter: ['type: matched'] }
request_internal_invalid:
- { ref_parameter: {src: hdca, id: 123}, parameter: 8 }
- { ref_parameter: {src: hdca, id: 123}, parameter: null }


cwl_int:
request_valid:
- parameter: 5
Expand Down
Loading