mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Separate different style Galaxy testing behaviors into classes.
This commit is contained in:
+80
-78
@@ -8,7 +8,6 @@ that script for a list of options.
|
||||
import os
|
||||
import os.path
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))
|
||||
sys.path[1:1] = [ os.path.join( galaxy_root, "lib" ), os.path.join( galaxy_root, "test" ) ]
|
||||
@@ -17,93 +16,96 @@ from base import driver_util
|
||||
log = driver_util.build_logger()
|
||||
|
||||
from base.api_util import get_master_api_key, get_user_api_key
|
||||
from galaxy.web import buildapp
|
||||
|
||||
|
||||
class GalaxyTestDriver(driver_util.TestDriver):
|
||||
"""Instantial a Galaxy-style nose TestDriver for testing Galaxy."""
|
||||
class MigratedToolsGalaxyTestDriver(driver_util.GalaxyTestDriver):
|
||||
"""Instantiate a Galaxy-style nose TestDriver for testing migrated Galaxy tools."""
|
||||
|
||||
def setup(self):
|
||||
"""Setup a Galaxy server for functional test (if needed)."""
|
||||
# ---- Configuration ------------------------------------------------------
|
||||
testing_migrated_tools = _check_arg('-migrated')
|
||||
testing_installed_tools = _check_arg('-installed')
|
||||
testing_framework_tools = _check_arg('-framework')
|
||||
testing_data_manager = _check_arg('-data_managers')
|
||||
testing_workflow = _check_arg('-workflow')
|
||||
testing_shed_tools = testing_migrated_tools or testing_installed_tools
|
||||
testing_shed_tools = True
|
||||
|
||||
datatypes_conf_override = None
|
||||
default_tool_conf = None
|
||||
def build_tests(self):
|
||||
"""Build migrated tool test methods."""
|
||||
self.setup_shed_tools(
|
||||
testing_migrated_tools=True,
|
||||
)
|
||||
self.build_tool_tests()
|
||||
|
||||
if testing_framework_tools:
|
||||
default_tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF
|
||||
datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF
|
||||
|
||||
external_galaxy = os.environ.get('GALAXY_TEST_EXTERNAL', None)
|
||||
class InstalledToolsGalaxyTestDriver(driver_util.GalaxyTestDriver):
|
||||
"""Galaxy-style nose TestDriver for testing installed Galaxy tools."""
|
||||
|
||||
galaxy_test_tmp_dir = driver_util.get_galaxy_test_tmp_dir()
|
||||
self.temp_directories.append(galaxy_test_tmp_dir)
|
||||
testing_shed_tools = True
|
||||
|
||||
if external_galaxy is None:
|
||||
tempdir = tempfile.mkdtemp( dir=galaxy_test_tmp_dir )
|
||||
# Configure the database path.
|
||||
galaxy_db_path = driver_util.database_files_path(tempdir)
|
||||
galaxy_config = driver_util.setup_galaxy_config(
|
||||
galaxy_db_path,
|
||||
use_test_file_dir=not testing_shed_tools,
|
||||
default_install_db_merged=True,
|
||||
default_tool_conf=default_tool_conf,
|
||||
datatypes_conf=datatypes_conf_override,
|
||||
)
|
||||
def build_tests(self):
|
||||
"""Build installed tool test methods."""
|
||||
self.setup_shed_tools(
|
||||
testing_installed_tools=True,
|
||||
)
|
||||
self.build_tool_tests()
|
||||
|
||||
# ---- Build Application --------------------------------------------------
|
||||
app = driver_util.build_galaxy_app(galaxy_config)
|
||||
server_wrapper = driver_util.launch_server(
|
||||
app,
|
||||
buildapp.app_factory,
|
||||
galaxy_config,
|
||||
)
|
||||
self.server_wrappers.append(server_wrapper)
|
||||
log.info("Functional tests will be run against %s:%s" % (server_wrapper.host, server_wrapper.port))
|
||||
else:
|
||||
log.info("Functional tests will be run against %s" % external_galaxy)
|
||||
|
||||
if testing_shed_tools:
|
||||
driver_util.setup_shed_tools_for_test(
|
||||
app,
|
||||
galaxy_test_tmp_dir,
|
||||
testing_migrated_tools,
|
||||
testing_installed_tools,
|
||||
)
|
||||
if testing_workflow:
|
||||
import functional.workflow
|
||||
functional.workflow.WorkflowTestCase.master_api_key = get_master_api_key()
|
||||
functional.workflow.WorkflowTestCase.user_api_key = get_user_api_key()
|
||||
if testing_data_manager:
|
||||
import functional.test_data_managers
|
||||
functional.test_data_managers.data_managers = app.data_managers # seems like a hack...
|
||||
functional.test_data_managers.build_tests(
|
||||
tmp_dir=galaxy_test_tmp_dir,
|
||||
testing_shed_tools=testing_shed_tools,
|
||||
master_api_key=get_master_api_key(),
|
||||
user_api_key=get_user_api_key(),
|
||||
)
|
||||
class DefaultGalaxyTestDriver(driver_util.GalaxyTestDriver):
|
||||
"""Default Galaxy-style nose test driver.
|
||||
|
||||
if app is not None:
|
||||
# We must make sure that functional.test_toolbox is always imported after
|
||||
# database_contexts.galaxy_content is set (which occurs in this method above).
|
||||
# If functional.test_toolbox is imported before database_contexts.galaxy_content
|
||||
# is set, sa_session will be None in all methods that use it.
|
||||
import functional.test_toolbox
|
||||
functional.test_toolbox.toolbox = app.toolbox
|
||||
# When testing data managers, do not test toolbox.
|
||||
functional.test_toolbox.build_tests(
|
||||
app=app,
|
||||
testing_shed_tools=testing_shed_tools,
|
||||
master_api_key=get_master_api_key(),
|
||||
user_api_key=get_user_api_key(),
|
||||
)
|
||||
Just populate non-shed tool tests and run tests. Works
|
||||
for tool tests, regular twill tests, and API testing.
|
||||
"""
|
||||
|
||||
def build_tests(self):
|
||||
"""Build framework tool test methods."""
|
||||
self.build_tool_tests()
|
||||
|
||||
|
||||
class FrameworkToolsGalaxyTestDriver(DefaultGalaxyTestDriver):
|
||||
"""Galaxy-style nose TestDriver for testing framework Galaxy tools."""
|
||||
|
||||
default_tool_conf = driver_util.FRAMEWORK_SAMPLE_TOOLS_CONF
|
||||
datatypes_conf_override = driver_util.FRAMEWORK_DATATYPES_CONF
|
||||
|
||||
|
||||
class DataManagersGalaxyTestDriver(driver_util.GalaxyTestDriver):
|
||||
"""Galaxy-style nose TestDriver for testing framework Galaxy tools."""
|
||||
|
||||
def build_tests(self):
|
||||
"""Build data manager test methods."""
|
||||
import functional.test_data_managers
|
||||
functional.test_data_managers.data_managers = self.app.data_managers
|
||||
functional.test_data_managers.build_tests(
|
||||
tmp_dir=self.galaxy_test_tmp_dir,
|
||||
testing_shed_tools=self.testing_shed_tools,
|
||||
master_api_key=get_master_api_key(),
|
||||
user_api_key=get_user_api_key(),
|
||||
)
|
||||
|
||||
|
||||
class WorkflowGalaxyTestDriver(driver_util.GalaxyTestDriver):
|
||||
"""Galaxy-style nose TestDriver for testing a Galaxy workflow."""
|
||||
|
||||
def build_tests(self):
|
||||
"""Setup WorkflowTestCase for test execution."""
|
||||
import functional.workflow
|
||||
functional.workflow.WorkflowTestCase.master_api_key = get_master_api_key()
|
||||
functional.workflow.WorkflowTestCase.user_api_key = get_user_api_key()
|
||||
|
||||
|
||||
TEST_DRIVERS = {
|
||||
'-migrated': MigratedToolsGalaxyTestDriver,
|
||||
'-installed': InstalledToolsGalaxyTestDriver,
|
||||
'-framework': FrameworkToolsGalaxyTestDriver,
|
||||
'-data_managers': DataManagersGalaxyTestDriver,
|
||||
'-workflow': WorkflowGalaxyTestDriver,
|
||||
}
|
||||
|
||||
|
||||
def find_test_driver():
|
||||
"""Look at command-line args and find the correct Galaxy test driver."""
|
||||
test_driver = DefaultGalaxyTestDriver
|
||||
|
||||
for key in TEST_DRIVERS.keys():
|
||||
if _check_arg(key):
|
||||
test_driver = TEST_DRIVERS[key]
|
||||
|
||||
return test_driver
|
||||
|
||||
|
||||
def _check_arg( name ):
|
||||
@@ -116,4 +118,4 @@ def _check_arg( name ):
|
||||
return ret_val
|
||||
|
||||
if __name__ == "__main__":
|
||||
driver_util.drive_test(GalaxyTestDriver)
|
||||
driver_util.drive_test(find_test_driver())
|
||||
|
||||
@@ -22,7 +22,7 @@ import nose.plugins.manager
|
||||
|
||||
from paste import httpserver
|
||||
|
||||
from .api_util import get_master_api_key
|
||||
from .api_util import get_master_api_key, get_user_api_key
|
||||
from .tool_shed_util import parse_tool_panel_config
|
||||
from .nose_util import run
|
||||
from .instrument import StructuredTestDataPlugin
|
||||
@@ -30,6 +30,7 @@ from .instrument import StructuredTestDataPlugin
|
||||
from functional import database_contexts
|
||||
|
||||
from galaxy.app import UniverseApplication as GalaxyUniverseApplication
|
||||
from galaxy.web import buildapp
|
||||
from galaxy.webapps.tool_shed.app import UniverseApplication as ToolshedUniverseApplication
|
||||
from galaxy.util import asbool
|
||||
from galaxy.util.properties import load_app_properties
|
||||
@@ -575,6 +576,72 @@ class TestDriver(object):
|
||||
self.tear_down()
|
||||
|
||||
|
||||
class GalaxyTestDriver(TestDriver):
|
||||
"""Instantial a Galaxy-style nose TestDriver for testing Galaxy."""
|
||||
|
||||
testing_shed_tools = False
|
||||
|
||||
def setup(self):
|
||||
"""Setup a Galaxy server for functional test (if needed)."""
|
||||
self.external_galaxy = os.environ.get('GALAXY_TEST_EXTERNAL', None)
|
||||
self.galaxy_test_tmp_dir = get_galaxy_test_tmp_dir()
|
||||
self.temp_directories.append(self.galaxy_test_tmp_dir)
|
||||
|
||||
testing_shed_tools = getattr(self, "testing_shed_tools", False)
|
||||
default_tool_conf = getattr(self, "default_tool_conf", None)
|
||||
datatypes_conf_override = getattr(self, "datatypes_conf_override", None)
|
||||
|
||||
if self.external_galaxy is None:
|
||||
tempdir = tempfile.mkdtemp(dir=self.galaxy_test_tmp_dir)
|
||||
# Configure the database path.
|
||||
galaxy_db_path = database_files_path(tempdir)
|
||||
galaxy_config = setup_galaxy_config(
|
||||
galaxy_db_path,
|
||||
use_test_file_dir=not testing_shed_tools,
|
||||
default_install_db_merged=True,
|
||||
default_tool_conf=default_tool_conf,
|
||||
datatypes_conf=datatypes_conf_override,
|
||||
)
|
||||
|
||||
# ---- Build Application --------------------------------------------------
|
||||
self.app = build_galaxy_app(galaxy_config)
|
||||
server_wrapper = launch_server(
|
||||
self.app,
|
||||
buildapp.app_factory,
|
||||
galaxy_config,
|
||||
)
|
||||
self.server_wrappers.append(server_wrapper)
|
||||
log.info("Functional tests will be run against %s:%s" % (server_wrapper.host, server_wrapper.port))
|
||||
else:
|
||||
log.info("Functional tests will be run against %s" % self.external_galaxy)
|
||||
|
||||
def setup_shed_tools(self, testing_migrated_tools=False, testing_installed_tools=True):
|
||||
setup_shed_tools_for_test(
|
||||
self.app,
|
||||
self.galaxy_test_tmp_dir,
|
||||
testing_migrated_tools,
|
||||
testing_installed_tools
|
||||
)
|
||||
|
||||
def build_tool_tests(self):
|
||||
if self.app is None:
|
||||
return
|
||||
|
||||
# We must make sure that functional.test_toolbox is always imported after
|
||||
# database_contexts.galaxy_content is set (which occurs in this method above).
|
||||
# If functional.test_toolbox is imported before database_contexts.galaxy_content
|
||||
# is set, sa_session will be None in all methods that use it.
|
||||
import functional.test_toolbox
|
||||
functional.test_toolbox.toolbox = self.app.toolbox
|
||||
# When testing data managers, do not test toolbox.
|
||||
functional.test_toolbox.build_tests(
|
||||
app=self.app,
|
||||
testing_shed_tools=self.testing_shed_tools,
|
||||
master_api_key=get_master_api_key(),
|
||||
user_api_key=get_user_api_key(),
|
||||
)
|
||||
|
||||
|
||||
def drive_test(test_driver_class):
|
||||
"""Instantiate driver class, run, and exit appropriately."""
|
||||
sys.exit(test_driver_class().run())
|
||||
@@ -591,7 +658,6 @@ __all__ = [
|
||||
"get_webapp_global_conf",
|
||||
"nose_config_and_run",
|
||||
"setup_galaxy_config",
|
||||
"setup_shed_tools_for_test",
|
||||
"TestDriver",
|
||||
"wait_for_http_server",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user