Skip to content

Commit a40bebd

Browse files
committed
tests: no more files written to the working directory.
1 parent eacf048 commit a40bebd

File tree

7 files changed

+43
-12
lines changed

7 files changed

+43
-12
lines changed

.github/workflows/ci-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ jobs:
6969
path: .mypy_cache/${{ env.py-semver }}
7070
key: mypy-${{ env.py-semver }}
7171

72+
- name: make working directory read-only
73+
run: chmod a-w .
74+
7275
- name: Test with tox
7376
run: tox
7477

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
@@ -10,6 +10,8 @@
1010

1111
from .util import get_data, get_main_output, needs_docker, needs_singularity
1212

13+
import pytest
14+
1315

1416
def test_newline_in_entry() -> None:
1517
"""Files in a InitialWorkingDirectory are created with a newline character."""
@@ -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_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
@@ -5,6 +5,8 @@
55

66
from cwltool.main import main
77

8+
import pytest
9+
810
from .util import (
911
get_data,
1012
get_main_output,
@@ -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)