forked from nipype/pydra-fsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_run_cluster.py
64 lines (62 loc) · 2.22 KB
/
test_run_cluster.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import re, os, shutil, pytest
from pathlib import Path
from ..cluster import Cluster
@pytest.mark.xfail("FSLDIR" not in os.environ, reason="no FSL found", raises=FileNotFoundError)
@pytest.mark.parametrize(
"inputs, outputs",
[
(
{
"in_file": "zstat1.nii.gz",
"threshold": 2.3,
"use_mm": True,
"out_index_file": True,
},
[
"out_index_file",
"out_localmax_txt_file",
"out_localmax_vol_file",
"out_threshold_file",
"out_max_file",
"out_mean_file",
"out_pval_file",
"out_size_file",
"out_threshold_file",
],
)
],
)
def test_Cluster(test_data, inputs, outputs):
if inputs is None:
in_file = Path(test_data) / "test.nii.gz"
task = Cluster(in_file=in_file)
else:
for key, val in inputs.items():
try:
pattern = r"\.[a-zA-Z]*"
if isinstance(val, str):
if re.findall(pattern, val) != []:
inputs[key] = Path(test_data) / val
elif "_dir" in key:
dirpath = Path(test_data) / val
if dirpath.exists() and dirpath.is_dir():
shutil.rmtree(dirpath)
inputs[key] = Path(test_data) / val
else:
inputs[key] = eval(val)
elif isinstance(val, list):
if all(re.findall(pattern, _) != [] for _ in val):
inputs[key] = [Path(test_data) / _ for _ in val]
else:
inputs[key] = eval(val)
except:
pass
task = Cluster(**inputs)
assert set(task.generated_output_names) == set(["return_code", "stdout", "stderr"] + outputs)
res = task()
print("RESULT: ", res)
for out_nm in outputs:
if isinstance(getattr(res.output, out_nm), list):
assert [os.path.exists(x) for x in getattr(res.output, out_nm)]
else:
assert os.path.exists(getattr(res.output, out_nm))