Skip to content

Commit 0573f20

Browse files
committed
Merge pull request #63 from matthew-brett/mgh-windows-fixes
BF - delete images after read for windows tests
2 parents 161c941 + 8ed81b0 commit 0573f20

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

nibabel/freesurfer/tests/test_mghformat.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import numpy as np
1313
from .. import load, save, MGHImage
1414
from ..mghformat import MGHError
15-
from ...tmpdirs import TemporaryDirectory
15+
from ...tmpdirs import InTemporaryDirectory
1616
from ...testing import data_path
1717
from numpy.testing import assert_equal, assert_array_equal, \
1818
assert_array_almost_equal, assert_almost_equal, assert_raises
@@ -52,23 +52,23 @@ def test_write_mgh():
5252
v = v.reshape((5, 4, 3, 2)).astype(np.float32)
5353
# form a MGHImage object using data and vox2ras matrix
5454
img = MGHImage(v, v2r)
55-
with TemporaryDirectory() as tmpdir:
56-
save(img, os.path.join(tmpdir, 'tmpsave.mgz'))
55+
with InTemporaryDirectory():
56+
save(img, 'tmpsave.mgz')
5757
# read from the tmp file and see if it checks out
58-
mgz = load(os.path.join(tmpdir, 'tmpsave.mgz'))
59-
58+
mgz = load('tmpsave.mgz')
59+
h = mgz.get_header()
60+
dat = mgz.get_data()
61+
# Delete loaded image to allow file deletion by windows
62+
del mgz
6063
# header
61-
h = mgz.get_header()
6264
assert_equal(h['version'], 1)
6365
assert_equal(h['type'], 3)
6466
assert_equal(h['dof'], 0)
6567
assert_equal(h['goodRASFlag'], 1)
6668
assert_array_equal(h['dims'], [5, 4, 3, 2])
6769
assert_array_almost_equal(h['mrparms'], [0.0, 0.0, 0.0, 0.0])
6870
assert_array_almost_equal(h.get_vox2ras(), v2r)
69-
7071
# data
71-
dat = mgz.get_data()
7272
assert_almost_equal(dat, v, 7)
7373

7474

@@ -79,20 +79,20 @@ def test_write_noaffine_mgh():
7979
# form a MGHImage object using data
8080
# and the default affine matrix (Note the "None")
8181
img = MGHImage(v, None)
82-
with TemporaryDirectory() as tmpdir:
83-
save(img, os.path.join(tmpdir, 'tmpsave.mgz'))
82+
with InTemporaryDirectory():
83+
save(img, 'tmpsave.mgz')
8484
# read from the tmp file and see if it checks out
85-
mgz = load(os.path.join(tmpdir, 'tmpsave.mgz'))
86-
85+
mgz = load('tmpsave.mgz')
86+
h = mgz.get_header()
87+
# Delete loaded image to allow file deletion by windows
88+
del mgz
8789
# header
88-
h = mgz.get_header()
8990
assert_equal(h['version'], 1)
9091
assert_equal(h['type'], 0) # uint8 for mgh
9192
assert_equal(h['dof'], 0)
9293
assert_equal(h['goodRASFlag'], 1)
9394
assert_array_equal(h['dims'], [7, 13, 3, 22])
9495
assert_array_almost_equal(h['mrparms'], [0.0, 0.0, 0.0, 0.0])
95-
9696
# important part -- whether default affine info is stored
9797
ex_mdc = np.array([[-1, 0, 0],
9898
[0, 0, -1],

0 commit comments

Comments
 (0)