Skip to content

Commit 282332a

Browse files
committed
Add tests for environment variable caching
1 parent 6db18b7 commit 282332a

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

tests/cache_environment.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cwl:requirements:
2+
- class: EnvVarRequirement
3+
envDef:
4+
- envName: TEST_ENV
5+
envValue: value1

tests/cache_environment2.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cwl:requirements:
2+
- class: EnvVarRequirement
3+
envDef:
4+
- envName: TEST_ENV
5+
envValue: value2

tests/cache_environment_tool.cwl

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class: CommandLineTool
2+
cwlVersion: v1.2
3+
inputs:
4+
[]
5+
outputs:
6+
[]
7+
8+
baseCommand: ["echo"]

tests/test_examples.py

+45
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,51 @@ def test_cache_default_literal_file(tmp_path: Path, factor: str) -> None:
13461346
assert "completed success" in stderr
13471347
assert error_code == 0
13481348

1349+
@pytest.mark.parametrize("factor", test_factors)
1350+
def test_cache_environment_variable(tmp_path: Path, factor: str) -> None:
1351+
"""Ensure that changing the environment variables will result in different cache keys"""
1352+
test_file = "cache_environment_tool.cwl"
1353+
test_job_file = "cache_environment.yml"
1354+
cache_dir = str(tmp_path / "cwltool_cache")
1355+
commands = factor.split()
1356+
commands.extend(
1357+
[
1358+
"--cachedir",
1359+
cache_dir,
1360+
"--outdir",
1361+
str(tmp_path / "outdir"),
1362+
get_data("tests/" + test_file),
1363+
get_data(f"tests/{test_job_file}")
1364+
]
1365+
)
1366+
error_code, _, stderr = get_main_output(commands)
1367+
1368+
stderr = re.sub(r"\s\s+", " ", stderr)
1369+
assert "Output of job will be cached in" in stderr
1370+
assert error_code == 0, stderr
1371+
1372+
error_code, _, stderr = get_main_output(commands)
1373+
assert "Output of job will be cached in" not in stderr
1374+
assert error_code == 0, stderr
1375+
1376+
commands = factor.split()
1377+
test_job_file = "cache_environment2.yml"
1378+
commands.extend(
1379+
[
1380+
"--cachedir",
1381+
cache_dir,
1382+
"--outdir",
1383+
str(tmp_path / "outdir"),
1384+
get_data("tests/" + test_file),
1385+
get_data(f"tests/{test_job_file}")
1386+
]
1387+
)
1388+
1389+
error_code, _, stderr = get_main_output(commands)
1390+
1391+
stderr = re.sub(r"\s\s+", " ", stderr)
1392+
assert "Output of job will be cached in" in stderr
1393+
assert error_code == 0, stderr
13491394

13501395
def test_write_summary(tmp_path: Path) -> None:
13511396
"""Test --write-summary."""

0 commit comments

Comments
 (0)