Skip to content

Commit 3f8bfbe

Browse files
committed
tests: no more files written to the working directory.
1 parent 73256b4 commit 3f8bfbe

9 files changed

+94
-17
lines changed

.github/workflows/ci-tests.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,44 @@ jobs:
114114
- name: Test with tox
115115
run: tox
116116

117+
clean_working_dir:
118+
name: No leftovers
119+
runs-on: ubuntu-22.04
120+
env:
121+
py-semver: "3.11"
122+
steps:
123+
- uses: actions/checkout@v3
124+
with:
125+
fetch-depth: 0
126+
127+
- name: Set up Singularity
128+
run: |
129+
wget --no-verbose https://github.com/sylabs/singularity/releases/download/v3.10.4/singularity-ce_3.10.4-focal_amd64.deb
130+
sudo apt-get install -y ./singularity-ce_3.10.4-focal_amd64.deb
131+
132+
- name: Give the test runner user a name to make provenance happy.
133+
run: sudo usermod -c 'CI Runner' $(whoami)
134+
135+
- name: Set up Python
136+
uses: actions/setup-python@v4
137+
with:
138+
python-version: ${{ env.py-semver }}
139+
cache: pip
140+
141+
- name: install with test dependencies
142+
run: |
143+
pip install -U pip setuptools wheel
144+
pip install --no-build-isolation -rtest-requirements.txt .[deps]
145+
146+
- name: make working directory read-only
147+
run: |
148+
mkdir .pytest_cache
149+
chmod a-w .
150+
151+
- name: run tests
152+
run: make test
153+
154+
117155
conformance_tests:
118156
name: CWL conformance
119157
runs-on: ubuntu-22.04

tests/test_dependencies.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""Tests of satisfying SoftwareRequirement via dependencies."""
22
import os
33
import tempfile
4+
from getpass import getuser
45
from pathlib import Path
56
from shutil import which
67
from types import ModuleType
7-
from typing import Optional, Tuple, Callable
8-
from getpass import getuser
8+
from typing import Optional, Tuple
9+
910
import pytest
1011

1112
from cwltool.context import LoadingContext
@@ -63,6 +64,7 @@ def bioconda_setup(request: pytest.FixtureRequest) -> Tuple[Optional[int], str]:
6364
:py:method:`pytest.TempPathFactory.getbasetemp`.
6465
"""
6566

67+
assert request.config.cache
6668
deps_dir = request.config.cache.get("bioconda_deps", None)
6769
if deps_dir is not None and not Path(deps_dir).exists():
6870
# cache value set, but cache is gone :( ... recreate
@@ -86,7 +88,7 @@ def bioconda_setup(request: pytest.FixtureRequest) -> Tuple[Optional[int], str]:
8688
request.config.cache.set("bioconda_deps", str(deps_dir))
8789

8890
deps_dirpath = Path(deps_dir)
89-
deps_dirpath.mkdir(exist_ok=True)
91+
deps_dirpath.mkdir(parents=True, exist_ok=True)
9092

9193
wflow = get_data("tests/seqtk_seq.cwl")
9294
job = get_data("tests/seqtk_seq_job.json")
@@ -106,7 +108,7 @@ def bioconda_setup(request: pytest.FixtureRequest) -> Tuple[Optional[int], str]:
106108

107109

108110
@pytest.mark.skipif(not deps, reason="galaxy-tool-util is not installed")
109-
def test_bioconda(bioconda_setup: Callable[[], Tuple[Optional[int], str]]) -> None:
111+
def test_bioconda(bioconda_setup: Tuple[Optional[int], str]) -> None:
110112
error_code, stderr = bioconda_setup
111113
assert error_code == 0, stderr
112114

