3131
3232from  ..interfaces .confounds  import  ExpandModel , SpikeRegressors 
3333from  ..interfaces .plotting  import  CompCorVariancePlot , ConfoundsCorrelationPlot 
34- from  .conftest  import  datadir 
3534
3635
3736def  _smoke_test_report (report_interface , artifact_name ):
@@ -43,7 +42,7 @@ def _smoke_test_report(report_interface, artifact_name):
4342    assert  os .path .isfile (out_report ), f'Report "{ out_report }  " does not exist' 
4443
4544
46- def  _expand_test (model_formula ):
45+ def  _expand_test (model_formula ,  datadir ):
4746    orig_data_file  =  os .path .join (datadir , 'confounds_test.tsv' )
4847    exp_data_file  =  (
4948        pe .Node (
@@ -56,7 +55,7 @@ def _expand_test(model_formula):
5655    return  pd .read_csv (exp_data_file , sep = '\t ' )
5756
5857
59- def  _spikes_test (lags = None , mincontig = None , fmt = 'mask' ):
58+ def  _spikes_test (lags = None , mincontig = None , fmt = 'mask' ,  * ,  datadir ):
6059    orig_data_file  =  os .path .join (datadir , 'spikes_test.tsv' )
6160    lags  =  lags  or  [0 ]
6261    spk_data_file  =  (
@@ -78,7 +77,7 @@ def _spikes_test(lags=None, mincontig=None, fmt='mask'):
7877    return  pd .read_csv (spk_data_file , sep = '\t ' )
7978
8079
81- def  test_expansion_variable_selection ():
80+ def  test_expansion_variable_selection (datadir ):
8281    """Test model expansion: simple variable selection""" 
8382    model_formula  =  'a + b + c + d' 
8483    expected_data  =  pd .DataFrame (
@@ -89,11 +88,11 @@ def test_expansion_variable_selection():
8988            'd' : [9 , 7 , 5 , 3 , 1 ],
9089        }
9190    )
92-     exp_data  =  _expand_test (model_formula )
91+     exp_data  =  _expand_test (model_formula ,  datadir )
9392    pd .testing .assert_frame_equal (exp_data , expected_data )
9493
9594
96- def  test_expansion_derivatives_and_powers ():
95+ def  test_expansion_derivatives_and_powers (datadir ):
9796    """Temporal derivatives and quadratics""" 
9897    model_formula  =  '(dd1(a) + d1(b))^^2 + d1-2((c)^2) + d + others' 
9998    # b_derivative1_power2 is dropped as an exact duplicate of b_derivative1 
@@ -112,13 +111,13 @@ def test_expansion_derivatives_and_powers():
112111            'f' : [np .nan , 6 , 4 , 2 , 0 ],
113112        }
114113    )
115-     exp_data  =  _expand_test (model_formula )
114+     exp_data  =  _expand_test (model_formula ,  datadir )
116115    assert  set (exp_data .columns ) ==  set (expected_data .columns )
117116    for  col  in  expected_data .columns :
118117        pd .testing .assert_series_equal (expected_data [col ], exp_data [col ], check_dtype = False )
119118
120119
121- def  test_expansion_na_robustness ():
120+ def  test_expansion_na_robustness (datadir ):
122121    """NA robustness""" 
123122    model_formula  =  '(dd1(f))^^2' 
124123    expected_data  =  pd .DataFrame (
@@ -129,16 +128,16 @@ def test_expansion_na_robustness():
129128            'f_derivative1_power2' : [np .nan , np .nan , 4 , 4 , 4 ],
130129        }
131130    )
132-     exp_data  =  _expand_test (model_formula )
131+     exp_data  =  _expand_test (model_formula ,  datadir )
133132    assert  set (exp_data .columns ) ==  set (expected_data .columns )
134133    for  col  in  expected_data .columns :
135134        pd .testing .assert_series_equal (expected_data [col ], exp_data [col ], check_dtype = False )
136135
137136
138- def  test_spikes ():
137+ def  test_spikes (datadir ):
139138    """Test outlier flagging""" 
140139    outliers  =  [1 , 1 , 0 , 0 , 1 ]
141-     spk_data  =  _spikes_test ()
140+     spk_data  =  _spikes_test (datadir = datadir )
142141    assert  np .all (np .isclose (outliers , spk_data ['motion_outlier' ]))
143142
144143    outliers_spikes  =  pd .DataFrame (
@@ -148,30 +147,30 @@ def test_spikes():
148147            'motion_outlier02' : [0 , 0 , 0 , 0 , 1 ],
149148        }
150149    )
151-     spk_data  =  _spikes_test (fmt = 'spikes' )
150+     spk_data  =  _spikes_test (fmt = 'spikes' ,  datadir = datadir )
152151    assert  set (spk_data .columns ) ==  set (outliers_spikes .columns )
153152    for  col  in  outliers_spikes .columns :
154153        assert  np .all (np .isclose (outliers_spikes [col ], spk_data [col ]))
155154
156155    lags  =  [0 , 1 ]
157156    outliers_lags  =  [1 , 1 , 1 , 0 , 1 ]
158-     spk_data  =  _spikes_test (lags = lags )
157+     spk_data  =  _spikes_test (lags = lags ,  datadir = datadir )
159158    assert  np .all (np .isclose (outliers_lags , spk_data ['motion_outlier' ]))
160159
161160    mincontig  =  2 
162161    outliers_mc  =  [1 , 1 , 1 , 1 , 1 ]
163-     spk_data  =  _spikes_test (lags = lags , mincontig = mincontig )
162+     spk_data  =  _spikes_test (lags = lags , mincontig = mincontig ,  datadir = datadir )
164163    assert  np .all (np .isclose (outliers_mc , spk_data ['motion_outlier' ]))
165164
166165
167- def  test_CompCorVariancePlot ():
166+ def  test_CompCorVariancePlot (datadir ):
168167    """CompCor variance report test""" 
169168    metadata_file  =  os .path .join (datadir , 'confounds_metadata_test.tsv' )
170169    cc_rpt  =  CompCorVariancePlot (metadata_files = [metadata_file ], metadata_sources = ['aCompCor' ])
171170    _smoke_test_report (cc_rpt , 'compcor_variance.svg' )
172171
173172
174- def  test_ConfoundsCorrelationPlot ():
173+ def  test_ConfoundsCorrelationPlot (datadir ):
175174    """confounds correlation report test""" 
176175    confounds_file  =  os .path .join (datadir , 'confounds_test.tsv' )
177176    cc_rpt  =  ConfoundsCorrelationPlot (
@@ -182,7 +181,7 @@ def test_ConfoundsCorrelationPlot():
182181    _smoke_test_report (cc_rpt , 'confounds_correlation.svg' )
183182
184183
185- def  test_ConfoundsCorrelationPlotColumns ():
184+ def  test_ConfoundsCorrelationPlotColumns (datadir ):
186185    """confounds correlation report test""" 
187186    confounds_file  =  os .path .join (datadir , 'confounds_test.tsv' )
188187    cc_rpt  =  ConfoundsCorrelationPlot (
0 commit comments