@@ -402,21 +402,23 @@ def test_keep_file_open_default():
402
402
# its default value
403
403
dtype = np .float32
404
404
data = np .arange (1000 , dtype = dtype ).reshape ((10 , 10 , 10 ))
405
- voxels = np .random .randint (0 , 10 , (10 , 3 ))
406
- mockmod = mock .MagicMock ()
407
405
with InTemporaryDirectory ():
408
406
fname = 'testdata.gz'
409
407
with gzip .open (fname , 'wb' ) as fobj :
410
408
fobj .write (data .tostring (order = 'F' ))
411
409
# If have_indexed_gzip, then keep_file_open should be True
412
- with mock .patch .dict ('sys.modules' , {'indexed_gzip' : mockmod }), \
413
- mock .patch ('indexed_gzip.SafeIndexedGzipFile' , gzip .GzipFile ):
410
+ with mock .patch ('nibabel.openers.HAVE_INDEXED_GZIP' , True ), \
411
+ mock .patch ('nibabel.arrayproxy.HAVE_INDEXED_GZIP' , True ), \
412
+ mock .patch ('nibabel.openers.SafeIndexedGzipFile' , gzip .GzipFile ,
413
+ create = True ):
414
414
proxy = ArrayProxy (fname , ((10 , 10 , 10 ), dtype ))
415
415
assert proxy ._keep_file_open
416
416
proxy = ArrayProxy (fname , ((10 , 10 , 10 ), dtype ), keep_file_open = 'auto' )
417
417
assert proxy ._keep_file_open
418
418
# If no have_indexed_gzip, then keep_file_open should be False
419
- with mock .patch .dict ('sys.modules' , {'indexed_gzip' : None }):
419
+ with mock .patch ('nibabel.openers.HAVE_INDEXED_GZIP' , False ), \
420
+ mock .patch ('nibabel.arrayproxy.HAVE_INDEXED_GZIP' , False ), \
421
+ mock .patch ('nibabel.openers.SafeIndexedGzipFile' , None , create = True ):
420
422
proxy = ArrayProxy (fname , ((10 , 10 , 10 ), dtype ))
421
423
assert not proxy ._keep_file_open
422
424
proxy = ArrayProxy (fname , ((10 , 10 , 10 ), dtype ), keep_file_open = 'auto' )
0 commit comments