@@ -345,7 +345,7 @@ def __init__(self, *args, **kwargs):
345345 CountingImageOpener .numOpeners += 1
346346
347347
348- def test_keep_file_open_true_false ():
348+ def test_keep_file_open_true_false_invalid ():
349349 # Test the behaviour of the keep_file_open __init__ flag, when it is set to
350350 # True or False.
351351 CountingImageOpener .numOpeners = 0
@@ -360,7 +360,8 @@ def test_keep_file_open_true_false():
360360 # handle, and that ArrayProxy(keep_file_open=False) creates a file
361361 # handle on every data access.
362362 with mock .patch ('nibabel.arrayproxy.ImageOpener' , CountingImageOpener ):
363- proxy_no_kfp = ArrayProxy (fname , ((10 , 10 , 10 ), dtype ))
363+ proxy_no_kfp = ArrayProxy (fname , ((10 , 10 , 10 ), dtype ),
364+ keep_file_open = False )
364365 assert not proxy_no_kfp ._keep_file_open
365366 for i in range (voxels .shape [0 ]):
366367 x , y , z = [int (c ) for c in voxels [i , :]]
@@ -388,13 +389,24 @@ def test_keep_file_open_true_false():
388389 assert not fobj .closed
389390 proxy_kfp = ArrayProxy (fobj , ((10 , 10 , 10 ), dtype ),
390391 keep_file_open = True )
391- assert not proxy_kfp ._keep_file_open
392+ assert proxy_kfp ._keep_file_open
392393 for i in range (voxels .shape [0 ]):
393394 assert proxy_kfp [x , y , z ] == x * 100 + y * 10 + z
394395 assert not fobj .closed
395396 del proxy_kfp
396397 proxy_kfp = None
397398 assert not fobj .closed
399+ # Test invalid values of keep_file_open
400+ with assert_raises (ValueError ):
401+ ArrayProxy (fname , ((10 , 10 , 10 ), dtype ), keep_file_open = 0 )
402+ with assert_raises (ValueError ):
403+ ArrayProxy (fname , ((10 , 10 , 10 ), dtype ), keep_file_open = 1 )
404+ with assert_raises (ValueError ):
405+ ArrayProxy (fname , ((10 , 10 , 10 ), dtype ), keep_file_open = 55 )
406+ with assert_raises (ValueError ):
407+ ArrayProxy (fname , ((10 , 10 , 10 ), dtype ), keep_file_open = 'autob' )
408+ with assert_raises (ValueError ):
409+ ArrayProxy (fname , ((10 , 10 , 10 ), dtype ), keep_file_open = 'cauto' )
398410
399411
400412def test_keep_file_open_default ():
0 commit comments