From 6cf064270b8d8a9137db786c97d6a0c3c1382776 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Mon, 17 Mar 2025 15:02:27 +0100 Subject: [PATCH 1/7] try to add TS tests --- bioblend/_tests/TestGalaxyToolShed.py | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 bioblend/_tests/TestGalaxyToolShed.py diff --git a/bioblend/_tests/TestGalaxyToolShed.py b/bioblend/_tests/TestGalaxyToolShed.py new file mode 100644 index 000000000..fc8a27c4c --- /dev/null +++ b/bioblend/_tests/TestGalaxyToolShed.py @@ -0,0 +1,40 @@ +""" """ + +import os +from typing import Any + +from bioblend.galaxy.tools.inputs import ( + conditional, + dataset, + inputs, + repeat, +) +from . import ( + GalaxyTestBase, + test_util, +) + + +class TestGalaxyToolShed(GalaxyTestBase.GalaxyTestBase): + def test_install(self): + for revision in ['52fbe4eb7ce7', '61acf8a76396', '6b8580e02e99', 'bd518ee51da5', 'c14c7fd4d1be']: + response = self.gi.toolshed.install_repository_revision( + "https://toolshed.g2.bx.psu.edu/", + "ampvis2_alpha_diversity", + "iuc", + revision + ) + assert isinstance(response, list), str(response) + assert len(response) == 1 + assert response[0]["status"] == 'Installed' + + for revision in ['289d6299bd2e', '77000428c613']: + response = self.gi.toolshed.install_repository_revision( + "https://toolshed.g2.bx.psu.edu/", + "ampvis2_alpha_diversity", + "iuc", + revision + ) + assert isinstance(response, list), str(response) + assert len(response) == 1 + assert response[0]["status"] == 'Installed' From 6205e1b35b0b9683aef47cc6fbc4a80a7d97f9b4 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Mon, 17 Mar 2025 16:58:20 +0100 Subject: [PATCH 2/7] fix --- bioblend/_tests/TestGalaxyToolShed.py | 108 +++++++++++++++++--------- 1 file changed, 73 insertions(+), 35 deletions(-) diff --git a/bioblend/_tests/TestGalaxyToolShed.py b/bioblend/_tests/TestGalaxyToolShed.py index fc8a27c4c..18bdf612f 100644 --- a/bioblend/_tests/TestGalaxyToolShed.py +++ b/bioblend/_tests/TestGalaxyToolShed.py @@ -1,40 +1,78 @@ """ """ -import os -from typing import Any - -from bioblend.galaxy.tools.inputs import ( - conditional, - dataset, - inputs, - repeat, -) -from . import ( - GalaxyTestBase, - test_util, -) +from . import GalaxyTestBase class TestGalaxyToolShed(GalaxyTestBase.GalaxyTestBase): - def test_install(self): - for revision in ['52fbe4eb7ce7', '61acf8a76396', '6b8580e02e99', 'bd518ee51da5', 'c14c7fd4d1be']: - response = self.gi.toolshed.install_repository_revision( - "https://toolshed.g2.bx.psu.edu/", - "ampvis2_alpha_diversity", - "iuc", - revision - ) - assert isinstance(response, list), str(response) - assert len(response) == 1 - assert response[0]["status"] == 'Installed' - - for revision in ['289d6299bd2e', '77000428c613']: - response = self.gi.toolshed.install_repository_revision( - "https://toolshed.g2.bx.psu.edu/", - "ampvis2_alpha_diversity", - "iuc", - revision - ) - assert isinstance(response, list), str(response) - assert len(response) == 1 - assert response[0]["status"] == 'Installed' + + def test_install_old_first(self): + # test uses two revisions where the tool version has not been bumped + # 6:289d6299bd2e, 7:c14c7fd4d1be has not been bumped + + # asking to install old version immediately installs + # new version + response = self.gi.toolshed.install_repository_revision( + tool_shed_url = "https://toolshed.g2.bx.psu.edu/", + name = "ampvis2_alpha_diversity", + owner = "iuc", + changeset_revision = "289d6299bd2e", + ) + assert isinstance(response, list), str(response) + assert len(response) == 1 + assert response[0]["status"] == 'Installed' + + installed_repos = self.gi.toolshed.get_repositories() + assert len(installed_repos) == 1 + assert installed_repos[0]['installed_changeset_revision'] == 'c14c7fd4d1be' + assert installed_repos[0]['changeset_revision'] == 'c14c7fd4d1be' + + self.gi.toolshed.uninstall_repository_revision( + name = "ampvis2_alpha_diversity", + owner = "iuc", + changeset_revision = "c14c7fd4d1be", + tool_shed_url = "https://toolshed.g2.bx.psu.edu/", + remove_from_disk = True, + ) + + def test_install_new_first(self): + # 6:289d6299bd2e + # 7:c14c7fd4d1be has not been bumped + response = self.gi.toolshed.install_repository_revision( + tool_shed_url = "https://toolshed.g2.bx.psu.edu/", + name = "ampvis2_alpha_diversity", + owner = "iuc", + changeset_revision = "c14c7fd4d1be", + ) + assert isinstance(response, list), str(response) + assert len(response) == 1 + assert response[0]["status"] == 'Installed' + + installed_repos = self.gi.toolshed.get_repositories() + assert len(installed_repos) == 1 + assert installed_repos[0]['installed_changeset_revision'] == 'c14c7fd4d1be' + assert installed_repos[0]['changeset_revision'] == 'c14c7fd4d1be' + + # install older revision + # -> galaxy realizes that a tool with the same version is alredy installed + # -> responds with a dict indicating this + response = self.gi.toolshed.install_repository_revision( + tool_shed_url = "https://toolshed.g2.bx.psu.edu/", + name = "ampvis2_alpha_diversity", + owner = "iuc", + changeset_revision = "289d6299bd2e", + ) + assert isinstance(response, dict), str(response) + assert response["status"] == 'ok' + + installed_repos = self.gi.toolshed.get_repositories() + assert len(installed_repos) == 1 + assert installed_repos[0]['installed_changeset_revision'] == 'c14c7fd4d1be' + assert installed_repos[0]['changeset_revision'] == 'c14c7fd4d1be' + + self.gi.toolshed.uninstall_repository_revision( + name = "ampvis2_alpha_diversity", + owner = "iuc", + changeset_revision = "c14c7fd4d1be", + tool_shed_url = "https://toolshed.g2.bx.psu.edu/", + remove_from_disk = True, + ) From 18a38c17e4c4f87cf9a99ea1e8bc4cda71af203f Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Mon, 17 Mar 2025 18:04:20 +0100 Subject: [PATCH 3/7] fix linter errors --- bioblend/_tests/TestGalaxyToolShed.py | 46 +++++++++++++-------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/bioblend/_tests/TestGalaxyToolShed.py b/bioblend/_tests/TestGalaxyToolShed.py index 18bdf612f..e407464da 100644 --- a/bioblend/_tests/TestGalaxyToolShed.py +++ b/bioblend/_tests/TestGalaxyToolShed.py @@ -12,10 +12,10 @@ def test_install_old_first(self): # asking to install old version immediately installs # new version response = self.gi.toolshed.install_repository_revision( - tool_shed_url = "https://toolshed.g2.bx.psu.edu/", - name = "ampvis2_alpha_diversity", - owner = "iuc", - changeset_revision = "289d6299bd2e", + tool_shed_url="https://toolshed.g2.bx.psu.edu/", + name="ampvis2_alpha_diversity", + owner="iuc", + changeset_revision="289d6299bd2e", ) assert isinstance(response, list), str(response) assert len(response) == 1 @@ -27,21 +27,21 @@ def test_install_old_first(self): assert installed_repos[0]['changeset_revision'] == 'c14c7fd4d1be' self.gi.toolshed.uninstall_repository_revision( - name = "ampvis2_alpha_diversity", - owner = "iuc", - changeset_revision = "c14c7fd4d1be", - tool_shed_url = "https://toolshed.g2.bx.psu.edu/", - remove_from_disk = True, + name="ampvis2_alpha_diversity", + owner="iuc", + changeset_revision="c14c7fd4d1be", + tool_shed_url="https://toolshed.g2.bx.psu.edu/", + remove_from_disk=True, ) def test_install_new_first(self): # 6:289d6299bd2e # 7:c14c7fd4d1be has not been bumped response = self.gi.toolshed.install_repository_revision( - tool_shed_url = "https://toolshed.g2.bx.psu.edu/", - name = "ampvis2_alpha_diversity", - owner = "iuc", - changeset_revision = "c14c7fd4d1be", + tool_shed_url="https://toolshed.g2.bx.psu.edu/", + name="ampvis2_alpha_diversity", + owner="iuc", + changeset_revision="c14c7fd4d1be", ) assert isinstance(response, list), str(response) assert len(response) == 1 @@ -56,10 +56,10 @@ def test_install_new_first(self): # -> galaxy realizes that a tool with the same version is alredy installed # -> responds with a dict indicating this response = self.gi.toolshed.install_repository_revision( - tool_shed_url = "https://toolshed.g2.bx.psu.edu/", - name = "ampvis2_alpha_diversity", - owner = "iuc", - changeset_revision = "289d6299bd2e", + tool_shed_url="https://toolshed.g2.bx.psu.edu/", + name="ampvis2_alpha_diversity", + owner="iuc", + changeset_revision="289d6299bd2e", ) assert isinstance(response, dict), str(response) assert response["status"] == 'ok' @@ -67,12 +67,12 @@ def test_install_new_first(self): installed_repos = self.gi.toolshed.get_repositories() assert len(installed_repos) == 1 assert installed_repos[0]['installed_changeset_revision'] == 'c14c7fd4d1be' - assert installed_repos[0]['changeset_revision'] == 'c14c7fd4d1be' + assert installed_repos[0]['changeset_revision'] == 'c14c7fd4d1be' self.gi.toolshed.uninstall_repository_revision( - name = "ampvis2_alpha_diversity", - owner = "iuc", - changeset_revision = "c14c7fd4d1be", - tool_shed_url = "https://toolshed.g2.bx.psu.edu/", - remove_from_disk = True, + name="ampvis2_alpha_diversity", + owner="iuc", + changeset_revision="c14c7fd4d1be", + tool_shed_url="https://toolshed.g2.bx.psu.edu/", + remove_from_disk=True, ) From f9dec17e288cb92c583bc7e96e5f92b0c288e5f0 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Mon, 17 Mar 2025 18:40:10 +0100 Subject: [PATCH 4/7] replace single quotes --- bioblend/_tests/TestGalaxyToolShed.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bioblend/_tests/TestGalaxyToolShed.py b/bioblend/_tests/TestGalaxyToolShed.py index e407464da..3dbe21b06 100644 --- a/bioblend/_tests/TestGalaxyToolShed.py +++ b/bioblend/_tests/TestGalaxyToolShed.py @@ -19,12 +19,12 @@ def test_install_old_first(self): ) assert isinstance(response, list), str(response) assert len(response) == 1 - assert response[0]["status"] == 'Installed' + assert response[0]["status"] == "Installed" installed_repos = self.gi.toolshed.get_repositories() assert len(installed_repos) == 1 - assert installed_repos[0]['installed_changeset_revision'] == 'c14c7fd4d1be' - assert installed_repos[0]['changeset_revision'] == 'c14c7fd4d1be' + assert installed_repos[0]["installed_changeset_revision"] == "c14c7fd4d1be" + assert installed_repos[0]["changeset_revision"] == "c14c7fd4d1be" self.gi.toolshed.uninstall_repository_revision( name="ampvis2_alpha_diversity", @@ -45,12 +45,12 @@ def test_install_new_first(self): ) assert isinstance(response, list), str(response) assert len(response) == 1 - assert response[0]["status"] == 'Installed' + assert response[0]["status"] == "Installed" installed_repos = self.gi.toolshed.get_repositories() assert len(installed_repos) == 1 - assert installed_repos[0]['installed_changeset_revision'] == 'c14c7fd4d1be' - assert installed_repos[0]['changeset_revision'] == 'c14c7fd4d1be' + assert installed_repos[0]["installed_changeset_revision"] == "c14c7fd4d1be" + assert installed_repos[0]["changeset_revision"] == "c14c7fd4d1be" # install older revision # -> galaxy realizes that a tool with the same version is alredy installed @@ -62,12 +62,12 @@ def test_install_new_first(self): changeset_revision="289d6299bd2e", ) assert isinstance(response, dict), str(response) - assert response["status"] == 'ok' + assert response["status"] == "ok" installed_repos = self.gi.toolshed.get_repositories() assert len(installed_repos) == 1 - assert installed_repos[0]['installed_changeset_revision'] == 'c14c7fd4d1be' - assert installed_repos[0]['changeset_revision'] == 'c14c7fd4d1be' + assert installed_repos[0]["installed_changeset_revision"] == "c14c7fd4d1be" + assert installed_repos[0]["changeset_revision"] == "c14c7fd4d1be" self.gi.toolshed.uninstall_repository_revision( name="ampvis2_alpha_diversity", From 64c6ac9b665ef3b7ea3536306198c3880036accc Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Mon, 17 Mar 2025 19:26:06 +0100 Subject: [PATCH 5/7] try to fix type annotation --- bioblend/galaxy/toolshed/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bioblend/galaxy/toolshed/__init__.py b/bioblend/galaxy/toolshed/__init__.py index 46a0f194c..38d807783 100644 --- a/bioblend/galaxy/toolshed/__init__.py +++ b/bioblend/galaxy/toolshed/__init__.py @@ -6,6 +6,7 @@ Any, Optional, TYPE_CHECKING, + Union, ) from bioblend.galaxy.client import Client @@ -80,7 +81,7 @@ def install_repository_revision( install_resolver_dependencies: bool = False, tool_panel_section_id: Optional[str] = None, new_tool_panel_section_label: Optional[str] = None, - ) -> dict[str, Any]: + ) -> Union[list[dict[str, Any]], dict[str, str]]: """ Install a specified repository revision from a specified Tool Shed into this Galaxy instance. This example demonstrates installation of a repository From 11515a34452febef70d57eb637d8dc16d93f902c Mon Sep 17 00:00:00 2001 From: M Bernt Date: Sun, 23 Mar 2025 15:35:57 +0100 Subject: [PATCH 6/7] Apply suggestions from code review Co-authored-by: Nicola Soranzo --- bioblend/_tests/TestGalaxyToolShed.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bioblend/_tests/TestGalaxyToolShed.py b/bioblend/_tests/TestGalaxyToolShed.py index 3dbe21b06..6f7831d81 100644 --- a/bioblend/_tests/TestGalaxyToolShed.py +++ b/bioblend/_tests/TestGalaxyToolShed.py @@ -6,8 +6,10 @@ class TestGalaxyToolShed(GalaxyTestBase.GalaxyTestBase): def test_install_old_first(self): - # test uses two revisions where the tool version has not been bumped - # 6:289d6299bd2e, 7:c14c7fd4d1be has not been bumped + # This test uses two revisions of the same tool, where only one has + # repository metadata associated: + # 6:289d6299bd2e contains a tool version bump + # 7:c14c7fd4d1be is a minor fix (no repository metadata changes) # asking to install old version immediately installs # new version @@ -17,7 +19,7 @@ def test_install_old_first(self): owner="iuc", changeset_revision="289d6299bd2e", ) - assert isinstance(response, list), str(response) + assert isinstance(response, list), response assert len(response) == 1 assert response[0]["status"] == "Installed" @@ -36,14 +38,14 @@ def test_install_old_first(self): def test_install_new_first(self): # 6:289d6299bd2e - # 7:c14c7fd4d1be has not been bumped + # 7:c14c7fd4d1be was not bumped response = self.gi.toolshed.install_repository_revision( tool_shed_url="https://toolshed.g2.bx.psu.edu/", name="ampvis2_alpha_diversity", owner="iuc", changeset_revision="c14c7fd4d1be", ) - assert isinstance(response, list), str(response) + assert isinstance(response, list), response assert len(response) == 1 assert response[0]["status"] == "Installed" @@ -61,7 +63,7 @@ def test_install_new_first(self): owner="iuc", changeset_revision="289d6299bd2e", ) - assert isinstance(response, dict), str(response) + assert isinstance(response, dict), response assert response["status"] == "ok" installed_repos = self.gi.toolshed.get_repositories() From e4b9a709b691a692003119b9917d5618a341e8dc Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Mon, 24 Mar 2025 11:49:14 +0000 Subject: [PATCH 7/7] Skip ``TestGalaxyToolShed`` tests on Galaxy 20.01 Under Python 3 (used on CI), these tests fail with: ``` 2025-03-23T14:50:39.1785054Z galaxy.tool_shed.util.hg_util ERROR 2025-03-23 14:49:10,252 Error cloning repository: Command '['hg', 'clone', '-r', '7', 'https://toolshed.g2.bx.psu.edu/repos/iuc/ampvis2_alpha_diversity', '/tmp/tmp.v7l6JdnDRz/shed_tools/toolshed.g2.bx.psu.edu/repos/iuc/ampvis2_alpha_diversity/c14c7fd4d1be/ampvis2_alpha_diversity']' returned non-zero exit status 1. 2025-03-23T14:50:39.1785127Z Output was: 2025-03-23T14:50:39.1785222Z Traceback (most recent call last): 2025-03-23T14:50:39.1785629Z File "/home/runner/work/bioblend/bioblend/galaxy-release_20.01/.venv/bin/hg", line 36, in 2025-03-23T14:50:39.1785712Z dispatch.run() 2025-03-23T14:50:39.1786146Z File "/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/importlib/util.py", line 245, in __getattribute__ 2025-03-23T14:50:39.1786252Z self.__spec__.loader.exec_module(self) 2025-03-23T14:50:39.1786453Z File "", line 728, in exec_module 2025-03-23T14:50:39.1786679Z File "", line 219, in _call_with_frames_removed 2025-03-23T14:50:39.1787151Z File "/home/runner/work/bioblend/bioblend/galaxy-release_20.01/.venv/lib/python3.7/site-packages/mercurial/dispatch.py", line 22, in 2025-03-23T14:50:39.1787231Z from .i18n import _ 2025-03-23T14:50:39.1787558Z File "/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/importlib/util.py", line 245, in __getattribute__ 2025-03-23T14:50:39.1787652Z self.__spec__.loader.exec_module(self) 2025-03-23T14:50:39.1788291Z File "/home/runner/work/bioblend/bioblend/galaxy-release_20.01/.venv/lib/python3.7/site-packages/mercurial/i18n.py", line 15, in 2025-03-23T14:50:39.1788381Z from .pycompat import getattr 2025-03-23T14:50:39.1788937Z ImportError: cannot import name 'getattr' from 'mercurial.pycompat' (/home/runner/work/bioblend/bioblend/galaxy-release_20.01/.venv/lib/python3.7/site-packages/mercurial/pycompat.py) ``` --- bioblend/_tests/TestGalaxyToolShed.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bioblend/_tests/TestGalaxyToolShed.py b/bioblend/_tests/TestGalaxyToolShed.py index 6f7831d81..e0ea7797a 100644 --- a/bioblend/_tests/TestGalaxyToolShed.py +++ b/bioblend/_tests/TestGalaxyToolShed.py @@ -1,8 +1,12 @@ """ """ -from . import GalaxyTestBase +from . import ( + GalaxyTestBase, + test_util, +) +@test_util.skip_unless_galaxy("release_20.05") class TestGalaxyToolShed(GalaxyTestBase.GalaxyTestBase): def test_install_old_first(self):