1
+ """Tests of satisfying SoftwareRequirement via dependencies."""
2
+ from io import StringIO
3
+ import json
1
4
import os
5
+ from pathlib import Path
2
6
from shutil import which
3
7
from types import ModuleType
4
8
from typing import Optional
5
9
6
10
import pytest
7
11
8
- from .util import get_data , get_main_output , needs_docker
12
+ from cwltool .main import main
13
+
14
+ from .util import get_data , get_main_output , needs_docker , working_directory
9
15
10
16
deps = None # type: Optional[ModuleType]
11
17
try :
@@ -37,11 +43,11 @@ def test_bioconda() -> None:
37
43
38
44
@pytest .mark .skipif (not deps , reason = "galaxy-lib is not installed" )
39
45
@pytest .mark .skipif (not which ("modulecmd" ), reason = "modulecmd not installed" )
40
- def test_modules () -> None :
46
+ def test_modules (monkeypatch : pytest . MonkeyPatch ) -> None :
41
47
wflow = get_data ("tests/random_lines.cwl" )
42
48
job = get_data ("tests/random_lines_job.json" )
43
- os . environ [ "MODULEPATH" ] = os . path . join (
44
- os .getcwd (), "tests/test_deps_env/modulefiles"
49
+ monkeypatch . setenv (
50
+ "MODULEPATH" , os .path . join ( os . getcwd (), "tests/test_deps_env/modulefiles" )
45
51
)
46
52
error_code , _ , stderr = get_main_output (
47
53
[
@@ -54,3 +60,37 @@ def test_modules() -> None:
54
60
)
55
61
56
62
assert error_code == 0 , stderr
63
+
64
+
65
+ @pytest .mark .skipif (not deps , reason = "galaxy-lib is not installed" )
66
+ @pytest .mark .skipif (not which ("modulecmd" ), reason = "modulecmd not installed" )
67
+ def test_modules_environment (tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> None :
68
+ monkeypatch .setenv (
69
+ "MODULEPATH" , os .path .join (os .getcwd (), "tests/test_deps_env/modulefiles" )
70
+ )
71
+
72
+ stdout = StringIO ()
73
+ stderr = StringIO ()
74
+ with working_directory (tmp_path ):
75
+ rc = main (
76
+ argsl = [
77
+ "--beta-dependency-resolvers-configuration" ,
78
+ get_data ("tests/test_deps_env_modules_resolvers_conf.yml" ),
79
+ get_data ("tests/env3.cwl" ),
80
+ get_data ("tests/env_with_software_req.yml" ),
81
+ ],
82
+ stdout = stdout ,
83
+ stderr = stderr ,
84
+ )
85
+ assert rc == 0
86
+
87
+ output = json .loads (stdout .getvalue ())
88
+ env_path = output ["env" ]["path" ]
89
+ tool_env = {}
90
+ with open (env_path ) as _ :
91
+ for line in _ :
92
+ key , val = line .split ("=" , 1 )
93
+ tool_env [key ] = val [:- 1 ]
94
+ assert tool_env ["TEST_VAR_MODULE" ] == "environment variable ends in space "
95
+ tool_path = tool_env ["PATH" ].split (":" )
96
+ assert get_data ("tests/test_deps_env/random-lines/1.0/scripts" ) in tool_path
0 commit comments