Mercurial > repos > iuc > map_param_value
changeset 1:a01f088d0e5e draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/map_param_value commit 49eab9a9d601cccd50401e5a0221264b5681b64d
author | iuc |
---|---|
date | Wed, 19 Oct 2022 11:37:19 +0000 |
parents | 43d7b3642a30 |
children | 5ac8a4bf7a8d |
files | map_param_value.xml |
diffstat | 1 files changed, 144 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/map_param_value.xml Sun Oct 16 08:05:37 2022 +0000 +++ b/map_param_value.xml Wed Oct 19 11:37:19 2022 +0000 @@ -1,10 +1,16 @@ -<tool name="Map parameter value" id="map_param_value" version="0.1.0" tool_type="expression" profile="22.01"> +<tool name="Map parameter value" id="map_param_value" version="0.1.1" tool_type="expression" profile="22.01"> <macros> <xml name="when_element" tokens="type_selection"> - <param name="input_param" type="@TYPE_SELECTION@" optional="true" label="Map this parameter value to a different value"/> + <param name="input_param" type="@TYPE_SELECTION@" optional="true" label="Value to map"> + <sanitizer sanitize="false"/> + </param> <repeat name="mappings" label="Add value mapping"> - <param name="from" type="@TYPE_SELECTION@" optional="true" label="Map from this value"></param> - <param name="to" type="text" label="to this value" help="This value must be coercable to the selected output parameter type"></param> + <param name="from" type="@TYPE_SELECTION@" optional="true" label="Map from this value"> + <sanitizer sanitize="false"/> + </param> + <param name="to" type="text" optional="true" label="to this value" help="This value must be coercable to the selected output parameter type"> + <sanitizer sanitize="false"/> + </param> </repeat> </xml> </macros> @@ -30,12 +36,12 @@ } for ( var i = 0; i < mappings.length; i++ ) { - if ( String(mappings[i].from) == source ) { + if ( String(mappings[i].from) == String(source) ) { return { output: coerceToOutput(mappings[i].to) }; } } if ( $job.unmapped.on_unmapped == "fail" ) { - return { __error_message: `text_param ${source} not found in mapping values.` }; + return { __error_message: `input_param ${source} not found in mapping values.` }; } else if ( $job.unmapped.on_unmapped == "default" ) { return { output: coerceToOutput($job.unmapped.default_value) }; } @@ -63,14 +69,8 @@ <expand macro="when_element" type_selection="boolean"/> </when> </conditional> - <param name="output_param_type" type="select" label="Select type of parameter to output"> - <option value="text">Text</option> - <option value="integer">Integer</option> - <option value="float">Float</option> - <option value="boolean">Boolean</option> - </param> <conditional name="unmapped"> - <param name="on_unmapped" type="select" label="Select how"> + <param name="on_unmapped" type="select" label="Select how to handle unmapped values"> <option value="input">Use unmodified input parameter value if input parameter value not found in mappings</option> <option value="fail">Fail if input parameter value not found in mappings</option> <option value="default">Provide a default value to use if input parameter value not found in mappings</option> @@ -81,6 +81,12 @@ <param name="default_value" type="text" label="Use this value if the input parameter value was not found in mappings"/> </when> </conditional> + <param name="output_param_type" type="select" label="Select type of parameter to output"> + <option value="text">Text</option> + <option value="integer">Integer</option> + <option value="float">Float</option> + <option value="boolean">Boolean</option> + </param> </inputs> <outputs> <output type="text" name="output_param_text" from="output"> @@ -98,6 +104,7 @@ </outputs> <tests> <test expect_num_outputs="1"> + <!-- map string A to string B --> <conditional name="input_param_type"> <param name="type" value="text"/> <param name="input_param" value="A" /> @@ -109,6 +116,19 @@ <output name="output_param_text" value_json=""B"" /> </test> <test expect_num_outputs="1"> + <!-- test that mapping works in the presence of usually sanitized characters --> + <conditional name="input_param_type"> + <param name="type" value="text"/> + <param name="input_param" value="echo $abc > 1" /> + <repeat name="mappings"> + <param name="from" value="echo $abc > 1" /> + <param name="to" value="echo $abc > 2" /> + </repeat> + </conditional> + <output name="output_param_text" value_json=""echo $abc > 2"" /> + </test> + <test expect_num_outputs="1"> + <!-- keep unmodified input if no match in mapping values --> <conditional name="input_param_type"> <param name="input_param" value="C" /> <repeat name="mappings"> @@ -118,7 +138,8 @@ </conditional> <output name="output_param_text" value_json=""C"" /> </test> - <test expect_num_outputs="1" expect_failure="true"> + <test expect_failure="true"> + <!-- fail job if no mapping found and on_unmapped is set to fail --> <conditional name="input_param_type"> <param name="input_param" value="C" /> <repeat name="mappings"> @@ -131,8 +152,8 @@ </conditional> </test> <test expect_num_outputs="1"> + <!-- map unspecified option text to string default via unmapped default value --> <conditional name="input_param_type"> - <param name="input_param" value="C" /> <repeat name="mappings"> <param name="from" value="A" /> <param name="to" value="B" /> @@ -140,11 +161,12 @@ </conditional> <conditional name="unmapped"> <param name="on_unmapped" value="default"/> - <param name="default_value" value="D"/> + <param name="default_value" value="default"/> </conditional> - <param name="output_param_text" value_json=""D"" /> + <output name="output_param_text" value_json=""default"" /> </test> <test expect_num_outputs="1"> + <!-- map string C to string X via default value --> <conditional name="input_param_type"> <param name="input_param" value="C" /> <repeat name="mappings"> @@ -156,9 +178,10 @@ <param name="on_unmapped" value="default"/> <param name="default_value" value="X"/> </conditional> - <param name="output_param_text" value_json=""X"" /> + <output name="output_param_text" value_json=""X"" /> </test> <test expect_num_outputs="1"> + <!-- map string C to string D in presence of multiple mappings --> <conditional name="input_param_type"> <param name="input_param" value="C" /> <repeat name="mappings"> @@ -170,9 +193,10 @@ <param name="to" value="D" /> </repeat> </conditional> - <param name="output_param_text" value_json=""D"" /> + <output name="output_param_text" value_json=""D"" /> </test> <test expect_num_outputs="1"> + <!-- map integer 42 to integer true value --> <conditional name="input_param_type"> <param name="type" value="integer" /> <param name="input_param" value="42" /> @@ -182,9 +206,10 @@ </repeat> </conditional> <param name="output_param_type" value="boolean"/> - <param name="output_param_boolean" value_json="true" /> + <output name="output_param_boolean" value_json="true" /> </test> <test expect_num_outputs="1"> + <!-- map float 1.2 to boolean false via unmapped default value --> <conditional name="input_param_type"> <param name="type" value="float" /> <param name="input_param" value="1.2" /> @@ -198,9 +223,10 @@ <param name="default_value" value="False"/> </conditional> <param name="output_param_type" value="boolean"/> - <param name="output_param_boolean" value_json="false" /> + <output name="output_param_boolean" value_json="false" /> </test> <test expect_num_outputs="1"> + <!-- map integer 1 to float 1.1 --> <conditional name="input_param_type"> <param name="type" value="integer" /> <param name="input_param" value="1" /> @@ -210,11 +236,12 @@ </repeat> </conditional> <param name="output_param_type" value="float"/> - <param name="output_param_float" value_json="1.1" /> + <output name="output_param_float" value_json="1.1" /> </test> <test expect_num_outputs="1"> + <!-- map string A to integer 2 --> <conditional name="input_param_type"> - <param name="type" value="string" /> + <param name="type" value="text" /> <param name="input_param" value="A" /> <repeat name="mappings"> <param name="from" value="A" /> @@ -222,8 +249,101 @@ </repeat> </conditional> <param name="output_param_type" value="integer"/> - <param name="output_param_float" value_json="2" /> + <output name="output_param_integer" value_json="2" /> + </test> + <test expect_num_outputs="1">A + <!-- map string False to boolean false --> + <conditional name="input_param_type"> + <param name="type" value="text" /> + <param name="input_param" value="False" /> + <repeat name="mappings"> + <param name="from" value="False" /> + <param name="to" value="false" /> + </repeat> + </conditional> + <conditional name="unmapped"> + <param name="on_unmapped" value="fail"/> + </conditional> + <param name="output_param_type" value="boolean"/> + <output name="output_param_boolean" value_json="false" /> + </test> + <test expect_num_outputs="1"> + <!-- map boolean false to boolean true --> + <conditional name="input_param_type"> + <param name="type" value="boolean" /> + <param name="input_param" value="false" /> + <repeat name="mappings"> + <param name="from" value="false" /> + <param name="to" value="true" /> + </repeat> + </conditional> + <conditional name="unmapped"> + <param name="on_unmapped" value="fail"/> + </conditional> + <param name="output_param_type" value="boolean"/> + <output name="output_param_boolean" value_json="true" /> + </test> + <test expect_num_outputs="1"> + <!-- map integer 0 to boolean false via default value coercion --> + <conditional name="input_param_type"> + <param name="type" value="integer" /> + <param name="input_param" value="0" /> + </conditional> + <param name="output_param_type" value="boolean"/> + <output name="output_param_boolean" value_json="false" /> </test> + <test expect_num_outputs="1"> + <!-- map null text value to boolean true --> + <conditional name="input_param_type"> + <param name="type" value="text" /> + <param name="input_param" value_json="null" /> + <repeat name="mappings"> + <param name="from" value_json="null" /> + <param name="to" value="true" /> + </repeat> + </conditional> + <param name="output_param_type" value="boolean"/> + <output name="output_param_boolean" value_json="true" /> + </test> + <test expect_num_outputs="1" doc="map null integer value to boolean true"> + <!-- map null integer value to boolean true --> + <conditional name="input_param_type"> + <param name="type" value="integer" /> + <param name="input_param" value_json="null" /> + <repeat name="mappings"> + <param name="from" value_json="null" /> + <param name="to" value="true" /> + </repeat> + </conditional> + <param name="output_param_type" value="boolean"/> + <output name="output_param_boolean" value_json="true" /> + </test> + <test expect_num_outputs="1"> + <!-- map integer value to null text --> + <conditional name="input_param_type"> + <param name="type" value="integer" /> + <param name="input_param" value="1" /> + <repeat name="mappings"> + <param name="from" value="1" /> + <param name="to" value_json="null" /> + </repeat> + </conditional> + <param name="output_param_type" value="text"/> + <output name="output_param_text" value_json="null" /> + </test> + <!-- Old Galaxy issue, optional unset text input still recorded as "" + We could work around this with a conditional, but no usecase yet + and we should better fix this in Galaxy + <test expect_num_outputs="1"> + <conditional name="input_param_type"> + <param name="input_param" value="A" /> + <repeat name="mappings"> + <param name="from" value="A" /> + </repeat> + </conditional> + <output name="output_param_text" value_json="null" /> + </test> + --> </tests> <help><![CDATA[ **What it does**