Skip to content

Commit

Permalink
Refactor test_driver -> target for reuse in fixtures.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Oct 11, 2024
1 parent 6dc681d commit d726b4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/galaxy_test/base/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

DEFAULT_WEB_HOST = socket.gethostbyname("localhost")

GalaxyTarget = Tuple[str, Optional[str], str]


def setup_keep_outdir() -> str:
keep_outdir = os.environ.get("GALAXY_TEST_SAVE", "")
Expand All @@ -23,7 +25,7 @@ def setup_keep_outdir() -> str:
return keep_outdir


def target_url_parts() -> Tuple[str, Optional[str], str]:
def target_url_parts() -> GalaxyTarget:
host = socket.gethostbyname(os.environ.get("GALAXY_TEST_HOST", DEFAULT_WEB_HOST))
port = os.environ.get("GALAXY_TEST_PORT")
if port:
Expand Down
20 changes: 12 additions & 8 deletions lib/galaxy_test/base/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@
from galaxy.tool_util.verify.test_data import TestDataResolver
from galaxy.util.unittest import TestCase
from galaxy_test.base.env import (
GalaxyTarget,
setup_keep_outdir,
target_url_parts,
)

log = logging.getLogger(__name__)


def host_port_and_url(test_driver: Optional[Any]) -> GalaxyTarget:
host, port, url = target_url_parts()
server_wrapper = test_driver and test_driver.server_wrappers and test_driver.server_wrappers[0]
if server_wrapper:
host = server_wrapper.host
port = server_wrapper.port
url = f"http://{host}:{port}{server_wrapper.prefix.rstrip('/')}/"
return host, port, url


@pytest.mark.usefixtures("embedded_driver")
class FunctionalTestCase(TestCase):
"""Base class for tests targetting actual Galaxy servers.
Expand All @@ -34,14 +45,7 @@ class FunctionalTestCase(TestCase):
_test_driver: Optional[Any]

def setUp(self) -> None:
self.host, self.port, self.url = target_url_parts()
server_wrapper = (
self._test_driver and self._test_driver.server_wrappers and self._test_driver.server_wrappers[0]
)
if server_wrapper:
self.host = server_wrapper.host
self.port = server_wrapper.port
self.url = f"http://{self.host}:{self.port}{server_wrapper.prefix.rstrip('/')}/"
self.host, self.port, self.url = host_port_and_url(self._test_driver)
self.test_data_resolver = TestDataResolver()
self.keepOutdir = setup_keep_outdir()

Expand Down

0 comments on commit d726b4b

Please sign in to comment.