Skip to content

Commit

Permalink
Add tests for environment variable caching
Browse files Browse the repository at this point in the history
  • Loading branch information
stxue1 committed Feb 27, 2025
1 parent 6db18b7 commit 282332a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/cache_environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cwl:requirements:
- class: EnvVarRequirement
envDef:
- envName: TEST_ENV
envValue: value1
5 changes: 5 additions & 0 deletions tests/cache_environment2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cwl:requirements:
- class: EnvVarRequirement
envDef:
- envName: TEST_ENV
envValue: value2
8 changes: 8 additions & 0 deletions tests/cache_environment_tool.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class: CommandLineTool
cwlVersion: v1.2
inputs:
[]
outputs:
[]

baseCommand: ["echo"]
45 changes: 45 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,51 @@ def test_cache_default_literal_file(tmp_path: Path, factor: str) -> None:
assert "completed success" in stderr
assert error_code == 0

@pytest.mark.parametrize("factor", test_factors)
def test_cache_environment_variable(tmp_path: Path, factor: str) -> None:
"""Ensure that changing the environment variables will result in different cache keys"""
test_file = "cache_environment_tool.cwl"
test_job_file = "cache_environment.yml"
cache_dir = str(tmp_path / "cwltool_cache")
commands = factor.split()
commands.extend(
[
"--cachedir",
cache_dir,
"--outdir",
str(tmp_path / "outdir"),
get_data("tests/" + test_file),
get_data(f"tests/{test_job_file}")
]
)
error_code, _, stderr = get_main_output(commands)

stderr = re.sub(r"\s\s+", " ", stderr)
assert "Output of job will be cached in" in stderr
assert error_code == 0, stderr

error_code, _, stderr = get_main_output(commands)
assert "Output of job will be cached in" not in stderr
assert error_code == 0, stderr

commands = factor.split()
test_job_file = "cache_environment2.yml"
commands.extend(
[
"--cachedir",
cache_dir,
"--outdir",
str(tmp_path / "outdir"),
get_data("tests/" + test_file),
get_data(f"tests/{test_job_file}")
]
)

error_code, _, stderr = get_main_output(commands)

stderr = re.sub(r"\s\s+", " ", stderr)
assert "Output of job will be cached in" in stderr
assert error_code == 0, stderr

def test_write_summary(tmp_path: Path) -> None:
"""Test --write-summary."""
Expand Down

0 comments on commit 282332a

Please sign in to comment.