Skip to content

Commit 559f93e

Browse files
committed
TEST: Check keep_file_open="auto"
1 parent 166162c commit 559f93e

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

nibabel/tests/test_arrayproxy.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -384,24 +384,18 @@ def test_keep_file_open_true_false_invalid():
384384
# Test that the keep_file_open flag has no effect if an open file
385385
# handle is passed in
386386
with open(fname, 'rb') as fobj:
387-
proxy_no_kfp = ArrayProxy(fobj, ((10, 10, 10), dtype),
388-
keep_file_open=False)
389-
assert not proxy_no_kfp._keep_file_open
390-
for i in range(voxels.shape[0]):
391-
assert proxy_no_kfp[x, y, z] == x * 100 + y * 10 + z
392-
assert not fobj.closed
393-
del proxy_no_kfp
394-
proxy_no_kfp = None
395-
assert not fobj.closed
396-
proxy_kfp = ArrayProxy(fobj, ((10, 10, 10), dtype),
397-
keep_file_open=True)
398-
assert proxy_kfp._keep_file_open
399-
for i in range(voxels.shape[0]):
400-
assert proxy_kfp[x, y, z] == x * 100 + y * 10 + z
387+
for kfo in (True, False, 'auto'):
388+
proxy = ArrayProxy(fobj, ((10, 10, 10), dtype),
389+
keep_file_open=kfo)
390+
if kfo == 'auto':
391+
kfo = False
392+
assert proxy._keep_file_open is kfo
393+
for i in range(voxels.shape[0]):
394+
assert proxy[x, y, z] == x * 100 + y * 10 + z
395+
assert not fobj.closed
396+
del proxy
401397
assert not fobj.closed
402-
del proxy_kfp
403-
proxy_kfp = None
404-
assert not fobj.closed
398+
assert fobj.closed
405399
# Test invalid values of keep_file_open
406400
with assert_raises(ValueError):
407401
ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open=0)

0 commit comments

Comments
 (0)