3 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/97b801cca67e/ Changeset: 97b801cca67e User: jmchilton Date: 2014-12-24 02:42:37+00:00 Summary: More tool panel manager unit tests. (Including adding file missing with previous commit 697b58f0.) Affected #: 3 files diff -r 697b58fa885a215bbcd33aa6e09c8f98e2c8b7fe -r 97b801cca67e566839e9c7fdaf5c558ff1eebab4 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 @@ -105,6 +105,8 @@ else: tool_elem = XmlET.Element( 'tool' ) tool_elem.attrib[ 'file' ] = tool_file_path + if not tool.guid: + raise ValueError("tool has no guid") tool_elem.attrib[ 'guid' ] = tool.guid tool_shed_elem = XmlET.SubElement( tool_elem, 'tool_shed' ) tool_shed_elem.text = tool_shed diff -r 697b58fa885a215bbcd33aa6e09c8f98e2c8b7fe -r 97b801cca67e566839e9c7fdaf5c558ff1eebab4 test/unit/tool_shed_unit_tests/test_tool_panel_manager.py --- /dev/null +++ b/test/unit/tool_shed_unit_tests/test_tool_panel_manager.py @@ -0,0 +1,73 @@ +import os + +from galaxy.util import parse_xml + +from tools.test_toolbox import BaseToolBoxTestCase +from tool_shed.galaxy_install.tools import tool_panel_manager + + +class ToolPanelManagerTestCase( BaseToolBoxTestCase ): + + def test_handle_tool_panel_section( self ): + self._init_tool() + self._add_config( """<toolbox><section id="tid" name="test"><tool file="tool.xml" /></section></toolbox>""" ) + toolbox = self.toolbox + tpm = tool_panel_manager.ToolPanelManager( self.app ) + # Test fetch existing section by id. + section_id, section = tpm.handle_tool_panel_section( toolbox, tool_panel_section_id="tid" ) + assert section_id == "tid" + assert len( section.elems ) == 1 # tool.xml + assert section.id == "tid" + assert len( toolbox.tool_panel ) == 1 + + section_id, section = tpm.handle_tool_panel_section( toolbox, new_tool_panel_section_label="tid2" ) + assert section_id == "tid2" + assert len( section.elems ) == 0 # new section + assert section.id == "tid2" + assert len( toolbox.tool_panel ) == 2 + + # Test re-fetch new section by same id. + section_id, section = tpm.handle_tool_panel_section( toolbox, new_tool_panel_section_label="tid2" ) + assert section_id == "tid2" + assert len( section.elems ) == 0 # new section + assert section.id == "tid2" + assert len( toolbox.tool_panel ) == 2 + + def test_add_tool_to_panel( self ): + self._init_tool() + self._add_config( """<toolbox tool_path="%s"></toolbox>""" % self.test_directory ) + tool_path = os.path.join(self.test_directory, "tool.xml") + self.tool.guid = "123456" + new_tools = [{"guid": "123456", "tool_config": tool_path}] + repository_tools_tups = [ + ( + tool_path, + "123456", + self.tool, + ) + ] + _, section = self.toolbox.get_or_create_section("tid1") + tpm = tool_panel_manager.ToolPanelManager( self.app ) + tool_panel_dict = tpm.generate_tool_panel_dict_for_new_install( + tool_dicts=new_tools, + tool_section=section, + ) + tpm.add_to_tool_panel( + repository_name="test_repo", + repository_clone_url="http://github.com/galaxyproject/example.git", + changeset_revision="0123456789abcde", + repository_tools_tups=repository_tools_tups, + owner="devteam", + shed_tool_conf="tool_conf.xml", + tool_panel_dict=tool_panel_dict, + ) + self._assert_valid_xml( self.integerated_tool_panel_path ) + self._assert_valid_xml( os.path.join( self.test_directory, "tool_conf.xml" ) ) + + def _assert_valid_xml( self, filename ): + try: + parse_xml( filename ) + except Exception: + message_template = "file %s does not contain valid XML, content %s" + message = message_template % ( filename, open( filename, "r" ).read() ) + raise AssertionError( message ) diff -r 697b58fa885a215bbcd33aa6e09c8f98e2c8b7fe -r 97b801cca67e566839e9c7fdaf5c558ff1eebab4 test/unit/tools/test_toolbox.py --- a/test/unit/tools/test_toolbox.py +++ b/test/unit/tools/test_toolbox.py @@ -23,6 +23,8 @@ def toolbox( self ): if self.__toolbox is None: self.__toolbox = SimplifiedToolBox( self ) + # wire app with this new toolbox + self.app.toolbox = self.__toolbox return self.__toolbox def setUp( self ): @@ -35,11 +37,15 @@ self.config_files = [] def _add_config( self, xml, name="tool_conf.xml" ): - path = os.path.join( self.test_directory, "tool_conf.xml" ) + path = self._tool_conf_path( name=name ) with open( path, "w" ) as f: f.write( xml ) self.config_files.append( path ) + def _tool_conf_path( self, name="tool_conf.xml" ): + path = os.path.join( self.test_directory, name ) + return path + def __reindex( self ): self.reindexed = True https://bitbucket.org/galaxy/galaxy-central/commits/f1d8ecfadb85/ Changeset: f1d8ecfadb85 User: jmchilton Date: 2014-12-24 02:42:37+00:00 Summary: PEP-8 and style tweaks to tool_panel_manager.py. Affected #: 1 file diff -r 97b801cca67e566839e9c7fdaf5c558ff1eebab4 -r f1d8ecfadb85df376846b5e4df0c0f30be569fc5 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 @@ -1,7 +1,6 @@ import logging import threading -import galaxy.tools from xml.etree import ElementTree as XmlET from tool_shed.util import basic_util @@ -67,13 +66,14 @@ self.app.toolbox.integrated_tool_panel, load_panel_dict=True ) elif config_elem.tag == 'tool': - guid = config_elem.get( 'guid' ) - self.app.toolbox.load_tool_tag_set( config_elem, - self.app.toolbox.tool_panel, - self.app.toolbox.integrated_tool_panel, - tool_path, - load_panel_dict=True, - guid=guid ) + self.app.toolbox.load_tool_tag_set( + config_elem, + self.app.toolbox.tool_panel, + self.app.toolbox.integrated_tool_panel, + tool_path, + load_panel_dict=True, + guid=config_elem.get( 'guid' ) + ) # Replace the old list of in-memory config_elems with the new list for this shed_tool_conf_dict. shed_tool_conf_dict[ 'config_elems' ] = config_elems self.app.toolbox.update_shed_config( index, shed_tool_conf_dict ) @@ -124,8 +124,9 @@ def generate_tool_panel_dict_for_new_install( self, tool_dicts, tool_section=None ): """ - When installing a repository that contains tools, all tools must currently be defined - within the same tool section in the tool panel or outside of any sections. + When installing a repository that contains tools, all tools must + currently be defined within the same tool section in the tool panel or + outside of any sections. """ tool_panel_dict = {} if tool_section: @@ -168,11 +169,12 @@ def generate_tool_panel_dict_from_shed_tool_conf_entries( self, repository ): """ - Keep track of the section in the tool panel in which this repository's tools - will be contained by parsing the shed_tool_conf in which the repository's tools - are defined and storing the tool panel definition of each tool in the repository. - This method is called only when the repository is being deactivated or un-installed - and allows for activation or re-installation using the original layout. + Keep track of the section in the tool panel in which this repository's + tools will be contained by parsing the shed_tool_conf in which the + repository's tools are defined and storing the tool panel definition + of each tool in the repository. This method is called only when the + repository is being deactivated or un-installed and allows for + activation or re-installation using the original layout. """ tool_panel_dict = {} shed_tool_conf, tool_path, relative_install_dir = \ @@ -351,8 +353,8 @@ def handle_tool_panel_selection( self, toolbox, metadata, no_changes_checked, tool_panel_section_id, new_tool_panel_section_label ): """ - Handle the selected tool panel location for loading tools included in tool shed - repositories when installing or reinstalling them. + Handle the selected tool panel location for loading tools included in + tool shed repositories when installing or reinstalling them. """ # Get the location in the tool panel in which each tool was originally loaded. tool_section = None @@ -390,10 +392,11 @@ def remove_from_shed_tool_config( self, shed_tool_conf_dict, guids_to_remove ): """ - A tool shed repository is being uninstalled so change the shed_tool_conf file. - Parse the config file to generate the entire list of config_elems instead of - using the in-memory list since it will be a subset of the entire list if one - or more repositories have been deactivated. + A tool shed repository is being uninstalled so change the + shed_tool_conf file. Parse the config file to generate the entire list + of config_elems instead of using the in-memory list since it will be a + subset of the entire list if one or more repositories have been + deactivated. """ shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ] tool_path = shed_tool_conf_dict[ 'tool_path' ] @@ -426,8 +429,8 @@ def remove_from_tool_panel( self, repository, shed_tool_conf, uninstall ): """ - A tool shed repository is being deactivated or uninstalled, so handle tool panel - alterations accordingly. + A tool shed repository is being deactivated or uninstalled, so handle + tool panel alterations accordingly. """ # Determine where the tools are currently defined in the tool panel and store this # information so the tools can be displayed in the same way when the repository is https://bitbucket.org/galaxy/galaxy-central/commits/39e603704707/ Changeset: 39e603704707 User: jmchilton Date: 2014-12-24 02:42:37+00:00 Summary: Unit test for tool panel merging tools by tool shed lineage. Affected #: 1 file diff -r f1d8ecfadb85df376846b5e4df0c0f30be569fc5 -r 39e6037047070a5014c4250dc7f47775e78452b4 test/unit/tools/test_toolbox.py --- a/test/unit/tools/test_toolbox.py +++ b/test/unit/tools/test_toolbox.py @@ -2,6 +2,7 @@ import unittest from galaxy.tools import ToolBox +from galaxy.model import tool_shed_install from galaxy.model.tool_shed_install import mapping import tools_support @@ -30,12 +31,50 @@ def setUp( self ): self.reindexed = False self.setup_app( mock_model=False ) + install_model = mapping.init( "sqlite:///:memory:", create_tables=True ) + self.app.install_model = install_model 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 _repo_install( self, changeset ): + repository = tool_shed_install.ToolShedRepository() + repository.tool_shed = "github.com" + repository.owner = "galaxyproject" + repository.name = "example" + repository.changeset_revision = changeset + repository.installed_changeset_revision = changeset + repository.deleted = False + repository.uninstalled = False + self.app.install_model.context.add( repository ) + self.app.install_model.context.flush( ) + return repository + + def _setup_two_versions( self ): + repository1 = self._repo_install( changeset="1" ) + version1 = tool_shed_install.ToolVersion() + version1.tool_id = "github.com/galaxyproect/example/test_tool/0.1" + version1.repository = repository1 + self.app.install_model.context.add( version1 ) + self.app.install_model.context.flush( ) + + repository2 = self._repo_install( changeset="2" ) + version2 = tool_shed_install.ToolVersion() + version2.tool_id = "github.com/galaxyproect/example/test_tool/0.2" + version2.repository = repository2 + + self.app.install_model.context.add( version2 ) + self.app.install_model.context.flush( ) + + version_association = tool_shed_install.ToolVersionAssociation() + version_association.parent_id = version1.id + version_association.tool_id = version2.id + + self.app.install_model.context.add( version_association ) + self.app.install_model.context.flush( ) + def _add_config( self, xml, name="tool_conf.xml" ): path = self._tool_conf_path( name=name ) with open( path, "w" ) as f: @@ -78,7 +117,49 @@ def test_groups_tools( self ): self._init_tool() - self._add_config( """<toolbox><tool file="tool.xml" /></toolbox>""" ) + self._add_config( """<toolbox tool_path="%s"> +<section id="tid" name="TID" version=""> + <tool file="tool.xml" guid="github.com/galaxyproect/example/test_tool/0.1"> + <tool_shed>github.com</tool_shed> + <repository_name>example</repository_name> + <repository_owner>galaxyproject</repository_owner> + <installed_changeset_revision>2</installed_changeset_revision> + <id>github.com/galaxyproect/example/test_tool/0.1</id> + <version>0.1</version> + </tool> +</section> +<section id="tid" name="TID" version=""> + <tool file="tool.xml" guid="github.com/galaxyproect/example/test_tool/0.2"> + <tool_shed>github.com</tool_shed> + <repository_name>example</repository_name> + <repository_owner>galaxyproject</repository_owner> + <installed_changeset_revision>2</installed_changeset_revision> + <id>github.com/galaxyproect/example/test_tool/0.2</id> + <version>0.2</version> + </tool> +</section> +</toolbox>""" % self.test_directory ) + self._setup_two_versions() + + # Assert tool versions of the tool with simple id 'test_tool' + all_versions = self.toolbox.get_tool( "test_tool", get_all_versions=True ) + assert len( all_versions ) == 2 + + # Verify lineage_ids on both tools is correctly ordered. + for version in ["0.1", "0.2"]: + guid = "github.com/galaxyproect/example/test_tool/" + version + lineage_ids = self.toolbox.get_tool( guid ).lineage_ids + assert lineage_ids[ 0 ] == "github.com/galaxyproect/example/test_tool/0.1" + assert lineage_ids[ 1 ] == "github.com/galaxyproect/example/test_tool/0.2" + + # Test tool_version attribute. + assert self.toolbox.get_tool( "test_tool", tool_version="0.1" ).guid == "github.com/galaxyproect/example/test_tool/0.1" + assert self.toolbox.get_tool( "test_tool", tool_version="0.2" ).guid == "github.com/galaxyproect/example/test_tool/0.2" + + # Assert only newer version of the tool loaded into the panel. + section = self.toolbox.tool_panel["tid"] + assert len(section.elems) == 1 + assert section.elems.values()[0].id == "github.com/galaxyproect/example/test_tool/0.2" def test_update_shed_conf(self): self.__setup_shed_tool_conf() @@ -110,7 +191,6 @@ def __init__( self, test_case ): app = test_case.app # Handle app/config stuff needed by toolbox but not by tools. - app.install_model = mapping.init( "sqlite:///:memory:", create_tables=True ) app.job_config.get_tool_resource_parameters = lambda tool_id: None app.config.update_integrated_tool_panel = True config_files = test_case.config_files 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.