diff --git a/tests/cache_environment.yml b/tests/cache_environment.yml new file mode 100644 index 000000000..97cfe97a2 --- /dev/null +++ b/tests/cache_environment.yml @@ -0,0 +1,5 @@ +cwl:requirements: + - class: EnvVarRequirement + envDef: + - envName: TEST_ENV + envValue: value1 diff --git a/tests/cache_environment2.yml b/tests/cache_environment2.yml new file mode 100644 index 000000000..95f3d656b --- /dev/null +++ b/tests/cache_environment2.yml @@ -0,0 +1,5 @@ +cwl:requirements: + - class: EnvVarRequirement + envDef: + - envName: TEST_ENV + envValue: value2 diff --git a/tests/cache_environment_tool.cwl b/tests/cache_environment_tool.cwl new file mode 100644 index 000000000..179170c5e --- /dev/null +++ b/tests/cache_environment_tool.cwl @@ -0,0 +1,8 @@ +class: CommandLineTool +cwlVersion: v1.2 +inputs: + [] +outputs: + [] + +baseCommand: ["echo"] \ No newline at end of file diff --git a/tests/test_examples.py b/tests/test_examples.py index b78965bb4..68ec774db 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -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."""