Skip to content

Commit

Permalink
Merge pull request #5706 from bernt-matthias/map-data
Browse files Browse the repository at this point in the history
Extend `map_param_value` to datasets
  • Loading branch information
mvdbeek authored Jan 10, 2024
2 parents 7536270 + 4f913b2 commit 709b05f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
57 changes: 53 additions & 4 deletions tools/map_param_value/map_param_value.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<tool name="Map parameter value" id="map_param_value" version="0.1.1" tool_type="expression" profile="22.01">
<tool name="Map parameter value" id="map_param_value" version="0.2.0" tool_type="expression" profile="22.01">
<macros>
<xml name="when_element" tokens="type_selection">
<param name="input_param" type="@TYPE_SELECTION@" optional="true" label="Value to map">
<sanitizer sanitize="false"/>
</param>
<repeat name="mappings" label="Add value mapping">
<repeat name="mappings" title="Add value mapping">
<param name="from" type="@TYPE_SELECTION@" optional="true" label="Map from this value">
<sanitizer sanitize="false"/>
</param>
Expand Down Expand Up @@ -55,6 +55,7 @@ return { output: coerceToOutput(source) };
<option value="integer">Integer</option>
<option value="float">Float</option>
<option value="boolean">Boolean</option>
<option value="data">Dataset</option>
</param>
<when value="text">
<expand macro="when_element" type_selection="text"/>
Expand All @@ -68,6 +69,9 @@ return { output: coerceToOutput(source) };
<when value="boolean">
<expand macro="when_element" type_selection="boolean"/>
</when>
<when value="data">
<expand macro="when_element" type_selection="data"/>
</when>
</conditional>
<conditional name="unmapped">
<param name="on_unmapped" type="select" label="Select how to handle unmapped values">
Expand Down Expand Up @@ -251,7 +255,7 @@ return { output: coerceToOutput(source) };
<param name="output_param_type" value="integer"/>
<output name="output_param_integer" value_json="2" />
</test>
<test expect_num_outputs="1">A
<test expect_num_outputs="1">
<!-- map string False to boolean false -->
<conditional name="input_param_type">
<param name="type" value="text" />
Expand Down Expand Up @@ -344,12 +348,57 @@ return { output: coerceToOutput(source) };
<output name="output_param_text" value_json="null" />
</test>
-->
<!-- two tests (1 wo the optional input and one with the optional input) showing
how to map a optional input to True/False depending on if the dataset is
given/not -->
<test expect_num_outputs="1">
<conditional name="input_param_type">
<param name="type" value="data" />
<repeat name="mappings">
<param name="to" value_json="false" />
</repeat>
</conditional>
<conditional name="unmapped">
<param name="on_unmapped" value="default"/>
<param name="default_value" value="true"/>
</conditional>
<param name="output_param_type" value="boolean"/>
<output name="output_param_text" value_json="false" />
</test>
<test expect_num_outputs="1">
<conditional name="input_param_type">
<param name="input_param" value="test.txt" ftype="txt" />
<param name="type" value="data" />
<repeat name="mappings">
<param name="to" value_json="false" />
</repeat>
</conditional>
<conditional name="unmapped">
<param name="on_unmapped" value="default"/>
<param name="default_value" value="true"/>
</conditional>
<param name="output_param_type" value="boolean"/>
<output name="output_param_text" value_json="true" />
</test>
<!-- another test checking of two datasets are the same -->
<test expect_num_outputs="1">
<conditional name="input_param_type">
<param name="input_param" value="test.txt" ftype="txt" />
<param name="type" value="data" />
<repeat name="mappings">
<param name="from" value="test.txt" ftype="txt" />
<param name="to" value_json="true" />
</repeat>
</conditional>
<param name="output_param_type" value="boolean"/>
<output name="output_param_text" value_json="true" />
</test>
</tests>
<help><![CDATA[
**What it does**
Maps a parameter value to another value.
This can be used to transform any non-data value (text, integer, float and boolean) to a different value of a different type.
This can be used to transform any value (text, integer, float and boolean, dataset) to a different non-dataset value of a different type.
**Settings**
Expand Down
1 change: 1 addition & 0 deletions tools/map_param_value/test-data/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test

0 comments on commit 709b05f

Please sign in to comment.