Skip to content

Commit 3f6b455

Browse files
rupertnashmr-c
authored andcommitted
add a basic integration test for environment variables from modules
1 parent df79fd0 commit 3f6b455

File tree

5 files changed

+62
-5
lines changed

5 files changed

+62
-5
lines changed

cwltool/run_job.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ def handle_software_environment(cwl_env: Dict[str, str], script: str) -> Dict[st
1818
with open("output_environment.bash") as env_file:
1919
for line in env_file:
2020
key, val = line.split("=", 1)
21-
if key in ("_", "PWD", "SHLVL"):
21+
if key in ("_", "PWD", "SHLVL", "TMPDIR", "HOME"):
2222
# Skip some variables that are meaningful to the shell
23+
# or set specifically by the CWL runtime environment.
2324
continue
2425
env[key] = val[:-1] # remove trailing newline
2526
return env

tests/env3.cwl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: v1.0
3+
class: CommandLineTool
4+
inputs: []
5+
baseCommand: env
6+
outputs:
7+
env:
8+
type: stdout

tests/env_with_software_req.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cwltool:overrides:
2+
env3.cwl:
3+
requirements:
4+
SoftwareRequirement:
5+
packages:
6+
- package: 'random-lines'
7+
version: '1.0'

tests/test_dependencies.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
"""Tests of satisfying SoftwareRequirement via dependencies."""
2+
from io import StringIO
3+
import json
14
import os
5+
from pathlib import Path
26
from shutil import which
37
from types import ModuleType
48
from typing import Optional
59

610
import pytest
711

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
915

1016
deps = None # type: Optional[ModuleType]
1117
try:
@@ -37,11 +43,11 @@ def test_bioconda() -> None:
3743

3844
@pytest.mark.skipif(not deps, reason="galaxy-lib is not installed")
3945
@pytest.mark.skipif(not which("modulecmd"), reason="modulecmd not installed")
40-
def test_modules() -> None:
46+
def test_modules(monkeypatch: pytest.MonkeyPatch) -> None:
4147
wflow = get_data("tests/random_lines.cwl")
4248
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")
4551
)
4652
error_code, _, stderr = get_main_output(
4753
[
@@ -54,3 +60,37 @@ def test_modules() -> None:
5460
)
5561

5662
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

tests/test_deps_env/modulefiles/random-lines/1.0

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ if {![file exists $prefix]} {
1313
}
1414

1515
prepend-path PATH ${prefix}/scripts
16+
setenv TEST_VAR_MODULE "environment variable ends in space "

0 commit comments

Comments
 (0)