Merge pull request #9279 from bernt-matthias/topic/inputs-multiple-test

extend config file inputs tests
This commit is contained in:
Marius van den Beek
2020-02-20 16:09:59 +01:00
committed by GitHub
5 changed files with 79 additions and 32 deletions
+25 -20
View File
@@ -11,15 +11,15 @@ def json_wrap(inputs, input_values, as_dict=None, handle_files="skip"):
for input in inputs.values():
input_name = input.name
value = input_values[input_name]
json_value = _json_wrap_input(input, value, handle_files=handle_files)
value_wrapper = input_values[input_name]
json_value = _json_wrap_input(input, value_wrapper, handle_files=handle_files)
if json_value is SKIP_INPUT:
continue
as_dict[input_name] = json_value
return as_dict
def _json_wrap_input(input, value, handle_files="skip"):
def _json_wrap_input(input, value_wrapper, handle_files="skip"):
input_type = input.type
def _data_input_to_path(v):
@@ -30,13 +30,13 @@ def _json_wrap_input(input, value, handle_files="skip"):
if input_type == "repeat":
repeat_job_value = []
for d in value:
for d in value_wrapper:
repeat_instance_job_value = {}
json_wrap(input.inputs, d, repeat_instance_job_value, handle_files=handle_files)
repeat_job_value.append(repeat_instance_job_value)
json_value = repeat_job_value
elif input_type == "conditional":
values = value
values = value_wrapper
current = values["__current_case__"]
conditional_job_value = {}
json_wrap(input.cases[current].inputs, values, conditional_job_value, handle_files=handle_files)
@@ -46,29 +46,29 @@ def _json_wrap_input(input, value, handle_files="skip"):
conditional_job_value[test_param_name] = test_value
json_value = conditional_job_value
elif input_type == "section":
values = value
values = value_wrapper
section_job_value = {}
json_wrap(input.inputs, values, section_job_value, handle_files=handle_files)
json_value = section_job_value
elif input_type == "data" and input.multiple:
if handle_files == "paths":
json_value = list(map(_data_input_to_path, value))
json_value = list(map(_data_input_to_path, value_wrapper))
elif handle_files == "skip":
return SKIP_INPUT
else:
raise NotImplementedError()
elif input_type == "data":
if handle_files == "paths":
json_value = _data_input_to_path(value)
json_value = _data_input_to_path(value_wrapper)
elif handle_files == "skip":
return SKIP_INPUT
elif handle_files == "OBJECT":
if value:
if isinstance(value, list):
value = value[0]
json_value = _hda_to_object(value)
if value_wrapper:
if isinstance(value_wrapper, list):
value_wrapper = value_wrapper[0]
json_value = _hda_to_object(value_wrapper)
if input.load_contents:
with open(str(value), mode='rb') as fh:
with open(str(value_wrapper), mode='rb') as fh:
json_value['contents'] = fh.read(input.load_contents).decode('utf-8', errors='replace')
return json_value
else:
@@ -79,20 +79,25 @@ def _json_wrap_input(input, value, handle_files="skip"):
if handle_files == "skip":
return SKIP_INPUT
raise NotImplementedError()
elif input_type in ["select", "text", "color", "hidden"]:
json_value = _cast_if_not_none(value, str)
elif input_type in ["text", "color", "hidden"]:
json_value = _cast_if_not_none(value_wrapper, str)
elif input_type == "float":
json_value = _cast_if_not_none(value, float, empty_to_none=True)
json_value = _cast_if_not_none(value_wrapper, float, empty_to_none=True)
elif input_type == "integer":
json_value = _cast_if_not_none(value, int, empty_to_none=True)
json_value = _cast_if_not_none(value_wrapper, int, empty_to_none=True)
elif input_type == "boolean":
json_value = _cast_if_not_none(value, bool)
json_value = _cast_if_not_none(value_wrapper, bool)
elif input_type == "select":
if input.multiple:
json_value = [_ for _ in _cast_if_not_none(value_wrapper.value, list)]
else:
json_value = _cast_if_not_none(value_wrapper.value, str)
elif input_type == "data_column":
# value is a SelectToolParameterWrapper()
if input.multiple:
json_value = [int(_) for _ in _cast_if_not_none(value.value, list)]
json_value = [int(_) for _ in _cast_if_not_none(value_wrapper.value, list)]
else:
json_value = [_cast_if_not_none(value.value, int)]
json_value = [_cast_if_not_none(value_wrapper.value, int)]
else:
raise NotImplementedError("input_type [%s] not implemented" % input_type)
-1
View File
@@ -1 +0,0 @@
{"col": [11]}
@@ -1,13 +1,29 @@
<tool id="column_param_configfile" name="Column Param into configfile" >
<command>
cat '$inputs' > '$output1'
</command>
<command detect_errors="exit_code"><![CDATA[
python $check_inputs inputs.json
]]></command>
<configfiles>
<inputs name="inputs" />
<inputs name="inputs" filename="inputs.json" />
<configfile name="check_inputs"><![CDATA[
import json
import sys
input_json_path = sys.argv[1]
as_dict = json.load(open(input_json_path, "r"))
def assert_equals(x, y):
assert x == y, "%s[%s] != %s[%s] " % (x, type(x), y, type(y))
assert_equals(as_dict["col"], [11])
assert_equals(as_dict["col_mult"], [1,2,3])
with open("$output1", "w") as f:
f.write("okay\n")
]]></configfile>
</configfiles>
<inputs>
<param type="data" format="tabular" name="input1" label="Input 1" />
<param name="col" type="data_column" data_ref="input1" label="Column to Use" />
<param name="col" type="data_column" data_ref="input1" label="Column to Use"/>
<param name="col_mult" type="data_column" data_ref="input1" label="Columns to Use" multiple="true"/>
</inputs>
<outputs>
<data name="output1" format="data" />
@@ -16,7 +32,12 @@ cat '$inputs' > '$output1'
<test>
<param name="input1" value="11.tabular" />
<param name="col" value="11" />
<output name="output1" file="configfile.json"/>
<param name="col_mult" value="1,2,3" />
<output name="output1">
<assert_contents>
<has_line line="okay" />
</assert_contents>
</output>
</test>
</tests>
</tool>
+20 -4
View File
@@ -1,7 +1,8 @@
<tool id="inputs_as_json" name="inputs_as_json" version="1.0.0">
<command detect_errors="exit_code">
<command detect_errors="exit_code"><![CDATA[
cat inputs.json &&
python $check_inputs inputs.json $test_case
</command>
]]></command>
<configfiles>
<inputs name="inputs" filename="inputs.json" />
<!-- Can specify with fixed path in working directory instead:
@@ -15,9 +16,8 @@ input_json_path = sys.argv[1]
test_case = sys.argv[2]
as_dict = json.load(open(input_json_path, "r"))
def assert_equals(x, y):
assert x == y, "%s != %s" % (x, y)
assert x == y, "%s[%s] != %s[%s] " % (x, type(x), y, type(y))
if test_case == "1":
assert_equals(as_dict["test_case"], 1)
@@ -27,6 +27,8 @@ if test_case == "1":
assert_equals(as_dict["inttest"], 12456)
assert_equals(as_dict["floattest"], 6.789)
assert_equals(as_dict["radio_select"], "a_radio")
assert_equals(as_dict["optional_select"], None)
assert_equals(as_dict["optional_multiple_select"], [])
assert_equals(as_dict["repeat"][0]["r"], "000000")
assert_equals(as_dict["repeat"][1]["r"], "FFFFFF")
assert_equals(as_dict["cond"]["more_text"], "fdefault")
@@ -40,6 +42,8 @@ elif test_case == "2":
assert_equals(as_dict["inttest"], None)
assert_equals(as_dict["floattest"], 1.0)
assert_equals(as_dict["radio_select"], "a_radio")
assert_equals(as_dict["optional_select"], "a")
assert_equals(as_dict["optional_multiple_select"], ['a', 'b'])
assert_equals(as_dict["repeat"][0]["r"], "000000")
assert_equals(as_dict["cond"]["cond_test"], "second")
assert_equals(as_dict["cond"]["more_text"], "sdefault")
@@ -63,6 +67,16 @@ with open("output", "w") as f:
<option value="c_radio">C Radio</option>
</param>
<param name="data_input" type="data" optional="true" />
<param name="optional_select" type="select" optional="true">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
</param>
<param name="optional_multiple_select" type="select" optional="true" multiple="true">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
</param>
<repeat name="repeat" title="Repeat" min="1">
<param name="r" type="color" />
</repeat>
@@ -114,6 +128,8 @@ with open("output", "w") as f:
<param name="booltest" value="false" />
<param name="booltest2" value="boolfalse" />
<param name="data_input" value="simple_line.txt" />
<param name="optional_select" value="a"/>
<param name="optional_multiple_select" value="a,b"/>
<!-- Testing null integers -->
<!-- <param name="inttest" value="12456" /> -->
<param name="r" value="000000" />
@@ -17,7 +17,7 @@ as_dict = json.load(open(input_json_path, "r"))
def assert_equals(x, y):
assert x == y, "%s != %s" % (x, y)
assert x == y, "%s[%s] != %s[%s] " % (x, type(x), y, type(y))
if test_case == "1":
assert_equals(as_dict["test_case"], 1)
@@ -32,6 +32,7 @@ if test_case == "1":
assert_equals(as_dict["cond"]["more_text"], "fdefault")
assert_equals(as_dict["section_example"]["section_text"], "section_default")
assert_equals(as_dict["data_input"], None)
assert_equals(as_dict["multiple_data_input"], [None])
elif test_case == "2":
assert_equals(as_dict["test_case"], 2)
assert_equals(as_dict["text_test"], "bar")
@@ -46,6 +47,9 @@ elif test_case == "2":
assert_equals(as_dict["section_example"]["section_text"], "section_default")
data_input = as_dict["data_input"]
assert data_input is not None
multiple_data_input = as_dict["multiple_data_input"]
assert type(multiple_data_input) is list
assert len(multiple_data_input) == 2
with open("output", "w") as f:
f.write("okay\n")
@@ -64,6 +68,7 @@ with open("output", "w") as f:
<option value="c_radio">C Radio</option>
</param>
<param name="data_input" type="data" optional="true" />
<param name="multiple_data_input" type="data" optional="true" multiple="true" />
<repeat name="repeat" title="Repeat" min="1">
<param name="r" type="color" />
</repeat>
@@ -115,6 +120,7 @@ with open("output", "w") as f:
<param name="booltest" value="false" />
<param name="booltest2" value="boolfalse" />
<param name="data_input" value="simple_line.txt" />
<param name="multiple_data_input" value="simple_line.txt,simple_line_alternative.txt" />
<!-- Testing null integers -->
<!-- <param name="inttest" value="12456" /> -->
<param name="r" value="000000" />