commit/galaxy-central: jmchilton: Move ToolPanelManager operation to create or get section into ToolBox.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/697b58fa885a/ Changeset: 697b58fa885a User: jmchilton Date: 2014-12-23 19:22:08+00:00 Summary: Move ToolPanelManager operation to create or get section into ToolBox. Now with unit test. Part of broader effort to make ToolBox interface more explicit, tested, and hide implementation details from other parts of code (such as ToolPanelManager). Also reworked the code to now build up and re-parse XML structures - just use a dictionary - thanks to 34b3e1c. Affected #: 3 files diff -r 5328806e31ac52e01f89b89d4d7873c38d9ae07b -r 697b58fa885a215bbcd33aa6e09c8f98e2c8b7fe lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -256,6 +256,27 @@ self.write_integrated_tool_panel_config_file() app.reindex_tool_search() + def get_or_create_section( self, section_id, new_label=None ): + tool_panel_section_key = str( section_id ) + if tool_panel_section_key in self.tool_panel: + # Appending a tool to an existing section in toolbox.tool_panel + tool_section = self.tool_panel[ tool_panel_section_key ] + log.debug( "Appending to tool panel section: %s" % str( tool_section.name ) ) + else: + # Appending a new section to toolbox.tool_panel + if new_label is None: + # This might add an ugly section label to the tool panel, but, oh well... + new_label = section_id + section_dict = { + 'name': new_label, + 'id': section_id, + 'version': '', + } + tool_section = ToolSection( section_dict ) + self.tool_panel[ tool_panel_section_key ] = tool_section + log.debug( "Loading new tool panel section: %s" % str( tool_section.name ) ) + return tool_panel_section_key, tool_section + def __resolve_tool_path(self, tool_path, config_filename): if not tool_path: # Default to backward compatible config setting. diff -r 5328806e31ac52e01f89b89d4d7873c38d9ae07b -r 697b58fa885a215bbcd33aa6e09c8f98e2c8b7fe lib/tool_shed/galaxy_install/tools/tool_panel_manager.py --- a/lib/tool_shed/galaxy_install/tools/tool_panel_manager.py +++ b/lib/tool_shed/galaxy_install/tools/tool_panel_manager.py @@ -312,24 +312,7 @@ return tool_section def get_or_create_tool_section( self, toolbox, tool_panel_section_id, new_tool_panel_section_label=None ): - tool_panel_section_key = str( tool_panel_section_id ) - if tool_panel_section_key in toolbox.tool_panel: - # Appending a tool to an existing section in toolbox.tool_panel - tool_section = toolbox.tool_panel[ tool_panel_section_key ] - log.debug( "Appending to tool panel section: %s" % str( tool_section.name ) ) - else: - # Appending a new section to toolbox.tool_panel - if new_tool_panel_section_label is None: - # This might add an ugly section label to the tool panel, but, oh well... - new_tool_panel_section_label = tool_panel_section_id - elem = XmlET.Element( 'section' ) - elem.attrib[ 'name' ] = new_tool_panel_section_label - elem.attrib[ 'id' ] = tool_panel_section_id - elem.attrib[ 'version' ] = '' - tool_section = galaxy.tools.ToolSection( elem ) - toolbox.tool_panel[ tool_panel_section_key ] = tool_section - log.debug( "Loading new tool panel section: %s" % str( tool_section.name ) ) - return tool_panel_section_key, tool_section + return toolbox.get_or_create_section( section_id=tool_panel_section_id, new_label=new_tool_panel_section_label ) def get_shed_tool_conf_dict( self, shed_tool_conf ): """ diff -r 5328806e31ac52e01f89b89d4d7873c38d9ae07b -r 697b58fa885a215bbcd33aa6e09c8f98e2c8b7fe test/unit/tools/test_toolbox.py --- a/test/unit/tools/test_toolbox.py +++ b/test/unit/tools/test_toolbox.py @@ -6,63 +6,7 @@ import tools_support -class ToolBoxTestCase( unittest.TestCase, tools_support.UsesApp, tools_support.UsesTools ): - - def test_load_file( self ): - self._init_tool() - self.__add_config( """<toolbox><tool file="tool.xml" /></toolbox>""" ) - - toolbox = self.toolbox - assert toolbox.get_tool( "test_tool" ) is not None - assert toolbox.get_tool( "not_a_test_tool" ) is None - - def test_load_file_in_section( self ): - self._init_tool() - self.__add_config( """<toolbox><section id="t" name="test"><tool file="tool.xml" /></section></toolbox>""" ) - - toolbox = self.toolbox - assert toolbox.get_tool( "test_tool" ) is not None - assert toolbox.get_tool( "not_a_test_tool" ) is None - - def test_writes_integrate_tool_panel( self ): - self._init_tool() - self.__add_config( """<toolbox><tool file="tool.xml" /></toolbox>""" ) - - self.assert_integerated_tool_panel(exists=False) - self.toolbox - self.assert_integerated_tool_panel(exists=True) - - def test_groups_tools( self ): - self._init_tool() - self.__add_config( """<toolbox><tool file="tool.xml" /></toolbox>""" ) - - def test_update_shed_conf(self): - self.__setup_shed_tool_conf() - self.toolbox.update_shed_config( 0, {} ) - assert self.reindexed - self.assert_integerated_tool_panel(exists=True) - - def test_update_shed_conf_deactivate_only(self): - self.__setup_shed_tool_conf() - self.toolbox.update_shed_config( 0, {}, integrated_panel_changes=False ) - assert self.reindexed - # No changes, should be regenerated - self.assert_integerated_tool_panel(exists=False) - - def setUp( self ): - self.reindexed = False - self.setup_app( mock_model=False ) - self.app.reindex_tool_search = self.__reindex - itp_config = os.path.join(self.test_directory, "integrated_tool_panel.xml") - self.app.config.integrated_tool_panel_config = itp_config - self.__toolbox = None - self.config_files = [] - - def __reindex( self ): - self.reindexed = True - - def __remove_itp( self ): - os.remove( os.path) +class BaseToolBoxTestCase( unittest.TestCase, tools_support.UsesApp, tools_support.UsesTools ): @property def integerated_tool_panel_path( self ): @@ -81,14 +25,73 @@ self.__toolbox = SimplifiedToolBox( self ) return self.__toolbox - def __add_config( self, xml, name="tool_conf.xml" ): + def setUp( self ): + self.reindexed = False + self.setup_app( mock_model=False ) + self.app.reindex_tool_search = self.__reindex + itp_config = os.path.join(self.test_directory, "integrated_tool_panel.xml") + self.app.config.integrated_tool_panel_config = itp_config + self.__toolbox = None + self.config_files = [] + + def _add_config( self, xml, name="tool_conf.xml" ): path = os.path.join( self.test_directory, "tool_conf.xml" ) with open( path, "w" ) as f: f.write( xml ) self.config_files.append( path ) + def __reindex( self ): + self.reindexed = True + + +class ToolBoxTestCase( BaseToolBoxTestCase ): + + def test_load_file( self ): + self._init_tool() + self._add_config( """<toolbox><tool file="tool.xml" /></toolbox>""" ) + + toolbox = self.toolbox + assert toolbox.get_tool( "test_tool" ) is not None + assert toolbox.get_tool( "not_a_test_tool" ) is None + + def test_load_file_in_section( self ): + self._init_tool() + self._add_config( """<toolbox><section id="t" name="test"><tool file="tool.xml" /></section></toolbox>""" ) + + toolbox = self.toolbox + assert toolbox.get_tool( "test_tool" ) is not None + assert toolbox.get_tool( "not_a_test_tool" ) is None + + def test_writes_integrate_tool_panel( self ): + self._init_tool() + self._add_config( """<toolbox><tool file="tool.xml" /></toolbox>""" ) + + self.assert_integerated_tool_panel(exists=False) + self.toolbox + self.assert_integerated_tool_panel(exists=True) + + def test_groups_tools( self ): + self._init_tool() + self._add_config( """<toolbox><tool file="tool.xml" /></toolbox>""" ) + + def test_update_shed_conf(self): + self.__setup_shed_tool_conf() + self.toolbox.update_shed_config( 0, {} ) + assert self.reindexed + self.assert_integerated_tool_panel(exists=True) + + def test_update_shed_conf_deactivate_only(self): + self.__setup_shed_tool_conf() + self.toolbox.update_shed_config( 0, {}, integrated_panel_changes=False ) + assert self.reindexed + # No changes, should be regenerated + self.assert_integerated_tool_panel(exists=False) + + def __remove_itp( self ): + os.remove( os.path) + def __setup_shed_tool_conf( self ): - self.__add_config( """<toolbox tool_path="."></toolbox>""" ) + self._add_config( """<toolbox tool_path="."></toolbox>""" ) self.toolbox # create toolbox assert not self.reindexed 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