tests/test_examples.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,8 @@ def test_cache_relative_paths(tmp_path: Path, factor: str) -> None:
12911291
commands = factor.split()
12921292
commands.extend(
12931293
[
1294+
"--out",
1295+
str(tmp_path / "out"),
12941296
"--cachedir",
12951297
cache_dir,
12961298
get_data(f"tests/{test_file}"),
@@ -1306,6 +1308,8 @@ def test_cache_relative_paths(tmp_path: Path, factor: str) -> None:
13061308
commands = factor.split()
13071309
commands.extend(
13081310
[
1311+
"--out",
1312+
str(tmp_path / "out2"),
13091313
"--cachedir",
13101314
cache_dir,
13111315
get_data(f"tests/{test_file}"),
@@ -1324,6 +1328,8 @@ def test_cache_relative_paths(tmp_path: Path, factor: str) -> None:
13241328
def test_write_summary(tmp_path: Path) -> None:
13251329
"""Test --write-summary."""
13261330
commands = [
1331+
"--out",
1332+
str(tmp_path / "out1"),
13271333
get_data("tests/wf/no-parameters-echo.cwl"),
13281334
]
13291335
error_code, stdout, stderr = get_main_output(commands)
@@ -1332,6 +1338,8 @@ def test_write_summary(tmp_path: Path) -> None:
13321338

13331339
final_output_path = str(tmp_path / "final-output.json")
13341340
commands_no = [
1341+
"--out",
1342+
str(tmp_path / "out2"),
13351343
"--write-summary",
13361344
final_output_path,
13371345
get_data("tests/wf/no-parameters-echo.cwl"),
@@ -1347,10 +1355,11 @@ def test_write_summary(tmp_path: Path) -> None:
13471355

13481356

13491357
@needs_docker
1350-
def test_compute_checksum() -> None:
1358+
def test_compute_checksum(tmp_path: Path) -> None:
13511359
runtime_context = RuntimeContext()
13521360
runtime_context.compute_checksum = True
13531361
runtime_context.use_container = False
1362+
runtime_context.outdir = str(tmp_path)
13541363
factory = cwltool.factory.Factory(runtime_context=runtime_context)
13551364
echo = factory.make(get_data("tests/wf/cat-tool.cwl"))
13561365
output = echo(
@@ -1413,10 +1422,12 @@ def test_bad_stdout_expr_error() -> None:
14131422

14141423

14151424
@needs_docker
1416-
def test_stdin_with_id_preset() -> None:
1425+
def test_stdin_with_id_preset(tmp_path: Path) -> None:
14171426
"""Confirm that a type: stdin with a preset id does not give an error."""
14181427
error_code, _, stderr = get_main_output(
14191428
[
1429+
"--out",
1430+
str(tmp_path),
14201431
get_data("tests/wf/1590.cwl"),
14211432
"--file1",
14221433
get_data("tests/wf/whale.txt"),
@@ -1590,7 +1601,7 @@ def test_v1_0_arg_empty_prefix_separate_false() -> None:
15901601

15911602
def test_scatter_output_filenames(tmp_path: Path) -> None:
15921603
"""Confirm that the final output is renamed correctly from identically named scatter outputs."""
1593-
cwd = Path.cwd()
1604+
cwd = tmp_path
15941605
with working_directory(tmp_path):
15951606
rtc = RuntimeContext()
15961607
rtc.outdir = str(cwd)
@@ -1726,10 +1737,10 @@ def test_command_line_tool_class() -> None:
17261737
assert str(expression_tool) == f"CommandLineTool: file://{tool_path}"
17271738

17281739

1729-
def test_record_default_with_long() -> None:
1740+
def test_record_default_with_long(tmp_path: Path) -> None:
17301741
"""Confirm that record defaults are respected."""
17311742
tool_path = get_data("tests/wf/paramref_arguments_roundtrip.cwl")
1732-
err_code, stdout, stderr = get_main_output([tool_path])
1743+
err_code, stdout, stderr = get_main_output(["--outdir", str(tmp_path), tool_path])
17331744
assert err_code == 0
17341745
result = json.loads(stdout)["same_record"]
17351746
assert result["first"] == "y"

tests/test_iwdr.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from stat import S_IWGRP, S_IWOTH, S_IWRITE
66
from typing import Any
77

8+
import pytest
9+
810
from cwltool.factory import Factory
911
from cwltool.main import main
1012

@@ -246,7 +248,9 @@ def test_iwdr_permutations_inplace(tmp_path_factory: Any) -> None:
246248

247249

248250
@needs_singularity
249-
def test_iwdr_permutations_singularity(tmp_path_factory: Any) -> None:
251+
def test_iwdr_permutations_singularity(
252+
tmp_path_factory: pytest.TempPathFactory, monkeypatch: pytest.MonkeyPatch
253+
) -> None:
250254
misc = tmp_path_factory.mktemp("misc")
251255
fifth = misc / "fifth"
252256
fifth.mkdir()
@@ -269,6 +273,8 @@ def test_iwdr_permutations_singularity(tmp_path_factory: Any) -> None:
269273
twelfth = misc / "twelfth"
270274
twelfth.touch()
271275
outdir = str(tmp_path_factory.mktemp("outdir"))
276+
singularity_dir = str(tmp_path_factory.mktemp("singularity"))
277+
monkeypatch.setenv("CWL_SINGULARITY_CACHE", singularity_dir)
272278
err_code, stdout, _ = get_main_output(
273279
[
274280
"--outdir",
@@ -306,7 +312,9 @@ def test_iwdr_permutations_singularity(tmp_path_factory: Any) -> None:
306312

307313

308314
@needs_singularity
309-
def test_iwdr_permutations_singularity_inplace(tmp_path_factory: Any) -> None:
315+
def test_iwdr_permutations_singularity_inplace(
316+
tmp_path_factory: pytest.TempPathFactory, monkeypatch: pytest.MonkeyPatch
317+
) -> None:
310318
"""IWDR tests using --singularity and a forced InplaceUpdateRequirement."""
311319
misc = tmp_path_factory.mktemp("misc")
312320
fifth = misc / "fifth"
@@ -330,6 +338,8 @@ def test_iwdr_permutations_singularity_inplace(tmp_path_factory: Any) -> None:
330338
twelfth = misc / "twelfth"
331339
twelfth.touch()
332340
outdir = str(tmp_path_factory.mktemp("outdir"))
341+
singularity_dir = str(tmp_path_factory.mktemp("singularity"))
342+
monkeypatch.setenv("CWL_SINGULARITY_CACHE", singularity_dir)
333343
assert (
334344
main(
335345
[

tests/test_js_sandbox.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ def hide_nodejs(temp_dir: Path) -> str:
6363
if entry not in ("nodejs", "node"):
6464
os.symlink(os.path.join(dirname, entry), new_dir / entry)
6565
paths.append(str(new_dir))
66+
dirname_path = Path(dirname)
67+
for path in paths:
68+
if Path(path).resolve() == dirname_path:
69+
paths.remove(path)
6670
return ":".join(paths)
6771

6872

@@ -94,12 +98,17 @@ def test_value_from_two_concatenated_expressions_singularity(
9498
js_engine = sandboxjs.get_js_engine()
9599
js_engine.have_node_slim = False # type: ignore[attr-defined]
96100
js_engine.localdata = threading.local() # type: ignore[attr-defined]
97-
new_paths = hide_nodejs(tmp_path)
101+
hide_base = tmp_path / "hide"
102+
hide_base.mkdir()
103+
new_paths = hide_nodejs(hide_base)
104+
singularity_cache = tmp_path / "singularity"
105+
singularity_cache.mkdir()
98106
factory = Factory()
99107
factory.loading_context.singularity = True
100108
factory.loading_context.debug = True
101109
factory.runtime_context.debug = True
102110
with monkeypatch.context() as m:
111+
m.setenv("CWL_SINGULARITY_CACHE", str(singularity_cache))
103112
m.setenv("PATH", new_paths)
104113
echo = factory.make(get_data("tests/wf/vf-concat.cwl"))
105114
file = {"class": "File", "location": get_data("tests/wf/whale.txt")}

tests/test_provenance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ def check_prov(
591591

592592

593593
@pytest.fixture
594-
def research_object() -> Generator[ResearchObject, None, None]:
595-
re_ob = ResearchObject(StdFsAccess(""))
594+
def research_object(tmp_path: Path) -> Generator[ResearchObject, None, None]:
595+
re_ob = ResearchObject(StdFsAccess(str(tmp_path / "ro")), temp_prefix_ro=str(tmp_path / "tmp"))
596596
yield re_ob
597597
re_ob.close()
598598

tests/test_singularity.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from pathlib import Path
44
from typing import Any
55

6+
import pytest
7+
68
from cwltool.main import main
79

810
from .util import (
@@ -58,7 +60,10 @@ def test_singularity_workflow(tmp_path: Path) -> None:
5860
assert error_code == 0
5961

6062

61-
def test_singularity_iwdr() -> None:
63+
def test_singularity_iwdr(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
64+
singularity_dir = tmp_path / "singularity"
65+
singularity_dir.mkdir()
66+
monkeypatch.setenv("CWL_SINGULARITY_CACHE", str(singularity_dir))
6267
result_code = main(
6368
[
6469
"--singularity",

tests/test_subgraph.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,12 @@ def test_single_process_packed_subwf_step(tmp_path: Path) -> None:
219219

220220

221221
@needs_docker
222-
def test_single_process_subwf_subwf_inline_step() -> None:
222+
def test_single_process_subwf_subwf_inline_step(tmp_path: Path) -> None:
223223
"""Test --single-process on an inline sub-sub-workflow step."""
224224
err_code, stdout, stderr = get_main_output(
225225
[
226+
"--outdir",
227+
str(tmp_path),
226228
"--single-process",
227229
"step1/stepX/stepY",
228230
get_data("tests/subgraph/count-lines17-wf.cwl.json"),

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ envlist =
1111
skip_missing_interpreters = True
1212

1313
[pytest]
14-
addopts=--ignore cwltool/schemas --basetemp ./tmp -n auto
14+
addopts=--ignore cwltool/schemas -n auto
1515
testpaths = tests
1616

1717
[gh-actions]

0 commit comments

Comments
 (0)