Skip to content

Commit

Permalink
Skip ToolShed tests if BIOBLEND_TOOLSHED_URL is down
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed May 12, 2024
1 parent 803b30d commit c103e7f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bioblend/_tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
Optional,
)

import requests

import bioblend.galaxy

NO_GALAXY_MESSAGE = "Externally configured Galaxy required, but not found. Set BIOBLEND_GALAXY_URL and BIOBLEND_GALAXY_API_KEY to run this test."
Expand All @@ -19,6 +21,14 @@ def random_string(length: int = 8) -> str:
return "".join(random.choice(string.ascii_lowercase) for _ in range(length))


def is_site_up(url: str) -> bool:
try:
response = requests.get(url, timeout=10)
return response.status_code == 200
except Exception:
return False


def skip_unless_toolshed() -> Callable:
"""Decorate tests with this to skip the test if a URL for a ToolShed
to run the tests is not provided.
Expand All @@ -27,6 +37,9 @@ def skip_unless_toolshed() -> Callable:
return unittest.skip(
"Externally configured ToolShed required, but not found. Set BIOBLEND_TOOLSHED_URL (e.g. to https://testtoolshed.g2.bx.psu.edu/ ) to run this test."
)
toolshed_url = os.environ["BIOBLEND_TOOLSHED_URL"]
if not is_site_up(toolshed_url):
return unittest.skip(f"Configured ToolShed [{toolshed_url}] appears to be down")
return lambda f: f


Expand Down

0 comments on commit c103e7f

Please sign in to comment.