@@ -345,7 +345,7 @@ def __init__(self, *args, **kwargs):
345
345
CountingImageOpener .numOpeners += 1
346
346
347
347
348
- def test_keep_file_open_true_false ():
348
+ def test_keep_file_open_true_false_invalid ():
349
349
# Test the behaviour of the keep_file_open __init__ flag, when it is set to
350
350
# True or False.
351
351
CountingImageOpener .numOpeners = 0
@@ -360,7 +360,8 @@ def test_keep_file_open_true_false():
360
360
# handle, and that ArrayProxy(keep_file_open=False) creates a file
361
361
# handle on every data access.
362
362
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 )
364
365
assert not proxy_no_kfp ._keep_file_open
365
366
for i in range (voxels .shape [0 ]):
366
367
x , y , z = [int (c ) for c in voxels [i , :]]
@@ -388,13 +389,24 @@ def test_keep_file_open_true_false():
388
389
assert not fobj .closed
389
390
proxy_kfp = ArrayProxy (fobj , ((10 , 10 , 10 ), dtype ),
390
391
keep_file_open = True )
391
- assert not proxy_kfp ._keep_file_open
392
+ assert proxy_kfp ._keep_file_open
392
393
for i in range (voxels .shape [0 ]):
393
394
assert proxy_kfp [x , y , z ] == x * 100 + y * 10 + z
394
395
assert not fobj .closed
395
396
del proxy_kfp
396
397
proxy_kfp = None
397
398
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' )
398
410
399
411
400
412
def test_keep_file_open_default ():
0 commit comments