1
1
"""Tests of satisfying SoftwareRequirement via dependencies."""
2
2
import os
3
+ import tempfile
3
4
from pathlib import Path
4
5
from shutil import which
5
6
from types import ModuleType
6
- from typing import Optional
7
-
7
+ from typing import Optional , Tuple , Callable
8
+ from getpass import getuser
8
9
import pytest
9
10
10
11
from cwltool .context import LoadingContext
@@ -26,7 +27,15 @@ def test_biocontainers(tmp_path: Path) -> None:
26
27
wflow = get_data ("tests/seqtk_seq.cwl" )
27
28
job = get_data ("tests/seqtk_seq_job.json" )
28
29
error_code , _ , _ = get_main_output (
29
- ["--outdir" , str (tmp_path ), "--beta-use-biocontainers" , wflow , job ]
30
+ [
31
+ "--outdir" ,
32
+ str (tmp_path / "out" ),
33
+ "--beta-use-biocontainers" ,
34
+ "--beta-dependencies-directory" ,
35
+ str (tmp_path / "deps" ),
36
+ wflow ,
37
+ job ,
38
+ ]
30
39
)
31
40
32
41
assert error_code == 0
@@ -38,31 +47,84 @@ def test_biocontainers_resolution(tmp_path: Path) -> None:
38
47
"""Confirm expected container name for --beta-use-biocontainers."""
39
48
tool = load_tool (get_data ("tests/seqtk_seq.cwl" ), LoadingContext ())
40
49
assert (
41
- get_container_from_software_requirements (True , tool ) == "quay.io/biocontainers/seqtk:r93--0"
50
+ get_container_from_software_requirements (
51
+ True , tool , container_image_cache_path = str (tmp_path )
52
+ )
53
+ == "quay.io/biocontainers/seqtk:r93--0"
42
54
)
43
55
44
56
45
- @pytest .mark .skipif (not deps , reason = "galaxy-tool-util is not installed" )
46
- def test_bioconda (tmp_path : Path ) -> None :
57
+ @pytest .fixture (scope = "session" )
58
+ def bioconda_setup (request : pytest .FixtureRequest ) -> Tuple [Optional [int ], str ]:
59
+ """
60
+ Caches the conda environment created for seqtk_seq.cwl.
61
+
62
+ Respects ``--basetemp`` via code copied from
63
+ :py:method:`pytest.TempPathFactory.getbasetemp`.
64
+ """
65
+
66
+ deps_dir = request .config .cache .get ("bioconda_deps" , None )
67
+ if deps_dir is not None and not Path (deps_dir ).exists ():
68
+ # cache value set, but cache is gone :( ... recreate
69
+ deps_dir = None
70
+
71
+ if deps_dir is None :
72
+ given_basetemp = request .config .option .basetemp
73
+ if given_basetemp is not None :
74
+ basetemp = Path (os .path .abspath (str (given_basetemp ))).resolve ()
75
+ deps_dir = basetemp / "bioconda"
76
+ else :
77
+ from_env = os .environ .get ("PYTEST_DEBUG_TEMPROOT" )
78
+ temproot = Path (from_env or tempfile .gettempdir ()).resolve ()
79
+ rootdir = temproot .joinpath (f"pytest-of-{ getuser () or 'unknown' } " )
80
+ try :
81
+ rootdir .mkdir (mode = 0o700 , exist_ok = True )
82
+ except OSError :
83
+ rootdir = temproot .joinpath ("pytest-of-unknown" )
84
+ rootdir .mkdir (mode = 0o700 , exist_ok = True )
85
+ deps_dir = rootdir / "bioconda"
86
+ request .config .cache .set ("bioconda_deps" , str (deps_dir ))
87
+
88
+ deps_dirpath = Path (deps_dir )
89
+ deps_dirpath .mkdir (exist_ok = True )
90
+
47
91
wflow = get_data ("tests/seqtk_seq.cwl" )
48
92
job = get_data ("tests/seqtk_seq_job.json" )
49
93
error_code , _ , stderr = get_main_output (
50
- ["--outdir" , str (tmp_path ), "--beta-conda-dependencies" , "--debug" , wflow , job ]
94
+ [
95
+ "--outdir" ,
96
+ str (deps_dirpath / "out" ),
97
+ "--beta-conda-dependencies" ,
98
+ "--beta-dependencies-directory" ,
99
+ str (deps_dirpath / "deps" ),
100
+ "--debug" ,
101
+ wflow ,
102
+ job ,
103
+ ]
51
104
)
105
+ return error_code , stderr
52
106
107
+
108
+ @pytest .mark .skipif (not deps , reason = "galaxy-tool-util is not installed" )
109
+ def test_bioconda (bioconda_setup : Callable [[], Tuple [Optional [int ], str ]]) -> None :
110
+ error_code , stderr = bioconda_setup
53
111
assert error_code == 0 , stderr
54
112
55
113
56
114
@pytest .mark .skipif (not deps , reason = "galaxy-tool-util is not installed" )
57
115
@pytest .mark .skipif (not which ("modulecmd" ), reason = "modulecmd not installed" )
58
- def test_modules (monkeypatch : pytest .MonkeyPatch ) -> None :
116
+ def test_modules (monkeypatch : pytest .MonkeyPatch , tmp_path : Path ) -> None :
59
117
"""Do a basic smoke test using environment modules to satisfy a SoftwareRequirement."""
60
118
wflow = get_data ("tests/random_lines.cwl" )
61
119
job = get_data ("tests/random_lines_job.json" )
62
120
monkeypatch .setenv ("MODULEPATH" , os .path .join (os .getcwd (), "tests/test_deps_env/modulefiles" ))
63
121
error_code , _ , stderr = get_main_output (
64
122
[
123
+ "--outdir" ,
124
+ str (tmp_path / "out" ),
65
125
"--beta-dependency-resolvers-configuration" ,
126
+ "--beta-dependencies-directory" ,
127
+ str (tmp_path / "deps" ),
66
128
"tests/test_deps_env_modules_resolvers_conf.yml" ,
67
129
"--debug" ,
68
130
wflow ,
0 commit comments