@@ -427,15 +427,22 @@ def test_keep_file_open_true_false_invalid():
427
427
else :
428
428
with open (fname , 'wb' ) as fobj :
429
429
fobj .write (data .tostring (order = 'F' ))
430
+ # pass in a file name or open file handle. If the latter, we open
431
+ # two file handles, because we're going to create two proxies
432
+ # below.
430
433
if filetype == 'open' :
431
- fname = open (fname , 'rb' )
434
+ fobj1 = open (fname , 'rb' )
435
+ fobj2 = open (fname , 'rb' )
436
+ else :
437
+ fobj1 = fname
438
+ fobj2 = fname
432
439
try :
433
- proxy = ArrayProxy (fname , ((10 , 10 , 10 ), dtype ),
440
+ proxy = ArrayProxy (fobj1 , ((10 , 10 , 10 ), dtype ),
434
441
keep_file_open = kfo )
435
442
# We also test that we get the same behaviour when the
436
443
# KEEP_FILE_OPEN_DEFAULT flag is changed
437
444
with patch_keep_file_open_default (kfo ):
438
- proxy_def = ArrayProxy (fname , ((10 , 10 , 10 ), dtype ))
445
+ proxy_def = ArrayProxy (fobj2 , ((10 , 10 , 10 ), dtype ))
439
446
# check internal flags
440
447
assert proxy ._persist_opener == exp_persist
441
448
assert proxy ._keep_file_open == exp_kfo
@@ -458,13 +465,17 @@ def test_keep_file_open_true_false_invalid():
458
465
# if we were using an open file handle, check that the proxy
459
466
# didn't close it
460
467
if filetype == 'open' :
461
- assert not fname .closed
468
+ assert not fobj1 .closed
469
+ assert not fobj2 .closed
462
470
except Exception :
463
471
print ('Failed test' , test )
464
472
raise
465
473
finally :
474
+ del proxy
475
+ del proxy_def
466
476
if filetype == 'open' :
467
- fname .close ()
477
+ fobj1 .close ()
478
+ fobj2 .close ()
468
479
# Test invalid values of keep_file_open
469
480
print ('testinv' )
470
481
with InTemporaryDirectory ():
0 commit comments