Skip to content

Commit 6922e8d

Browse files
committed
[TST] Add doctest for #1339
1 parent e706408 commit 6922e8d

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

fmriprep/interfaces/bids.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,35 @@ class DerivativesDataSink(SimpleInterface):
184184
Saves the `in_file` into a BIDS-Derivatives folder provided
185185
by `base_directory`, given the input reference `source_file`.
186186
187+
>>> from pathlib import Path
187188
>>> import tempfile
188189
>>> from fmriprep.utils.bids import collect_data
189-
>>> tmpdir = tempfile.mkdtemp()
190-
>>> tmpfile = os.path.join(tmpdir, 'a_temp_file.nii.gz')
191-
>>> open(tmpfile, 'w').close() # "touch" the file
192-
>>> dsink = DerivativesDataSink(base_directory=tmpdir)
193-
>>> dsink.inputs.in_file = tmpfile
190+
>>> tmpdir = Path(tempfile.mkdtemp())
191+
>>> tmpfile = tmpdir / 'a_temp_file.nii.gz'
192+
>>> tmpfile.open('w').close() # "touch" the file
193+
>>> dsink = DerivativesDataSink(base_directory=str(tmpdir))
194+
>>> dsink.inputs.in_file = str(tmpfile)
194195
>>> dsink.inputs.source_file = collect_data('ds114', '01')[0]['t1w'][0]
195196
>>> dsink.inputs.keep_dtype = True
196197
>>> dsink.inputs.suffix = 'target-mni'
197198
>>> res = dsink.run()
198199
>>> res.outputs.out_file # doctest: +ELLIPSIS
199200
'.../fmriprep/sub-01/ses-retest/anat/sub-01_ses-retest_target-mni_T1w.nii.gz'
200201
202+
>>> bids_dir = tmpdir / 'bidsroot' / 'sub-02' / 'ses-noanat' / 'func'
203+
>>> bids_dir.mkdir(parents=True, exist_ok=True)
204+
>>> tricky_source = bids_dir / 'sub-02_ses-noanat_task-rest_run-01_bold.nii.gz'
205+
>>> tricky_source.open('w').close()
206+
>>> dsink = DerivativesDataSink(base_directory=str(tmpdir))
207+
>>> dsink.inputs.in_file = str(tmpfile)
208+
>>> dsink.inputs.source_file = str(tricky_source)
209+
>>> dsink.inputs.keep_dtype = True
210+
>>> dsink.inputs.desc = 'preproc'
211+
>>> res = dsink.run()
212+
>>> res.outputs.out_file # doctest: +ELLIPSIS
213+
'.../fmriprep/sub-02/ses-noanat/func/sub-02_ses-noanat_task-rest_run-01_\
214+
desc-preproc_bold.nii.gz'
215+
201216
"""
202217
input_spec = DerivativesDataSinkInputSpec
203218
output_spec = DerivativesDataSinkOutputSpec

0 commit comments

Comments
 (0)