Skip to content

Commit a45c9f8

Browse files
authored
[MAINT] refactor and increase tests for run.py (#249)
* refactor and increase tests * add graphviz for travis python builds
1 parent 59456ff commit a45c9f8

File tree

2 files changed

+61
-68
lines changed

2 files changed

+61
-68
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,23 @@ jobs:
4545
- TOXENV=docs
4646
python: '3.5' # match version from readthedocs
4747
- stage: test
48+
before_install:
49+
- sudo apt-get update
50+
- sudo apt-get install -y graphviz
4851
python: '3.5'
4952
env:
5053
- TOXENV=py35
5154
- stage: test
55+
before_install:
56+
- sudo apt-get update
57+
- sudo apt-get install -y graphviz
5258
python: '3.6'
5359
env:
5460
- TOXENV=py36
5561
- stage: test
62+
before_install:
63+
- sudo apt-get update
64+
- sudo apt-get install -y graphviz
5665
python: '3.7'
5766
env:
5867
- TOXENV=py37,report,codecov
Lines changed: 52 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from subprocess import call
21
import os
32

43
import pytest
@@ -37,74 +36,41 @@ def test_conditional_arguments(monkeypatch):
3736
get_parser().parse_args(no_img)
3837

3938

40-
def test_nibs_lss(bids_dir, atlas_file, atlas_lut, deriv_dir):
41-
bids_dir = str(bids_dir)
42-
out_dir = os.path.join(bids_dir, 'derivatives')
43-
assert call(["nibs",
44-
"-a " + str(atlas_file),
45-
"-l " + str(atlas_lut),
46-
"-c WhiteMatter CSF",
47-
"--high-pass 0.008",
48-
"--estimator lss",
49-
"-sp MNI152NLin2009cAsym",
50-
"-sm 0.0",
51-
"--hrf-model spm",
52-
"--session-label pre",
53-
"--task-label waffles",
54-
"--run-label 1",
55-
"--description-label preproc",
56-
"--graph",
57-
bids_dir,
58-
"fmriprep",
59-
out_dir,
60-
"participant"])
61-
62-
63-
def test_nibs_fs(bids_dir, atlas_file, atlas_lut, deriv_dir):
64-
bids_dir = str(bids_dir)
65-
out_dir = os.path.join(bids_dir, 'derivatives')
66-
assert call(["nibs",
67-
"-a " + str(atlas_file),
68-
"-l " + str(atlas_lut),
69-
"-c WhiteMatter CSF",
70-
"--high-pass 0.008",
71-
"--estimator lss",
72-
"-sp MNI152NLin2009cAsym",
73-
"-sm 0.0",
74-
"--hrf-model fir",
75-
"--fir-delays 0 1 2 3 4"
76-
"--session-label pre",
77-
"--task-label waffles",
78-
"--run-label 1",
79-
"--description-label preproc",
80-
"--graph",
81-
bids_dir,
82-
"fmriprep",
83-
out_dir,
84-
"participant"])
85-
86-
87-
def test_nibs_lsa(bids_dir, atlas_file, atlas_lut, deriv_dir):
39+
@pytest.mark.parametrize("estimator,fir_delays,hrf_model",
40+
[('lsa', None, 'spm'),
41+
('lss', None, 'spm'),
42+
('lss', [0, 1, 2, 3, 4], 'fir')])
43+
def test_nibs(
44+
bids_dir, deriv_dir, sub_fmriprep, sub_metadata, bold_file, preproc_file,
45+
sub_events, confounds_file, brainmask_file, atlas_file, atlas_lut,
46+
estimator, fir_delays, hrf_model, monkeypatch):
47+
import sys
8848
bids_dir = str(bids_dir)
8949
out_dir = os.path.join(bids_dir, 'derivatives')
90-
assert call(["nibs",
91-
"-a " + str(atlas_file),
92-
"-l " + str(atlas_lut),
93-
"-c WhiteMatter CSF",
94-
"--high-pass 0.008",
95-
"--estimator lsa",
96-
"-sp MNI152NLin2009cAsym",
97-
"-sm 0.0",
98-
"--hrf-model spm",
99-
"--session-label pre",
100-
"--task-label waffles",
101-
"--run-label 1",
102-
"--description-label preproc",
103-
"--graph",
104-
bids_dir,
105-
"fmriprep",
106-
out_dir,
107-
"participant"])
50+
args = ["nibs",
51+
"-a", str(atlas_file),
52+
"-l", str(atlas_lut),
53+
"-c", "WhiteMatter", "CSF",
54+
"--high-pass", "0.008",
55+
"--estimator", estimator,
56+
"-sp", "MNI152NLin2009cAsym",
57+
"-sm", "0.0",
58+
"--hrf-model", hrf_model,
59+
"--session-label", "pre",
60+
"--task-label", "waffles",
61+
"--run-label", "1",
62+
"--description-label", "preproc",
63+
"--graph",
64+
bids_dir,
65+
"fmriprep",
66+
out_dir,
67+
"participant"]
68+
if fir_delays:
69+
args.append('--fir-delays')
70+
args.extend([str(d) for d in fir_delays])
71+
72+
monkeypatch.setattr(sys, 'argv', args)
73+
assert main() is None
10874

10975

11076
def test_init(monkeypatch):
@@ -114,7 +80,7 @@ def test_init(monkeypatch):
11480
run.init()
11581

11682

117-
def test_main(monkeypatch):
83+
def test_deriv_directory(monkeypatch):
11884
import sys
11985

12086
parser_args = [
@@ -131,3 +97,21 @@ def test_main(monkeypatch):
13197
main()
13298

13399
assert "is not an available directory" in str(no_dir.value)
100+
101+
102+
def test_fir_delays(monkeypatch):
103+
import sys
104+
105+
parser_args = [
106+
'nibs',
107+
'bids_dir',
108+
'derivatives_pipeline',
109+
'output_dir',
110+
'participant',
111+
'--hrf-model', 'fir',
112+
]
113+
monkeypatch.setattr(sys, 'argv', parser_args)
114+
with pytest.raises(ValueError) as no_delays:
115+
main()
116+
117+
assert "If the FIR HRF model is selected" in str(no_delays.value)

0 commit comments

Comments
 (0)