Skip to content

Commit 5f30c8e

Browse files
committed
tests: replace py.path and NamedTemporaryFile with pathlib.Path
1 parent ac60dc1 commit 5f30c8e

17 files changed

+563
-585
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pep257: pydocstyle
9292
pydocstyle: $(PYSOURCES)
9393
pydocstyle --add-ignore=D100,D101,D102,D103 $^ || true
9494

95-
pydocstyle_report.txt: $(PYSOURCES)
95+
pydocstyle_report.txt: $(filter-out tests/%,${PYSOURCES})
9696
pydocstyle setup.py $^ > $@ 2>&1 || true
9797

9898
diff_pydocstyle_report: pydocstyle_report.txt

cwltool/executors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@
3232
from .mutation import MutationManager
3333
from .process import Process, cleanIntermediate, relocateOutputs
3434
from .provenance_profile import ProvenanceProfile
35+
from .task_queue import TaskQueue
3536
from .utils import CWLObjectType, JobsType
3637
from .workflow import Workflow
3738
from .workflow_job import WorkflowJob, WorkflowJobStep
38-
from .task_queue import TaskQueue
39-
4039

4140
TMPDIR_LOCK = Lock()
4241

cwltool/task_queue.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import queue
77
import threading
8-
98
from typing import Callable, Optional
109

1110
from .loghandler import _logger

tests/test_docker.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
from distutils import spawn
2-
3-
import py.path
2+
from pathlib import Path
43

54
from cwltool.main import main
65

76
from .util import get_data, get_main_output, needs_docker
87

98

109
@needs_docker
11-
def test_docker_workflow(tmpdir: py.path.local) -> None:
10+
def test_docker_workflow(tmp_path: Path) -> None:
11+
"""Basic test for docker with a CWL Workflow."""
1212
result_code, _, stderr = get_main_output(
1313
[
1414
"--default-container",
1515
"debian",
1616
"--outdir",
17-
str(tmpdir),
17+
str(tmp_path),
1818
get_data("tests/wf/hello-workflow.cwl"),
1919
"--usermessage",
2020
"hello",
2121
]
2222
)
2323
assert "completed success" in stderr
24-
assert (tmpdir / "response.txt").read_text("utf-8") == "hello"
24+
assert (tmp_path / "response.txt").read_text("utf-8") == "hello"
2525
assert result_code == 0
2626

2727

tests/test_empty_input.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
from io import StringIO
2+
from pathlib import Path
23

34
from cwltool.main import main
45

5-
from .util import get_data, temp_dir, windows_needs_docker
6+
from .util import get_data, windows_needs_docker
67

78

89
@windows_needs_docker
9-
def test_empty_input() -> None:
10+
def test_empty_input(tmp_path: Path) -> None:
11+
"""Affirm that an empty input works."""
1012
empty_json = "{}"
1113
empty_input = StringIO(empty_json)
1214

13-
with temp_dir() as tmpdir:
14-
params = ["--outdir", tmpdir, get_data("tests/wf/no-parameters-echo.cwl"), "-"]
15+
params = [
16+
"--outdir",
17+
str(tmp_path),
18+
get_data("tests/wf/no-parameters-echo.cwl"),
19+
"-",
20+
]
1521

16-
try:
17-
assert main(params, stdin=empty_input) == 0
18-
except SystemExit as err:
19-
assert err.code == 0
22+
try:
23+
assert main(params, stdin=empty_input) == 0
24+
except SystemExit as err:
25+
assert err.code == 0

tests/test_examples.py

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from typing import Any, Dict, List, Union, cast
1010
from urllib.parse import urlparse
1111

12-
import py.path
1312
import pydot # type: ignore
1413
import pytest
1514
from ruamel.yaml.comments import CommentedMap, CommentedSeq
@@ -34,7 +33,6 @@
3433
get_main_output,
3534
get_windows_safe_factory,
3635
needs_docker,
37-
temp_dir,
3836
windows_needs_docker,
3937
)
4038

@@ -1053,62 +1051,64 @@ def test_no_js_console(factor: str) -> None:
10531051

10541052
@needs_docker
10551053
@pytest.mark.parametrize("factor", test_factors)
1056-
def test_cid_file_dir(tmpdir: py.path.local, factor: str) -> None:
1054+
def test_cid_file_dir(tmp_path: Path, factor: str) -> None:
1055+
"""Test --cidfile-dir option works."""
10571056
test_file = "cache_test_workflow.cwl"
1058-
cwd = tmpdir.chdir()
1057+
cwd = Path.cwd()
1058+
os.chdir(tmp_path)
10591059
commands = factor.split()
1060-
commands.extend(["--cidfile-dir", str(tmpdir), get_data("tests/wf/" + test_file)])
1060+
commands.extend(["--cidfile-dir", str(tmp_path), get_data("tests/wf/" + test_file)])
10611061
error_code, stdout, stderr = get_main_output(commands)
10621062
assert "completed success" in stderr
10631063
assert error_code == 0
1064-
cidfiles_count = sum(1 for _ in tmpdir.visit(fil="*"))
1064+
cidfiles_count = sum(1 for _ in tmp_path.glob("**/*"))
10651065
assert cidfiles_count == 2
1066-
cwd.chdir()
1067-
tmpdir.remove(ignore_errors=True)
1066+
os.chdir(cwd)
10681067

