Skip to content

Commit 32f41c9

Browse files
committed
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.
1 parent 84c4a73 commit 32f41c9

File tree

1 file changed

+61
-46
lines changed

1 file changed

+61
-46
lines changed

tests/test_dependency_script.py

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import glob
22
import os
3+
import shutil
34
import tempfile
45

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

1112

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

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

30-
class DependencyScriptTestCase(CliTestCase):
24+
for env_var, default in [
25+
("INSTALL_DIR", clazz.install_dir),
26+
("DOWNLOAD_CACHE", clazz.download_cache),
27+
]:
28+
if env_var not in os.environ:
29+
os.environ[env_var] = default
30+
os.makedirs(default)
31+
value = os.environ[env_var]
32+
assert os.path.isdir(value), value
33+
34+
@classmethod
35+
def tearDownClass(clazz):
36+
shutil.rmtree(clazz.install_dir)
37+
shutil.rmtree(clazz.download_cache)
3138

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

4249
def test_empty_file(self):
43-
# Using empty file repos/fastqc/tool_dependencies.xml
44-
ds_cmd = ["dependency_script",
45-
os.path.join(TEST_REPOS_DIR, "fastqc")]
46-
self._check_exit_code(ds_cmd, 1)
50+
with self._isolate():
51+
# Using empty file repos/fastqc/tool_dependencies.xml
52+
ds_cmd = ["dependency_script",
53+
os.path.join(TEST_REPOS_DIR, "fastqc")]
54+
self._check_exit_code(ds_cmd, 1)
4755

4856
@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
4957
def test_samtools_example(self):
50-
# Also checking the --download_cache option
51-
ds_cmd = ["dependency_script",
52-
"--download_cache", os.environ["DOWNLOAD_CACHE"],
53-
os.path.join(TEST_REPOS_DIR, "package_1")]
54-
self._check_exit_code(ds_cmd, 0)
58+
with self._isolate():
59+
# Also checking the --download_cache option
60+
ds_cmd = ["dependency_script",
61+
"--download_cache", os.environ["DOWNLOAD_CACHE"],
62+
os.path.join(TEST_REPOS_DIR, "package_1")]
63+
self._check_exit_code(ds_cmd, 0)
5564

5665
@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
5766
def test_cd_hit_auxtools(self):
58-
ds_cmd = ["dependency_script",
59-
os.path.join(TEST_REPOS_DIR, "bad_repo_name")]
60-
self._check_exit_code(ds_cmd, 0)
67+
with self._isolate():
68+
ds_cmd = ["dependency_script",
69+
os.path.join(TEST_REPOS_DIR, "bad_repo_name")]
70+
self._check_exit_code(ds_cmd, 0)
6171

6272
@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
6373
def test_good_examples(self):
64-
ds_cmd = ["dependency_script",
65-
os.path.join(TEST_REPOS_DIR, "package_1"),
66-
os.path.join(TEST_REPOS_DIR, "bad_package_category/"),
67-
os.path.join(TEST_REPOS_DIR, "bad_repo_name")]
68-
self._check_exit_code(ds_cmd, 0)
74+
with self._isolate():
75+
ds_cmd = ["dependency_script",
76+
os.path.join(TEST_REPOS_DIR, "package_1"),
77+
os.path.join(TEST_REPOS_DIR, "bad_package_category/"),
78+
os.path.join(TEST_REPOS_DIR, "bad_repo_name")]
79+
self._check_exit_code(ds_cmd, 0)
6980

7081
@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
7182
def test_repos_recurse(self):
72-
# At least one will fail
73-
ds_cmd = ["dependency_script", "-r", TEST_REPOS_DIR]
74-
self._check_exit_code(ds_cmd, 1)
83+
with self._isolate():
84+
# At least one will fail
85+
ds_cmd = ["dependency_script", "-r", TEST_REPOS_DIR]
86+
self._check_exit_code(ds_cmd, 1)
7587

7688
@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
7789
def test_repos_recurse_fast(self):
78-
# At least one will fail
79-
ds_cmd = ["dependency_script", "--fail_fast", "-r", TEST_REPOS_DIR]
80-
self._check_exit_code(ds_cmd, 1)
90+
with self._isolate():
91+
# At least one will fail
92+
ds_cmd = ["dependency_script", "--fail_fast", "-r", TEST_REPOS_DIR]
93+
self._check_exit_code(ds_cmd, 1)
8194

8295
@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
8396
def test_repos_list(self):
84-
# At least one will fail
85-
ds_cmd = ["dependency_script"] + self.repo_list
86-
self._check_exit_code(ds_cmd, 1)
97+
with self._isolate():
98+
# At least one will fail
99+
ds_cmd = ["dependency_script"] + self.repo_list
100+
self._check_exit_code(ds_cmd, 1)
87101

88102
@skip_if_environ("PLANEMO_SKIP_SLOW_TESTS")
89103
def test_repos_list_fast(self):
90-
# At least one will fail
91-
ds_cmd = ["dependency_script", "--fail_fast"] + self.repo_list
92-
self._check_exit_code(ds_cmd, 1)
104+
with self._isolate():
105+
# At least one will fail
106+
ds_cmd = ["dependency_script", "--fail_fast"] + self.repo_list
107+
self._check_exit_code(ds_cmd, 1)

0 commit comments

Comments
 (0)