def valuewrapper(tool, value, paramtype, optional=False): parameter: ToolParameter if paramtype == "integer": optional = 'optional="true"' if optional else 'value="10"' parameter = IntegerToolParameter(tool, XML('<param name="blah" type="integer" %s min="0" />' % optional)) elif paramtype == "text": optional = 'optional="true"' if optional else 'value="foo"' parameter = TextToolParameter(tool, XML('<param name="blah" type="text" %s/>' % optional)) elif paramtype == "float": optional = 'optional="true"' if optional else 'value="10.0"' parameter = FloatToolParameter(tool, XML('<param name="blah" type="float" %s/>' % optional)) elif paramtype == "boolean": optional = 'optional="true"' if optional else 'value=""' parameter = BooleanToolParameter(tool, XML('<param name="blah" type="boolean" truevalue="truevalue" falsevalue="falsevalue" %s/>' % optional)) return InputValueWrapper(parameter, value)
def create(self, trans, payload, **kwd): """ POST /api/forms Creates a new form. """ if not trans.user_is_admin: trans.response.status = 403 return "You are not authorized to create a new form." xml_text = payload.get('xml_text', None) if xml_text is None: trans.response.status = 400 return "Missing required parameter 'xml_text'." # enhance to allow creating from more than just xml form_definition = form_factory.from_elem(XML(xml_text)) trans.sa_session.add(form_definition) trans.sa_session.flush() encoded_id = trans.security.encode_id(form_definition.id) item = form_definition.to_dict(view='element', value_mapper={ 'id': trans.security.encode_id, 'form_definition_current_id': trans.security.encode_id }) item['url'] = url_for('form', id=encoded_id) return [item]
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.assertEqual(command_line, "prog1 --thresh=4 --test_param=true")
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, extra_filenames, _ = self.evaluator.build() self.assertEqual(command_line, "prog1 /new/path/human")
def test_context(self): if self._test_context is None: option_xml = "" if self.filtered_param: option_xml = '''<options><filter type="data_meta" ref="data1" key="dbkey" /></options>''' if self.metadata_filtered_param: option_xml = ''' <options options_filter_attribute="metadata.foo"> <filter type="add_value" value="bar" /> <filter type="add_value" value="baz" /> </options>''' param_xml = XML('''<param name="data2" type="data" format="txt">%s</param>''' % option_xml) self.param = basic.DataToolParameter( self.tool, param_xml, ) trans = bunch.Bunch( app=self.app, get_current_user_roles=lambda: self.current_user_roles, workflow_building_mode=True, ) self._test_context = dataset_matcher.get_dataset_matcher_factory(trans).dataset_matcher( param=self.param, other_values=self.other_values ) return self._test_context
def quick_output(format, format_source=None, change_format_xml=None): test_output = ToolOutput("test_output") test_output.format = format test_output.format_source = format_source if change_format_xml: test_output.change_format = XML(change_format_xml) else: test_output.change_format = None return test_output
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" {} {}> <option value="x">I am X</option> <option value="y" selected="true">I am Y</option> <option value="z">I am Z</option> </param>'''.format(multiple, optional)) parameter = SelectToolParameter(tool, xml) return SelectToolParameterWrapper(parameter, value)
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 test_evaluation_of_optional_datasets(self): # Make sure optional dataset don't cause evaluation to break and # evaluate in cheetah templates as 'None'. select_xml = XML('''<param name="input1" type="data" optional="true"></param>''') parameter = DataToolParameter(self.tool, select_xml) self.job.parameters = [JobParameter(name="input1", value=u'null')] self.tool.set_params({"input1": parameter}) self.tool._command_line = "prog1 --opt_input='${input1}'" self._set_compute_environment() command_line, extra_filenames, _ = self.evaluator.build() self.assertEqual(command_line, "prog1 --opt_input='None'")
def __init__(self, config_str=DISK_TEST_CONFIG, clazz=None, store_by="id"): self.temp_directory = mkdtemp() if config_str.startswith("<"): config_file = "store.xml" else: config_file = "store.yaml" self.write(config_str, config_file) config = MockConfig(self.temp_directory, config_file, store_by=store_by) if clazz is None: self.object_store = objectstore.build_object_store_from_config(config) elif config_file == "store.xml": self.object_store = clazz.from_xml(config, XML(config_str)) else: self.object_store = clazz(config, yaml.safe_load(StringIO(config_str)))
def _drilldown_parameter(tool): xml = XML('''<param name="some_name" type="drill_down" display="checkbox" hierarchy="recurse" multiple="true"> <options> <option name="Heading 1" value="heading1"> <option name="Option 1" value="option1"/> <option name="Option 2" value="option2"/> <option name="Heading 1" value="heading1"> <option name="Option 3" value="option3"/> <option name="Option 4" value="option4"/> </option> </option> <option name="Option 5" value="option5"/> </options> </param>''') parameter = DrillDownSelectToolParameter(tool, xml) return parameter
def _parameter_for(self, **kwds): content = kwds["xml"] param_xml = XML(content) return basic.ToolParameter.build(self.mock_tool, param_xml)
def test_thresh_param(self): elem = XML('<param name="thresh" type="integer" value="5" />') return IntegerToolParameter(self, elem)