@@ -402,21 +402,23 @@ def test_keep_file_open_default():
402402 # its default value
403403 dtype = np .float32
404404 data = np .arange (1000 , dtype = dtype ).reshape ((10 , 10 , 10 ))
405- voxels = np .random .randint (0 , 10 , (10 , 3 ))
406- mockmod = mock .MagicMock ()
407405 with InTemporaryDirectory ():
408406 fname = 'testdata.gz'
409407 with gzip .open (fname , 'wb' ) as fobj :
410408 fobj .write (data .tostring (order = 'F' ))
411409 # 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 ):
414414 proxy = ArrayProxy (fname , ((10 , 10 , 10 ), dtype ))
415415 assert proxy ._keep_file_open
416416 proxy = ArrayProxy (fname , ((10 , 10 , 10 ), dtype ), keep_file_open = 'auto' )
417417 assert proxy ._keep_file_open
418418 # 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 ):
420422 proxy = ArrayProxy (fname , ((10 , 10 , 10 ), dtype ))
421423 assert not proxy ._keep_file_open
422424 proxy = ArrayProxy (fname , ((10 , 10 , 10 ), dtype ), keep_file_open = 'auto' )
0 commit comments