Files
galaxy/test/unit/shed_unit/test_td_common_util.py
T
Nicola Soranzo 9d74bba7fb Drop support for retired Python 3.5
Upgrade syntax using `pyupgrade --py36-plus` .

Manually drop several `six` imports.

Also:
- Remove broken pr_cache in scripts/bootstrap_history.py
- Fix broken prefix removal in lib/galaxy/tool_util/deps/mulled/mulled_build.py
2020-10-07 11:52:13 +01:00

89 lines
3.8 KiB
Python

from contextlib import contextmanager
from os.path import join
from galaxy.tool_shed.galaxy_install.tool_dependencies.env_manager import EnvManager
from galaxy.tool_shed.galaxy_install.tool_dependencies.recipe.env_file_builder import EnvFileBuilder
from galaxy.util import parse_xml_string
TEST_DEPENDENCIES_DIR = "/opt/galaxy/dependencies"
TEST_INSTALL_DIR = "%s/test_install_dir" % TEST_DEPENDENCIES_DIR
class MockApp:
def __init__(self):
pass
def test_create_or_update_env_shell_file():
test_path = "/usr/share/R/libs"
env_file_builder = EnvFileBuilder(test_path)
line, path = env_file_builder.create_or_update_env_shell_file(TEST_INSTALL_DIR, dict(action="append_to", name="R_LIBS", value=test_path))
assert path == join(TEST_INSTALL_DIR, "env.sh")
assert line == "R_LIBS=$R_LIBS:/usr/share/R/libs; export R_LIBS"
line, path = env_file_builder.create_or_update_env_shell_file(TEST_INSTALL_DIR, dict(action="prepend_to", name="R_LIBS", value=test_path))
assert path == join(TEST_INSTALL_DIR, "env.sh")
assert line == "R_LIBS=/usr/share/R/libs:$R_LIBS; export R_LIBS"
line, path = env_file_builder.create_or_update_env_shell_file(TEST_INSTALL_DIR, dict(action="set_to", name="R_LIBS", value=test_path))
assert path == join(TEST_INSTALL_DIR, "env.sh")
assert line == "R_LIBS=/usr/share/R/libs; export R_LIBS"
line, path = env_file_builder.create_or_update_env_shell_file(TEST_INSTALL_DIR, dict(action="source", value=test_path))
assert path == join(TEST_INSTALL_DIR, "env.sh")
assert line == "if [ -f /usr/share/R/libs ] ; then . /usr/share/R/libs ; fi"
def test_get_env_shell_file_paths_from_setup_environment_elem():
xml = """<action name="setup_r_environment">
<repository name="package_r_3_0_1" owner="bgruening" toolshed="toolshed.g2.bx.psu.edu" changeset_revision="1234567">
<package name="R" version="3.0.1" />
</repository>
<repository name="package_zlib_1_2_8" owner="iuc" toolshed="toolshed.g2.bx.psu.edu" changeset_revision="7654321">
<package name="zlib" version="1.2.8" />
</repository>
</action>
"""
mock_app = MockApp()
action_elem = parse_xml_string(xml)
required_for_install_env_sh = '/path/to/existing.sh'
all_env_paths = [required_for_install_env_sh]
action_dict = {}
env_manager = EnvManager(mock_app)
r_env_sh = '/path/to/go/env.sh'
def mock_get_env_shell_file_paths(elem):
assert elem.get('name') in ["package_r_3_0_1", "package_zlib_1_2_8"]
return [r_env_sh]
with __mock_common_util_method(env_manager, "get_env_shell_file_paths", mock_get_env_shell_file_paths):
env_manager.get_env_shell_file_paths_from_setup_environment_elem(all_env_paths, action_elem, action_dict)
# Verify old env files weren't deleted.
assert required_for_install_env_sh in all_env_paths
# Verify new ones added.
assert r_env_sh in all_env_paths
# env_shell_file_paths includes everything
assert all([env in action_dict['env_shell_file_paths'] for env in all_env_paths])
# for every given repository there should be one env
# file + the required_for_install_env_sh file
assert len(action_dict['env_shell_file_paths']) == 3
# action_shell_file_paths includes only env files defined
# inside the setup_ action element.
assert required_for_install_env_sh in action_dict['action_shell_file_paths']
assert r_env_sh in action_dict['action_shell_file_paths']
# Poor man's mocking. Need to get a real mocking library as real Galaxy development
# dependnecy.
@contextmanager
def __mock_common_util_method(env_manager, name, mock_method):
real_method = getattr(env_manager, name)
try:
setattr(env_manager, name, mock_method)
yield
finally:
setattr(env_manager, name, real_method)