commit/galaxy-central: jmchilton: Merged in jmchilton/galaxy-central-fork-1 (pull request #389)
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/a50b64b9d707/ Changeset: a50b64b9d707 User: jmchilton Date: 2014-05-15 20:49:44 Summary: Merged in jmchilton/galaxy-central-fork-1 (pull request #389) Small Column Parameter Enhancements Affected #: 2 files diff -r 44ac8fc8f7b6789cff1302a15d53f6181a54118b -r a50b64b9d70704542eba7dd69410c2a25c54e2a3 lib/galaxy/tools/parameters/basic.py --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -1096,7 +1096,13 @@ self.accept_default = string_as_bool( elem.get( "accept_default", False )) self.data_ref = elem.get( "data_ref", None ) self.ref_input = None + # Legacy style default value specification... self.default_value = elem.get( "default_value", None ) + if self.default_value is None: + # Newer style... more in line with other parameters. + self.default_value = elem.get( "value", None ) + if self.default_value is not None: + self.default_value = ColumnListParameter._strip_c( self.default_value ) self.is_dynamic = True self.usecolnames = string_as_bool( elem.get( "use_header_names", False )) @@ -1105,10 +1111,6 @@ Label convention prepends column number with a 'c', but tool uses the integer. This removes the 'c' when entered into a workflow. """ - def _strip_c( column ): - if column.startswith( 'c' ): - column = column.strip().lower()[1:] - return column if self.multiple: #split on newline and , if value: @@ -1120,16 +1122,22 @@ column2 = column2.strip() if column2: column_list.append( column2 ) - value = map( _strip_c, column_list ) + value = map( ColumnListParameter._strip_c, column_list ) else: value = [] else: if value: - value = _strip_c( value ) + value = ColumnListParameter._strip_c( value ) else: value = None return super( ColumnListParameter, self ).from_html( value, trans, context ) + @staticmethod + def _strip_c(column): + if column.startswith( 'c' ): + column = column.strip().lower()[1:] + return column + def get_column_list( self, trans, other_values ): """ Generate a select list containing the columns of the associated diff -r 44ac8fc8f7b6789cff1302a15d53f6181a54118b -r a50b64b9d70704542eba7dd69410c2a25c54e2a3 test/unit/tools/test_column_parameters.py --- /dev/null +++ b/test/unit/tools/test_column_parameters.py @@ -0,0 +1,97 @@ +""" Tests for tool parameters, more tests exist in test_data_parameters.py and +test_select_parameters.py. +""" + +from unittest import TestCase +from galaxy.tools.parameters import basic +from galaxy.util import bunch +from galaxy import model +from elementtree.ElementTree import XML + +import tools_support + + +class DataColumnParameterTestCase( TestCase, tools_support.UsesApp ): + + def test_from_html(self): + value = self.param.from_html("3", self.trans, { "input_tsv": self.build_ready_hda() } ) + assert value == "3" + + def test_from_html_strips_c(self): + value = self.param.from_html("c1", self.trans, { "input_tsv": self.build_ready_hda() } ) + assert value == "1" + + def test_multiple_from_html(self): + self.multiple = True + value = self.param.from_html("1,2,3", self.trans, { "input_tsv": self.build_ready_hda() } ) + assert value == ["1", "2", "3"] + + def test_multiple_from_html_with_c(self): + self.multiple = True + value = self.param.from_html("c1,c2,c3", self.trans, { "input_tsv": self.build_ready_hda() } ) + assert value == ["1", "2", "3"] + + def test_get_initial_value_default(self): + self.assertEqual( '1', self.param.get_initial_value( self.trans, { "input_tsv": self.build_ready_hda() } ) ) + + def test_get_initial_value_override_legacy(self): + self.other_attributes = "default_value='2'" + self.assertEqual( '2', self.param.get_initial_value( self.trans, { "input_tsv": self.build_ready_hda() } ) ) + + def test_get_initial_value_override_newstyle(self): + self.other_attributes = "value='2'" + self.assertEqual( '2', self.param.get_initial_value( self.trans, { "input_tsv": self.build_ready_hda() } ) ) + + def test_get_initial_value_override_newstyle_strips_c(self): + self.other_attributes = "value='c2'" + self.assertEqual( '2', self.param.get_initial_value( self.trans, { "input_tsv": self.build_ready_hda() } ) ) + + def setUp( self ): + self.setup_app( mock_model=False ) + self.mock_tool = bunch.Bunch( + app=self.app, + tool_type="default", + ) + self.test_history = model.History() + self.app.model.context.add( self.test_history ) + self.app.model.context.flush() + self.trans = bunch.Bunch( + app=self.app, + get_history=lambda: self.test_history, + get_current_user_roles=lambda: [], + workflow_building_mode=False, + webapp=bunch.Bunch( name="galaxy" ), + ) + + self.type = "data_column" + self.other_attributes = "" + self.set_data_ref = "input_tsv" + self.multiple = False + self.optional = False + self._param = None + + def build_ready_hda(self): + hist = model.History() + self.app.model.context.add( hist ) + ready_hda = hist.add_dataset( model.HistoryDatasetAssociation( extension='interval', create_dataset=True, sa_session=self.app.model.context ) ) + ready_hda.set_dataset_state( 'ok' ) + return ready_hda + + @property + def param( self ): + if not self._param: + multi_text = "" + if self.multiple: + multi_text = 'multiple="True"' + optional_text = "" + if self.optional: + optional_text = 'optional="True"' + data_ref_text = "" + if self.set_data_ref: + data_ref_text = 'data_ref="input_tsv"' + template_xml = '''<param name="my_name" type="%s" %s %s %s %s></param>''' + self.param_xml = XML( template_xml % ( self.type, data_ref_text, multi_text, optional_text, self.other_attributes ) ) + self._param = basic.ColumnListParameter( self.mock_tool, self.param_xml ) + self._param.ref_input = bunch.Bunch(formats=[model.datatypes_registry.get_datatype_by_extension("tabular")]) + + return self._param Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org