diff --git a/lib/galaxy/tools/test.py b/lib/galaxy/tools/test.py index babdcb84fe2..07837255dc2 100644 --- a/lib/galaxy/tools/test.py +++ b/lib/galaxy/tools/test.py @@ -71,9 +71,8 @@ class ToolTestBuilder( object ): # No explicit value for param in test case, determine from default query_value = test_param.checked else: - # Test case supplied value, check cases against this. - query_value = string_as_bool( declared_value ) - matches_declared_value = lambda case_value: string_as_bool(case_value) == query_value + query_value = _process_bool_param_value( test_param, declared_value ) + matches_declared_value = lambda case_value: _process_bool_param_value( test_param, case_value ) == query_value elif isinstance(test_param, galaxy.tools.parameters.basic.SelectToolParameter): if declared_value is not None: # Test case supplied explicit value to check against. @@ -166,7 +165,8 @@ class ToolTestBuilder( object ): # as a new instance with value defined and hence enter # an infinite loop - hence the "case_value is not None" # check. - expanded_inputs[ case_context.for_state() ] = expanded_case_value + processed_value = _process_simple_value( value.test_param, expanded_case_value ) + expanded_inputs[ case_context.for_state() ] = processed_value elif isinstance( value, galaxy.tools.parameters.grouping.Section ): context = ParamContext( name=value.name, parent_context=parent_context ) for r_name, r_value in value.inputs.iteritems(): @@ -203,33 +203,8 @@ class ToolTestBuilder( object ): for ( name, value, extra ) in collection_def.collect_inputs(): require_file( name, value, extra, self.required_files ) processed_value = collection_def - elif isinstance( value, galaxy.tools.parameters.basic.SelectToolParameter ) and hasattr( value, 'static_options' ): - # Tests may specify values as either raw value or the value - # as they appear in the list - the API doesn't and shouldn't - # accept the text value - so we need to convert the text - # into the form value. - def process_param_value( param_value ): - found_value = False - value_for_text = None - if value.static_options: - for (text, opt_value, selected) in value.static_options: - if param_value == opt_value: - found_value = True - if value_for_text is None and param_value == text: - value_for_text = opt_value - if not found_value and value_for_text is not None: - processed_value = value_for_text - else: - processed_value = param_value - return processed_value - # Do replacement described above for lists or singleton - # values. - if isinstance( param_value, list ): - processed_value = map( process_param_value, param_value ) - else: - processed_value = process_param_value( param_value ) else: - processed_value = param_value + processed_value = _process_simple_value( value, param_value ) expanded_inputs[ context.for_state() ] = processed_value return expanded_inputs @@ -240,6 +215,54 @@ class ToolTestBuilder( object ): return require_file( name, value, extra, self.required_files ) +def _process_simple_value( param, param_value ): + if isinstance( param, galaxy.tools.parameters.basic.SelectToolParameter ) and hasattr( param, 'static_options' ): + # Tests may specify values as either raw value or the value + # as they appear in the list - the API doesn't and shouldn't + # accept the text value - so we need to convert the text + # into the form value. + def process_param_value( param_value ): + found_value = False + value_for_text = None + if param.static_options: + for (text, opt_value, selected) in param.static_options: + if param_value == opt_value: + found_value = True + if value_for_text is None and param_value == text: + value_for_text = opt_value + if not found_value and value_for_text is not None: + processed_value = value_for_text + else: + processed_value = param_value + return processed_value + # Do replacement described above for lists or singleton + # values. + if isinstance( param_value, list ): + processed_value = map( process_param_value, param_value ) + else: + processed_value = process_param_value( param_value ) + elif isinstance( param, galaxy.tools.parameters.basic.BooleanToolParameter ): + # Like above, tests may use the tool define values of simply + # true/false. + processed_value = _process_bool_param_value( param, param_value ) + else: + processed_value = param_value + return processed_value + + +def _process_bool_param_value( param, param_value ): + assert isinstance( param, galaxy.tools.parameters.basic.BooleanToolParameter ) + if isinstance( param_value, list ): + param_value = param_value[0] + if param.truevalue == param_value: + processed_value = True + elif param.falsevalue == param_value: + processed_value = False + else: + processed_value = string_as_bool( param_value ) + return processed_value + + @nottest def test_data_iter( required_files ): for fname, extra in required_files: diff --git a/test/functional/tools/boolean_conditional.xml b/test/functional/tools/boolean_conditional.xml new file mode 100644 index 00000000000..df699e267a8 --- /dev/null +++ b/test/functional/tools/boolean_conditional.xml @@ -0,0 +1,53 @@ + + + echo "$p1.p1val" >> $out_file1; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/functional/tools/samples_tool_conf.xml b/test/functional/tools/samples_tool_conf.xml index c4c86f5272f..948793afa9b 100644 --- a/test/functional/tools/samples_tool_conf.xml +++ b/test/functional/tools/samples_tool_conf.xml @@ -3,6 +3,7 @@ + diff --git a/test/functional/tools/simple_constructs.xml b/test/functional/tools/simple_constructs.xml index d67c0c282ee..6fdde0ff154 100644 --- a/test/functional/tools/simple_constructs.xml +++ b/test/functional/tools/simple_constructs.xml @@ -61,5 +61,17 @@ + + + + + + + + + + + +