def __test_arbitrary_path_rewriting( self ): self.job.parameters = [ JobParameter( name="index_path", value="\"/old/path/human\"" ) ] xml = XML('''<param name="index_path" type="select"> <option value="/old/path/human">Human</option> <option value="/old/path/mouse">Mouse</option> </param>''') parameter = SelectToolParameter( self.tool, xml ) def get_field_by_name_for_value( name, value, trans, other_values ): assert value == "/old/path/human" assert name == "path" return ["/old/path/human"] def get_options( trans, other_values ): return [ [ "", "/old/path/human", "" ] ] parameter.options = Bunch(get_field_by_name_for_value=get_field_by_name_for_value, get_options=get_options) self.tool.set_params( { "index_path": parameter } ) self.tool._command_line = "prog1 $index_path.fields.path" def test_path_rewriter(v): if v: v = v.replace("/old", "/new") return v self._set_compute_environment(path_rewriter=test_path_rewriter) command_line, extra_filenames, _ = self.evaluator.build( ) self.assertEquals(command_line, "prog1 /new/path/human")
def __test_arbitrary_path_rewriting(self): self.job.parameters = [ JobParameter(name="index_path", value="\"/old/path/human\"") ] xml = XML('''<param name="index_path" type="select"> <option value="/old/path/human">Human</option> <option value="/old/path/mouse">Mouse</option> </param>''') parameter = SelectToolParameter(self.tool, xml) def get_field_by_name_for_value(name, value, trans, other_values): assert value == "/old/path/human" assert name == "path" return ["/old/path/human"] parameter.options = Bunch( get_field_by_name_for_value=get_field_by_name_for_value) self.tool.set_params({"index_path": parameter}) self.tool._command_line = "prog1 $index_path.fields.path" def test_path_rewriter(v): if v: v = v.replace("/old", "/new") return v self._set_compute_environment(path_rewriter=test_path_rewriter) command_line, extra_filenames = self.evaluator.build() self.assertEquals(command_line, "prog1 /new/path/human")
def __test_arbitrary_path_rewriting(self): self.job.parameters = [ JobParameter(name="index_path", value="\"/old/path/human\"") ] xml = XML('''<param name="index_path" type="select"> <option value="/old/path/human">Human</option> <option value="/old/path/mouse">Mouse</option> </param>''') parameter = SelectToolParameter(self.tool, xml) def get_field_by_name_for_value(name, value, trans, other_values): assert value == "/old/path/human" assert name == "path" return ["/old/path/human"] def get_options(trans, other_values): return [["", "/old/path/human", ""]] parameter.options = Bunch( get_field_by_name_for_value=get_field_by_name_for_value, get_options=get_options) self.tool.set_params({"index_path": parameter}) self.tool._command_line = "prog1 $index_path.fields.path" self._set_compute_environment( unstructured_path_rewrites={"/old": "/new"}) command_line = self.evaluator.build()[0] self.assertEqual(command_line, "prog1 /new/path/human")
def test_conditional_evaluation(self): select_xml = XML( '''<param name="always_true" type="select"><option value="true">True</option></param>''' ) parameter = SelectToolParameter(self.tool, select_xml) conditional = Conditional() conditional.name = "c" conditional.test_param = parameter when = ConditionalWhen() when.inputs = {"thresh": self.tool.test_thresh_param()} when.value = "true" conditional.cases = [when] self.tool.set_params({"c": conditional}) self.job.parameters = [ JobParameter( name="c", value= '''{"thresh": 4, "always_true": "true", "__current_case__": 0}''' ) ] self.tool._command_line = "prog1 --thresh=${c.thresh} --test_param=${c.always_true}" self._set_compute_environment() command_line, extra_filenames = self.evaluator.build() self.assertEquals(command_line, "prog1 --thresh=4 --test_param=true")
def selectwrapper(tool, value, multiple=False, optional=False): optional = 'optional="true"' if optional else '' multiple = 'multiple="true"' if multiple else '' xml = XML('''<param name="blah" type="select" %s %s> <option value="x">I am X</option> <option value="y" selected="true">I am Y</option> <option value="z">I am Z</option> </param>''' % (multiple, optional)) parameter = SelectToolParameter(tool, xml) return SelectToolParameterWrapper(parameter, value)
def test_select_wrapper_simple_options(tool): xml = XML('''<param name="blah" type="select"> <option value="x">I am X</option> <option value="y" selected="true">I am Y</option> <option value="z">I am Z</option> </param>''') parameter = SelectToolParameter(tool, xml) wrapper = SelectToolParameterWrapper(parameter, "x", tool.app) assert str(wrapper) == "x" assert wrapper.name == "blah" assert wrapper.value_label == "I am X"
def _setup_blast_tool(tool, multiple=False): tool.app.write_test_tool_data("blastdb.loc", "val1\tname1\tpath1\nval2\tname2\tpath2\n") xml = XML('''<param name="database" type="select" label="Nucleotide BLAST database" multiple="%s"> <options from_file="blastdb.loc"> <column name="value" index="0"/> <column name="name" index="1"/> <column name="path" index="2"/> </options> </param>''' % multiple) parameter = SelectToolParameter(tool, xml) return parameter
def get_inputs( self ): # TODO: Use an external xml or yaml file to load the parameter definition parameter_type = self.state.inputs.get( "parameter_type", self.default_parameter_type ) optional = self.state.inputs.get( "optional", self.default_optional ) input_parameter_type = SelectToolParameter( None, XML( ''' <param name="parameter_type" label="Parameter type" type="select" value="%s"> <option value="text">Text</option> <option value="integer">Integer</option> <option value="float">Float</option> <option value="boolean">Boolean (True or False)</option> <option value="color">Color</option> </param> ''' % parameter_type ) ) return odict([( "parameter_type", input_parameter_type ), ( "optional", BooleanToolParameter( None, Element( "param", name="optional", label="Optional", type="boolean", value=optional )))])
def test_select_wrapper_multiple_options(tool): xml = XML('''<param name="blah" type="select" multiple="true"> <option value="x">I am X</option> <option value="y" selected="true">I am Y</option> <option value="z">I am Z</option> </param>''') parameter = SelectToolParameter(tool, xml) wrapper = SelectToolParameterWrapper(parameter, ["x"]) assert wrapper.name == "blah" assert str(wrapper) == "x" assert "x" in wrapper wrapper = SelectToolParameterWrapper(parameter, ["x", "z"]) assert str(wrapper) == "x,z" assert "x" in wrapper wrapper = SelectToolParameterWrapper(parameter, []) assert str(wrapper) == "None" assert "x" not in wrapper