From a04ce55f038507a4c33f241fcc7cbbd18cf44999 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Wed, 31 May 2023 09:42:47 +0100 Subject: [PATCH] Reuse ``skip_unless_executable`` test decorator for conda and singularity --- lib/galaxy/util/unittest_utils/__init__.py | 13 +++++++++++++ lib/galaxy_test/driver/integration_util.py | 15 ++++----------- test/unit/tool_util/mulled/test_mulled_search.py | 4 ++-- .../test_mulled_update_singularity_containers.py | 8 +++----- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/galaxy/util/unittest_utils/__init__.py b/lib/galaxy/util/unittest_utils/__init__.py index a6798b6ac10..1a3d229eae2 100644 --- a/lib/galaxy/util/unittest_utils/__init__.py +++ b/lib/galaxy/util/unittest_utils/__init__.py @@ -5,8 +5,11 @@ from typing import ( ) from unittest import SkipTest +import pytest import requests +from galaxy.util.commands import which + def is_site_up(url: str) -> bool: try: @@ -30,3 +33,13 @@ def skip_if_site_down(url: str) -> Callable: skip_if_github_down = skip_if_site_down("https://github.com/") + + +def _identity(func: Callable) -> Callable: + return func + + +def skip_unless_executable(executable): + if which(executable): + return _identity + return pytest.mark.skip(f"PATH doesn't contain executable {executable}") diff --git a/lib/galaxy_test/driver/integration_util.py b/lib/galaxy_test/driver/integration_util.py index bc9b5c47c99..2d9309b083e 100644 --- a/lib/galaxy_test/driver/integration_util.py +++ b/lib/galaxy_test/driver/integration_util.py @@ -24,8 +24,11 @@ import pytest from galaxy.app import UniverseApplication from galaxy.tool_util.verify.test_data import TestDataResolver from galaxy.util import safe_makedirs -from galaxy.util.commands import which from galaxy.util.unittest import TestCase +from galaxy.util.unittest_utils import ( + _identity, + skip_unless_executable, +) from galaxy_test.base.api import ( UsesApiTestCaseMixin, UsesCeleryTasks, @@ -43,10 +46,6 @@ SCRIPT_DIRECTORY = os.path.abspath(os.path.dirname(__file__)) VAULT_CONF = os.path.join(SCRIPT_DIRECTORY, "vault_conf.yml") -def _identity(func): - return func - - def skip_if_jenkins(cls): if os.environ.get("BUILD_NUMBER", ""): return skip @@ -66,12 +65,6 @@ def skip_unless_postgres(): return pytest.mark.skip("GALAXY_TEST_DBURI does not point to postgres database, required for this test.") -def skip_unless_executable(executable): - if which(executable): - return _identity - return pytest.mark.skip(f"PATH doesn't contain executable {executable}") - - def skip_unless_docker(): return skip_unless_executable("docker") diff --git a/test/unit/tool_util/mulled/test_mulled_search.py b/test/unit/tool_util/mulled/test_mulled_search.py index 451a2af9bfa..dd17ab79d0e 100644 --- a/test/unit/tool_util/mulled/test_mulled_search.py +++ b/test/unit/tool_util/mulled/test_mulled_search.py @@ -1,13 +1,13 @@ import pytest from galaxy.tool_util.deps.mulled.mulled_search import ( - conda_path, CondaSearch, get_package_hash, GitHubSearch, QuaySearch, singularity_search, ) +from galaxy.util.unittest_utils import skip_unless_executable from ..util import external_dependency_management @@ -22,7 +22,7 @@ def test_quay_search(): @external_dependency_management -@pytest.mark.skipif(not conda_path, reason="requires conda on path") +@skip_unless_executable("conda") def test_conda_search(): t = CondaSearch("bioconda") search1 = t.get_json("asdfasdf") diff --git a/test/unit/tool_util/mulled/test_mulled_update_singularity_containers.py b/test/unit/tool_util/mulled/test_mulled_update_singularity_containers.py index 433a1b71358..728757b52f3 100644 --- a/test/unit/tool_util/mulled/test_mulled_update_singularity_containers.py +++ b/test/unit/tool_util/mulled/test_mulled_update_singularity_containers.py @@ -1,14 +1,12 @@ import os -import pytest - from galaxy.tool_util.deps.mulled.get_tests import main_test_search from galaxy.tool_util.deps.mulled.mulled_update_singularity_containers import ( docker_to_singularity, get_list_from_file, singularity_container_test, ) -from galaxy.util import which +from galaxy.util.unittest_utils import skip_unless_executable from ..util import external_dependency_management @@ -26,14 +24,14 @@ def test_get_list_from_file(tmp_path) -> None: @external_dependency_management -@pytest.mark.skipif(not which("singularity"), reason="requires singularity but singularity not on PATH") +@skip_unless_executable("singularity") def test_docker_to_singularity(tmp_path) -> None: docker_to_singularity("abundancebin:1.0.1--0", "singularity", tmp_path, no_sudo=True) assert tmp_path.joinpath("abundancebin:1.0.1--0").exists() @external_dependency_management -@pytest.mark.skipif(not which("singularity"), reason="requires singularity but singularity not on PATH") +@skip_unless_executable("singularity") def test_singularity_container_test(tmp_path) -> None: containers = [ "pybigwig:0.3.22--py36h54a71a5_0", # test Python imports