10691068

10701069
@needs_docker
10711070
@pytest.mark.parametrize("factor", test_factors)
1072-
def test_cid_file_dir_arg_is_file_instead_of_dir(
1073-
tmpdir: py.path.local, factor: str
1074-
) -> None:
1071+
def test_cid_file_dir_arg_is_file_instead_of_dir(tmp_path: Path, factor: str) -> None:
1072+
"""Test --cidfile-dir with a file produces the correct error."""
10751073
test_file = "cache_test_workflow.cwl"
1076-
bad_cidfile_dir = str(tmpdir.ensure("cidfile-dir-actually-a-file"))
1074+
bad_cidfile_dir = tmp_path / "cidfile-dir-actually-a-file"
1075+
bad_cidfile_dir.touch()
10771076
commands = factor.split()
10781077
commands.extend(
1079-
["--cidfile-dir", bad_cidfile_dir, get_data("tests/wf/" + test_file)]
1078+
["--cidfile-dir", str(bad_cidfile_dir), get_data("tests/wf/" + test_file)]
10801079
)
10811080
error_code, _, stderr = get_main_output(commands)
10821081
assert "is not a directory, please check it first" in stderr, stderr
10831082
assert error_code == 2 or error_code == 1, stderr
1084-
tmpdir.remove(ignore_errors=True)
10851083

10861084

10871085
@needs_docker
10881086
@pytest.mark.parametrize("factor", test_factors)
1089-
def test_cid_file_non_existing_dir(tmpdir: py.path.local, factor: str) -> None:
1087+
def test_cid_file_non_existing_dir(tmp_path: Path, factor: str) -> None:
1088+
"""Test that --cachedir with a bad path should produce a specific error."""
10901089
test_file = "cache_test_workflow.cwl"
1091-
bad_cidfile_dir = str(tmpdir.join("cidfile-dir-badpath"))
1090+
bad_cidfile_dir = tmp_path / "cidfile-dir-badpath"
10921091
commands = factor.split()
10931092
commands.extend(
10941093
[
10951094
"--record-container-id",
10961095
"--cidfile-dir",
1097-
bad_cidfile_dir,
1096+
str(bad_cidfile_dir),
10981097
get_data("tests/wf/" + test_file),
10991098
]
11001099
)
11011100
error_code, _, stderr = get_main_output(commands)
11021101
assert "directory doesn't exist, please create it first" in stderr, stderr
11031102
assert error_code == 2 or error_code == 1, stderr
1104-
tmpdir.remove(ignore_errors=True)
11051103

11061104

11071105
@needs_docker
11081106
@pytest.mark.parametrize("factor", test_factors)
1109-
def test_cid_file_w_prefix(tmpdir: py.path.local, factor: str) -> None:
1107+
def test_cid_file_w_prefix(tmp_path: Path, factor: str) -> None:
1108+
"""Test that --cidfile-prefix works."""
11101109
test_file = "cache_test_workflow.cwl"
1111-
cwd = tmpdir.chdir()
1110+
cwd = Path.cwd()
1111+
os.chdir(tmp_path)
11121112
try:
11131113
commands = factor.split()
11141114
commands.extend(
@@ -1120,13 +1120,12 @@ def test_cid_file_w_prefix(tmpdir: py.path.local, factor: str) -> None:
11201120
)
11211121
error_code, stdout, stderr = get_main_output(commands)
11221122
finally:
1123-
listing = tmpdir.listdir()
1124-
cwd.chdir()
1125-
cidfiles_count = sum(1 for _ in tmpdir.visit(fil="pytestcid*"))
1126-
tmpdir.remove(ignore_errors=True)
1123+
listing = tmp_path.iterdir()
1124+
os.chdir(cwd)
1125+
cidfiles_count = sum(1 for _ in tmp_path.glob("**/pytestcid*"))
11271126
assert "completed success" in stderr
11281127
assert error_code == 0
1129-
assert cidfiles_count == 2, "{}/n{}".format(listing, stderr)
1128+
assert cidfiles_count == 2, "{}/n{}".format(list(listing), stderr)
11301129

11311130

11321131
@needs_docker
@@ -1178,45 +1177,47 @@ def test_secondary_files_v1_0(factor: str) -> None:
11781177

