Skip to content

Commit ece6a15

Browse files
committed
ENH: improved use of InTemporaryDirectory
1 parent 1d5e5e5 commit ece6a15

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

nipy/labs/spatial_models/tests/test_parcel_io.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from os.path import join, exists
1+
from os.path import exists
22
import numpy as np
33
from nibabel import Nifti1Image, save
44
from numpy.testing import assert_equal
@@ -43,14 +43,13 @@ def test_parcel_intra_from_3d_image():
4343
shape = (10, 10, 10)
4444
n_parcel, nn, mu = 10, 6, 1.
4545
mask_image = Nifti1Image(np.ones(shape), np.eye(4))
46-
dir_context = InTemporaryDirectory()
47-
with dir_context:
46+
with InTemporaryDirectory() as dir_context:
4847
surrogate_3d_dataset(mask=mask_image, out_image_file='image.nii')
4948

5049
#run the algo
5150
for method in ['ward', 'kmeans', 'gkm']:
5251
osp = fixed_parcellation(mask_image, ['image.nii'], n_parcel, nn,
53-
method, dir_context.name, mu)
52+
method, dir_context, mu)
5453
result = 'parcel_%s.nii' % method
5554
assert exists(result)
5655
assert_equal(osp.k, n_parcel)
@@ -65,15 +64,14 @@ def test_parcel_intra_from_3d_images_list():
6564
method = 'ward'
6665
mask_image = Nifti1Image(np.ones(shape), np.eye(4))
6766

68-
dir_context = InTemporaryDirectory()
69-
with dir_context:
67+
with InTemporaryDirectory() as dir_context:
7068
data_image = ['image_%d.nii' % i for i in range(5)]
7169
for datim in data_image:
7270
surrogate_3d_dataset(mask=mask_image, out_image_file=datim)
7371

7472
#run the algo
7573
osp = fixed_parcellation(mask_image, data_image, n_parcel, nn,
76-
method, dir_context.name, mu)
74+
method, dir_context, mu)
7775
assert exists('parcel_%s.nii' % method)
7876
assert_equal(osp.k, n_parcel)
7977

@@ -86,12 +84,11 @@ def test_parcel_intra_from_4d_image():
8684
n_parcel, nn, mu = 10, 6, 1.
8785
method = 'ward'
8886
mask_image = Nifti1Image(np.ones(shape), np.eye(4))
89-
dir_context = InTemporaryDirectory()
90-
with dir_context:
87+
with InTemporaryDirectory() as dir_context:
9188
surrogate_3d_dataset(n_subj=10, mask=mask_image,
9289
out_image_file='image.nii')
9390
osp = fixed_parcellation(mask_image, ['image.nii'], n_parcel, nn,
94-
method, dir_context.name, mu)
91+
method, dir_context, mu)
9592
assert exists('parcel_%s.nii' % method)
9693
assert_equal(osp.k, n_parcel)
9794

0 commit comments

Comments
 (0)