11# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22# vi: set ft=python sts=4 ts=4 sw=4 et:
33
4- from .....testing import (assert_equal , assert_true , assert_almost_equal ,
5- skipif , utils )
6- from .....interfaces import fsl , IdentityInterface , utility
7- from .....pipeline .engine import Node , Workflow
8-
9- from ..resting import create_resting_preproc
10-
114import unittest
12- import mock
13- from mock import MagicMock
14- import nibabel as nb
15- import numpy as np
165import os
176import tempfile
187import shutil
198
20- all_fields = ['func' , 'in_file' , 'slice_time_corrected_file' , 'stddev_file' ,
9+ import mock
10+ import numpy as np
11+
12+ from .....testing import (assert_equal , assert_true , utils )
13+ from .....interfaces import IdentityInterface
14+ from .....pipeline .engine import Node , Workflow
15+
16+ from ..resting import create_resting_preproc
17+
18+ ALL_FIELDS = ['func' , 'in_file' , 'slice_time_corrected_file' , 'stddev_file' ,
2119 'out_stat' , 'thresh' , 'num_noise_components' , 'detrended_file' ,
2220 'design_file' , 'highpass_sigma' , 'lowpass_sigma' , 'out_file' ,
2321 'noise_mask_file' , 'filtered_file' ]
@@ -29,16 +27,16 @@ def stub_node_factory(*args, **kwargs):
2927 if name == 'compcor' :
3028 return Node (* args , ** kwargs )
3129 else : # replace with an IdentityInterface
32- return Node (IdentityInterface (fields = all_fields ),
30+ return Node (IdentityInterface (fields = ALL_FIELDS ),
3331 name = name )
3432
3533def stub_wf (* args , ** kwargs ):
36- wf = Workflow (name = 'realigner' )
34+ wflow = Workflow (name = 'realigner' )
3735 inputnode = Node (IdentityInterface (fields = ['func' ]), name = 'inputspec' )
3836 outputnode = Node (interface = IdentityInterface (fields = ['realigned_file' ]),
3937 name = 'outputspec' )
40- wf .connect (inputnode , 'func' , outputnode , 'realigned_file' )
41- return wf
38+ wflow .connect (inputnode , 'func' , outputnode , 'realigned_file' )
39+ return wflow
4240
4341class TestResting (unittest .TestCase ):
4442
@@ -66,23 +64,23 @@ def setUp(self):
6664 mask = np .zeros (self .fake_data .shape [:3 ])
6765 for i in range (mask .shape [0 ]):
6866 for j in range (mask .shape [1 ]):
69- if i == j :
70- mask [i ,j ] = 1
67+ if i == j :
68+ mask [i , j ] = 1
7169 utils .save_toy_nii (mask , self .in_filenames ['mask_file' ])
7270
7371 @mock .patch ('nipype.workflows.rsfmri.fsl.resting.create_realign_flow' ,
7472 side_effect = stub_wf )
7573 @mock .patch ('nipype.pipeline.engine.Node' , side_effect = stub_node_factory )
76- def test_create_resting_preproc (self , mock_Node , mock_realign_wf ):
77- wf = create_resting_preproc (base_dir = os .getcwd ())
74+ def test_create_resting_preproc (self , mock_node , mock_realign_wf ):
75+ wflow = create_resting_preproc (base_dir = os .getcwd ())
7876
79- wf .inputs .inputspec .num_noise_components = self .num_noise_components
80- mask_in = wf .get_node ('threshold' ).inputs
77+ wflow .inputs .inputspec .num_noise_components = self .num_noise_components
78+ mask_in = wflow .get_node ('threshold' ).inputs
8179 mask_in .out_file = self .in_filenames ['mask_file' ]
82- func_in = wf .get_node ('slicetimer' ).inputs
80+ func_in = wflow .get_node ('slicetimer' ).inputs
8381 func_in .slice_time_corrected_file = self .in_filenames ['realigned_file' ]
8482
85- wf .run ()
83+ wflow .run ()
8684
8785 # assert
8886 expected_file = os .path .abspath (self .out_filenames ['components_file' ])
@@ -91,7 +89,7 @@ def test_create_resting_preproc(self, mock_Node, mock_realign_wf):
9189 num_got_components = len (components_data )
9290 assert_true (num_got_components == self .num_noise_components
9391 or num_got_components == self .fake_data .shape [3 ])
94- first_two = [row [:2 ] for row in components_data ]
92+ first_two = [row [:2 ] for row in components_data [ 1 :] ]
9593 assert_equal (first_two , [['-0.5172356654' , '-0.6973053243' ],
9694 ['0.2574722644' , '0.1645270737' ],
9795 ['-0.0806469590' , '0.5156853779' ],
0 commit comments