|
| 1 | +import re |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from .util import get_data, get_main_output, needs_docker |
| 7 | + |
| 8 | +test_factors = [(""), ("--parallel"), ("--debug"), ("--parallel --debug")] |
| 9 | + |
| 10 | + |
| 11 | +@needs_docker |
| 12 | +@pytest.mark.parametrize("factor", test_factors) |
| 13 | +def test_cid_file_non_existing_dir(tmp_path: Path, factor: str) -> None: |
| 14 | + """Test that --cachedir with a bad path should produce a specific error.""" |
| 15 | + test_file = "cache_test_workflow.cwl" |
| 16 | + bad_cidfile_dir = tmp_path / "cidfile-dir-badpath" |
| 17 | + commands = factor.split() |
| 18 | + commands.extend( |
| 19 | + [ |
| 20 | + "--record-container-id", |
| 21 | + "--cidfile-dir", |
| 22 | + str(bad_cidfile_dir), |
| 23 | + get_data("tests/wf/" + test_file), |
| 24 | + ] |
| 25 | + ) |
| 26 | + error_code, _, stderr = get_main_output(commands) |
| 27 | + stderr = re.sub(r"\s\s+", " ", stderr) |
| 28 | + assert "directory doesn't exist, please create it first" in stderr, stderr |
| 29 | + assert error_code == 2 or error_code == 1, stderr |
| 30 | + |
| 31 | + |
| 32 | +@needs_docker |
| 33 | +@pytest.mark.parametrize("factor", test_factors) |
| 34 | +def test_wf_without_container(tmp_path: Path, factor: str) -> None: |
| 35 | + """Confirm that we can run a workflow without a container.""" |
| 36 | + test_file = "hello-workflow.cwl" |
| 37 | + cache_dir = str(tmp_path / "cwltool_cache") |
| 38 | + commands = factor.split() |
| 39 | + commands.extend( |
| 40 | + [ |
| 41 | + "--cachedir", |
| 42 | + cache_dir, |
| 43 | + "--outdir", |
| 44 | + str(tmp_path / "outdir"), |
| 45 | + get_data("tests/wf/" + test_file), |
| 46 | + "--usermessage", |
| 47 | + "hello", |
| 48 | + ] |
| 49 | + ) |
| 50 | + error_code, _, stderr = get_main_output(commands) |
| 51 | + |
| 52 | + stderr = re.sub(r"\s\s+", " ", stderr) |
| 53 | + assert "completed success" in stderr |
| 54 | + assert error_code == 0 |
| 55 | + |
| 56 | + |
| 57 | +@needs_docker |
| 58 | +@pytest.mark.parametrize("factor", test_factors) |
| 59 | +def test_issue_740_fixed(tmp_path: Path, factor: str) -> None: |
| 60 | + """Confirm that re-running a particular workflow with caching succeeds.""" |
| 61 | + test_file = "cache_test_workflow.cwl" |
| 62 | + cache_dir = str(tmp_path / "cwltool_cache") |
| 63 | + commands = factor.split() |
| 64 | + commands.extend(["--cachedir", cache_dir, get_data("tests/wf/" + test_file)]) |
| 65 | + error_code, _, stderr = get_main_output(commands) |
| 66 | + |
| 67 | + stderr = re.sub(r"\s\s+", " ", stderr) |
| 68 | + assert "completed success" in stderr |
| 69 | + assert error_code == 0 |
| 70 | + |
| 71 | + commands = factor.split() |
| 72 | + commands.extend(["--cachedir", cache_dir, get_data("tests/wf/" + test_file)]) |
| 73 | + error_code, _, stderr = get_main_output(commands) |
| 74 | + |
| 75 | + stderr = re.sub(r"\s\s+", " ", stderr) |
| 76 | + assert "Output of job will be cached in" not in stderr |
| 77 | + assert error_code == 0, stderr |
| 78 | + |
| 79 | + |
| 80 | +@needs_docker |
| 81 | +@pytest.mark.parametrize("factor", test_factors) |
| 82 | +def test_cache_relative_paths(tmp_path: Path, factor: str) -> None: |
| 83 | + """Confirm that re-running a particular workflow with caching succeeds.""" |
| 84 | + test_file = "secondary-files.cwl" |
| 85 | + test_job_file = "secondary-files-job.yml" |
| 86 | + cache_dir = str(tmp_path / "cwltool_cache") |
| 87 | + commands = factor.split() |
| 88 | + commands.extend( |
| 89 | + [ |
| 90 | + "--out", |
| 91 | + str(tmp_path / "out"), |
| 92 | + "--cachedir", |
| 93 | + cache_dir, |
| 94 | + get_data(f"tests/{test_file}"), |
| 95 | + get_data(f"tests/{test_job_file}"), |
| 96 | + ] |
| 97 | + ) |
| 98 | + error_code, _, stderr = get_main_output(commands) |
| 99 | + |
| 100 | + stderr = re.sub(r"\s\s+", " ", stderr) |
| 101 | + assert "completed success" in stderr |
| 102 | + assert error_code == 0 |
| 103 | + |
| 104 | + commands = factor.split() |
| 105 | + commands.extend( |
| 106 | + [ |
| 107 | + "--out", |
| 108 | + str(tmp_path / "out2"), |
| 109 | + "--cachedir", |
| 110 | + cache_dir, |
| 111 | + get_data(f"tests/{test_file}"), |
| 112 | + get_data(f"tests/{test_job_file}"), |
| 113 | + ] |
| 114 | + ) |
| 115 | + error_code, _, stderr = get_main_output(commands) |
| 116 | + |
| 117 | + stderr = re.sub(r"\s\s+", " ", stderr) |
| 118 | + assert "Output of job will be cached in" not in stderr |
| 119 | + assert error_code == 0, stderr |
| 120 | + |
| 121 | + assert (tmp_path / "cwltool_cache" / "27903451fc1ee10c148a0bdeb845b2cf").exists() |
| 122 | + |
| 123 | + |
| 124 | +@pytest.mark.parametrize("factor", test_factors) |
| 125 | +def test_cache_default_literal_file(tmp_path: Path, factor: str) -> None: |
| 126 | + """Confirm that running a CLT with a default literal file with caching succeeds.""" |
| 127 | + test_file = "tests/wf/extract_region_specs.cwl" |
| 128 | + cache_dir = str(tmp_path / "cwltool_cache") |
| 129 | + commands = factor.split() |
| 130 | + commands.extend( |
| 131 | + [ |
| 132 | + "--out", |
| 133 | + str(tmp_path / "out"), |
| 134 | + "--cachedir", |
| 135 | + cache_dir, |
| 136 | + get_data(test_file), |
| 137 | + ] |
| 138 | + ) |
| 139 | + error_code, _, stderr = get_main_output(commands) |
| 140 | + |
| 141 | + stderr = re.sub(r"\s\s+", " ", stderr) |
| 142 | + assert "completed success" in stderr |
| 143 | + assert error_code == 0 |
| 144 | + |
| 145 | + |
| 146 | +@needs_docker |
| 147 | +@pytest.mark.parametrize("factor", test_factors) |
| 148 | +def test_cache_dockerreq_hint_instead_of_req(tmp_path: Path, factor: str) -> None: |
| 149 | + """The cache must not be checked when there is an invalid use of an absolute path in iwdr.listing.""" |
| 150 | + cache_dir = str(tmp_path / "cwltool_cache") |
| 151 | + test_job_file = "tests/wf/loadContents-input.yml" |
| 152 | + # First, run the iwd-container-entryname1 conformance tests with caching turned on |
| 153 | + test1_file = "tests/wf/iwd-container-entryname1.cwl" |
| 154 | + commands1 = factor.split() |
| 155 | + commands1.extend( |
| 156 | + [ |
| 157 | + "--out", |
| 158 | + str(tmp_path / "out1"), |
| 159 | + "--cachedir", |
| 160 | + cache_dir, |
| 161 | + get_data(test1_file), |
| 162 | + get_data(test_job_file), |
| 163 | + ] |
| 164 | + ) |
| 165 | + error_code1, _, stderr1 = get_main_output(commands1) |
| 166 | + |
| 167 | + stderr1 = re.sub(r"\s\s+", " ", stderr1) |
| 168 | + assert "completed success" in stderr1 |
| 169 | + assert error_code1 == 0 |
| 170 | + # Second, run the iwd-container-entryname3 test, which should fail |
| 171 | + # even though it would be a cache hit, except that its DockerRequirement is |
| 172 | + # in `hints` instead of `requirements` and one of the initial working directory |
| 173 | + # items has an absolute path starting with `/`. |
| 174 | + test2_file = "tests/wf/iwd-container-entryname3.cwl" |
| 175 | + commands2 = factor.split() |
| 176 | + commands2.extend( |
| 177 | + [ |
| 178 | + "--out", |
| 179 | + str(tmp_path / "out2"), |
| 180 | + "--cachedir", |
| 181 | + cache_dir, |
| 182 | + get_data(test2_file), |
| 183 | + get_data(test_job_file), |
| 184 | + ] |
| 185 | + ) |
| 186 | + error_code2, _, stderr2 = get_main_output(commands2) |
| 187 | + |
| 188 | + stderr2 = re.sub(r"\s\s+", " ", stderr2) |
| 189 | + assert ( |
| 190 | + "at index 0 of listing is invalid, name can only start with '/' " |
| 191 | + "when DockerRequirement is in 'requirements" in stderr2 |
| 192 | + ) |
| 193 | + assert error_code2 == 1 |
0 commit comments