9
9
from typing import Any , Dict , List , Union , cast
10
10
from urllib .parse import urlparse
11
11
12
- import py .path
13
12
import pydot # type: ignore
14
13
import pytest
15
14
from ruamel .yaml .comments import CommentedMap , CommentedSeq
34
33
get_main_output ,
35
34
get_windows_safe_factory ,
36
35
needs_docker ,
37
- temp_dir ,
38
36
windows_needs_docker ,
39
37
)
40
38
@@ -1053,62 +1051,64 @@ def test_no_js_console(factor: str) -> None:
1053
1051
1054
1052
@needs_docker
1055
1053
@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."""
1057
1056
test_file = "cache_test_workflow.cwl"
1058
- cwd = tmpdir .chdir ()
1057
+ cwd = Path .cwd ()
1058
+ os .chdir (tmp_path )
1059
1059
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 )])
1061
1061
error_code , stdout , stderr = get_main_output (commands )
1062
1062
assert "completed success" in stderr
1063
1063
assert error_code == 0
1064
- cidfiles_count = sum (1 for _ in tmpdir . visit ( fil = " *" ))
1064
+ cidfiles_count = sum (1 for _ in tmp_path . glob ( "**/ *" ))
1065
1065
assert cidfiles_count == 2
1066
- cwd .chdir ()
1067
- tmpdir .remove (ignore_errors = True )
1066
+ os .chdir (cwd )
1068
1067
1069
1068
1070
1069
@needs_docker
1071
1070
@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."""
1075
1073
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 ()
1077
1076
commands = factor .split ()
1078
1077
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 )]
1080
1079
)
1081
1080
error_code , _ , stderr = get_main_output (commands )
1082
1081
assert "is not a directory, please check it first" in stderr , stderr
1083
1082
assert error_code == 2 or error_code == 1 , stderr
1084
- tmpdir .remove (ignore_errors = True )
1085
1083
1086
1084
1087
1085
@needs_docker
1088
1086
@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."""
1090
1089
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"
1092
1091
commands = factor .split ()
1093
1092
commands .extend (
1094
1093
[
1095
1094
"--record-container-id" ,
1096
1095
"--cidfile-dir" ,
1097
- bad_cidfile_dir ,
1096
+ str ( bad_cidfile_dir ) ,
1098
1097
get_data ("tests/wf/" + test_file ),
1099
1098
]
1100
1099
)
1101
1100
error_code , _ , stderr = get_main_output (commands )
1102
1101
assert "directory doesn't exist, please create it first" in stderr , stderr
1103
1102
assert error_code == 2 or error_code == 1 , stderr
1104
- tmpdir .remove (ignore_errors = True )
1105
1103
1106
1104
1107
1105
@needs_docker
1108
1106
@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."""
1110
1109
test_file = "cache_test_workflow.cwl"
1111
- cwd = tmpdir .chdir ()
1110
+ cwd = Path .cwd ()
1111
+ os .chdir (tmp_path )
1112
1112
try :
1113
1113
commands = factor .split ()
1114
1114
commands .extend (
@@ -1120,13 +1120,12 @@ def test_cid_file_w_prefix(tmpdir: py.path.local, factor: str) -> None:
1120
1120
)
1121
1121
error_code , stdout , stderr = get_main_output (commands )
1122
1122
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*" ))
1127
1126
assert "completed success" in stderr
1128
1127
assert error_code == 0
1129
- assert cidfiles_count == 2 , "{}/n{}" .format (listing , stderr )
1128
+ assert cidfiles_count == 2 , "{}/n{}" .format (list ( listing ) , stderr )
1130
1129
1131
1130
1132
1131
@needs_docker
@@ -1178,45 +1177,47 @@ def test_secondary_files_v1_0(factor: str) -> None:
1178
1177
1179
1178
@needs_docker
1180
1179
@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."""
1182
1182
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 )
1197
1197
1198
1198
assert "completed success" in stderr
1199
1199
assert error_code == 0
1200
1200
1201
1201
1202
1202
@needs_docker
1203
1203
@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."""
1205
1206
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 )
1210
1211
1211
- assert "completed success" in stderr
1212
- assert error_code == 0
1212
+ assert "completed success" in stderr
1213
+ assert error_code == 0
1213
1214
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 )
1217
1218
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
1220
1221
1221
1222
1222
1223
@needs_docker
@@ -1238,15 +1239,15 @@ def test_compute_checksum() -> None:
1238
1239
1239
1240
@needs_docker
1240
1241
@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 :
1242
1243
test_file = "tests/wf/wc-tool.cwl"
1243
1244
job_file = "tests/wf/wc-job.json"
1244
1245
commands = factor .split ()
1245
1246
commands .extend (
1246
1247
[
1247
1248
"--no-compute-checksum" ,
1248
1249
"--outdir" ,
1249
- str (tmpdir ),
1250
+ str (tmp_path ),
1250
1251
get_data (test_file ),
1251
1252
get_data (job_file ),
1252
1253
]
@@ -1379,9 +1380,10 @@ def test_v1_0_arg_empty_prefix_separate_false() -> None:
1379
1380
assert error_code == 0
1380
1381
1381
1382
1382
- def test_scatter_output_filenames (tmpdir : py . path . local ) -> None :
1383
+ def test_scatter_output_filenames (tmp_path : Path ) -> None :
1383
1384
"""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 )
1385
1387
rtc = RuntimeContext ()
1386
1388
rtc .outdir = str (cwd )
1387
1389
factory = cwltool .factory .Factory (runtime_context = rtc )
0 commit comments