Permalink
Browse files

Run dependency script tests in isolated directories.

Otherwise files get written in Planemo's directory directly. Also cleanup some environment handling TODOs now that we have abandoned Python 2.6.
  • Loading branch information...
jmchilton committed Mar 16, 2017
1 parent 84c4a73 commit 32f41c9c0d828236685204f49a01cd1af6697c42
Showing with 61 additions and 46 deletions.
  1. +61 −46 tests/test_dependency_script.py
@@ -1,5 +1,6 @@
import glob
import os
import shutil
import tempfile

from .test_utils import (
@@ -9,25 +10,31 @@
)


# This is a bit of a hack, but having failed to get the test
# script to see $INSTALL_DIR and $DOWNLOAD_CACHE set via
# .travis.yml this is an alternative.
temp_dir = tempfile.mkdtemp()
for env_var, default in [
("INSTALL_DIR", os.path.join(temp_dir, "install_dir")),
("DOWNLOAD_CACHE", os.path.join(temp_dir, "download_cache")),
]:
if env_var not in os.environ:
os.environ[env_var] = default
os.makedirs(default)
value = os.environ[env_var]
print("Using $%s=%s" % (env_var, value))
assert os.path.isdir(value), value
# TODO - Once drop Python 2.6, create and remove temp_dir via
# setUpClass and tearDownClass methos
class DependencyScriptTestCase(CliTestCase):

@classmethod
def setUpClass(clazz):
# This is a bit of a hack, but having failed to get the test
# script to see $INSTALL_DIR and $DOWNLOAD_CACHE set via
# .travis.yml this is an alternative.
temp_dir = tempfile.mkdtemp()
clazz.install_dir = os.path.join(temp_dir, "install_dir")
clazz.download_cache = os.path.join(temp_dir, "download_cache")

class DependencyScriptTestCase(CliTestCase):
for env_var, default in [
("INSTALL_DIR", clazz.install_dir),
("DOWNLOAD_CACHE", clazz.download_cache),
]:
if env_var not in os.environ:
os.environ[env_var] = default
os.makedirs(default)
value = os.environ[env_var]
assert os.path.isdir(value), value

@classmethod
def tearDownClass(clazz):
shutil.rmtree(clazz.install_dir)
shutil.rmtree(clazz.download_cache)

def setUp(self):
# Pass to base-class
@@ -40,53 +47,61 @@ def setUp(self):
self.repo_list = repo_list

def test_empty_file(self):
# Using empty file repos/fastqc/tool_dependencies.xml
ds_cmd = ["dependency_script",
os.path.join(TEST_REPOS_DIR, "fastqc")]
self._check_exit_code(ds_cmd, 1)
with self._isolate():
# Using empty file repos/fastqc/tool_dependencies.xml
ds_cmd = ["dependency_script",
os.path.join(TEST_REPOS_DIR, "fastqc")]
self._check_exit_code(ds_cmd, 1)

@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
def test_samtools_example(self):
# Also checking the --download_cache option
ds_cmd = ["dependency_script",
"--download_cache", os.environ["DOWNLOAD_CACHE"],
os.path.join(TEST_REPOS_DIR, "package_1")]
self._check_exit_code(ds_cmd, 0)
with self._isolate():
# Also checking the --download_cache option
ds_cmd = ["dependency_script",
"--download_cache", os.environ["DOWNLOAD_CACHE"],
os.path.join(TEST_REPOS_DIR, "package_1")]
self._check_exit_code(ds_cmd, 0)

@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
def test_cd_hit_auxtools(self):
ds_cmd = ["dependency_script",
os.path.join(TEST_REPOS_DIR, "bad_repo_name")]
self._check_exit_code(ds_cmd, 0)
with self._isolate():
ds_cmd = ["dependency_script",
os.path.join(TEST_REPOS_DIR, "bad_repo_name")]
self._check_exit_code(ds_cmd, 0)

@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
def test_good_examples(self):
ds_cmd = ["dependency_script",
os.path.join(TEST_REPOS_DIR, "package_1"),
os.path.join(TEST_REPOS_DIR, "bad_package_category/"),
os.path.join(TEST_REPOS_DIR, "bad_repo_name")]
self._check_exit_code(ds_cmd, 0)
with self._isolate():
ds_cmd = ["dependency_script",
os.path.join(TEST_REPOS_DIR, "package_1"),
os.path.join(TEST_REPOS_DIR, "bad_package_category/"),
os.path.join(TEST_REPOS_DIR, "bad_repo_name")]
self._check_exit_code(ds_cmd, 0)

@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
def test_repos_recurse(self):
# At least one will fail
ds_cmd = ["dependency_script", "-r", TEST_REPOS_DIR]
self._check_exit_code(ds_cmd, 1)
with self._isolate():
# At least one will fail
ds_cmd = ["dependency_script", "-r", TEST_REPOS_DIR]
self._check_exit_code(ds_cmd, 1)

@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
def test_repos_recurse_fast(self):
# At least one will fail
ds_cmd = ["dependency_script", "--fail_fast", "-r", TEST_REPOS_DIR]
self._check_exit_code(ds_cmd, 1)
with self._isolate():
# At least one will fail
ds_cmd = ["dependency_script", "--fail_fast", "-r", TEST_REPOS_DIR]
self._check_exit_code(ds_cmd, 1)

@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
def test_repos_list(self):
# At least one will fail
ds_cmd = ["dependency_script"] + self.repo_list
self._check_exit_code(ds_cmd, 1)
with self._isolate():
# At least one will fail
ds_cmd = ["dependency_script"] + self.repo_list
self._check_exit_code(ds_cmd, 1)

@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
def test_repos_list_fast(self):
# At least one will fail
ds_cmd = ["dependency_script", "--fail_fast"] + self.repo_list
self._check_exit_code(ds_cmd, 1)
with self._isolate():
# At least one will fail
ds_cmd = ["dependency_script", "--fail_fast"] + self.repo_list
self._check_exit_code(ds_cmd, 1)

0 comments on commit 32f41c9

Please sign in to comment.