11791178
@needs_docker
11801179
@pytest.mark.parametrize("factor", test_factors)
1181-
def test_wf_without_container(tmpdir: py.path.local, factor: str) -> None:
1180+
def test_wf_without_container(tmp_path: Path, factor: str) -> None:
1181+
"""Confirm that we can run a workflow without a container."""
11821182
test_file = "hello-workflow.cwl"
1183-
with temp_dir("cwltool_cache") as cache_dir:
1184-
commands = factor.split()
1185-
commands.extend(
1186-
[
1187-
"--cachedir",
1188-
cache_dir,
1189-
"--outdir",
1190-
str(tmpdir),
1191-
get_data("tests/wf/" + test_file),
1192-
"--usermessage",
1193-
"hello",
1194-
]
1195-
)
1196-
error_code, _, stderr = get_main_output(commands)
1183+
cache_dir = str(tmp_path / "cwltool_cache")
1184+
commands = factor.split()
1185+
commands.extend(
1186+
[
1187+
"--cachedir",
1188+
cache_dir,
1189+
"--outdir",
1190+
str(tmp_path / "outdir"),
1191+
get_data("tests/wf/" + test_file),
1192+
"--usermessage",
1193+
"hello",
1194+
]
1195+
)
1196+
error_code, _, stderr = get_main_output(commands)
11971197

11981198
assert "completed success" in stderr
11991199
assert error_code == 0
12001200

12011201

12021202
@needs_docker
12031203
@pytest.mark.parametrize("factor", test_factors)
1204-
def test_issue_740_fixed(factor: str) -> None:
1204+
def test_issue_740_fixed(tmp_path: Path, factor: str) -> None:
1205+
"""Confirm that re-running a particular workflow with caching suceeds."""
12051206
test_file = "cache_test_workflow.cwl"
1206-
with temp_dir("cwltool_cache") as cache_dir:
1207-
commands = factor.split()
1208-
commands.extend(["--cachedir", cache_dir, get_data("tests/wf/" + test_file)])
1209-
error_code, _, stderr = get_main_output(commands)
1207+
cache_dir = str(tmp_path / "cwltool_cache")
1208+
commands = factor.split()
1209+
commands.extend(["--cachedir", cache_dir, get_data("tests/wf/" + test_file)])
1210+
error_code, _, stderr = get_main_output(commands)
12101211

1211-
assert "completed success" in stderr
1212-
assert error_code == 0
1212+
assert "completed success" in stderr
1213+
assert error_code == 0
12131214

1214-
commands = factor.split()
1215-
commands.extend(["--cachedir", cache_dir, get_data("tests/wf/" + test_file)])
1216-
error_code, _, stderr = get_main_output(commands)
1215+
commands = factor.split()
1216+
commands.extend(["--cachedir", cache_dir, get_data("tests/wf/" + test_file)])
1217+
error_code, _, stderr = get_main_output(commands)
12171218

1218-
assert "Output of job will be cached in" not in stderr
1219-
assert error_code == 0, stderr
1219+
assert "Output of job will be cached in" not in stderr
1220+
assert error_code == 0, stderr
12201221

12211222

12221223
@needs_docker
@@ -1238,15 +1239,15 @@ def test_compute_checksum() -> None:
12381239

12391240
@needs_docker
12401241
@pytest.mark.parametrize("factor", test_factors)
1241-
def test_no_compute_chcksum(tmpdir: py.path.local, factor: str) -> None:
1242+
def test_no_compute_chcksum(tmp_path: Path, factor: str) -> None:
12421243
test_file = "tests/wf/wc-tool.cwl"
12431244
job_file = "tests/wf/wc-job.json"
12441245
commands = factor.split()
12451246
commands.extend(
12461247
[
12471248
"--no-compute-checksum",
12481249
"--outdir",
1249-
str(tmpdir),
1250+
str(tmp_path),
12501251
get_data(test_file),
12511252
get_data(job_file),
12521253
]
@@ -1379,9 +1380,10 @@ def test_v1_0_arg_empty_prefix_separate_false() -> None:
13791380
assert error_code == 0
13801381

13811382

1382-
def test_scatter_output_filenames(tmpdir: py.path.local) -> None:
1383+
def test_scatter_output_filenames(tmp_path: Path) -> None:
13831384
"""If a scatter step produces identically named output then confirm that the final output is renamed correctly."""
1384-
cwd = tmpdir.chdir()
1385+
cwd = Path.cwd()
1386+
os.chdir(tmp_path)
13851387
rtc = RuntimeContext()
13861388
rtc.outdir = str(cwd)
13871389
factory = cwltool.factory.Factory(runtime_context=rtc)

0 commit comments

Comments
 (0)