tests/extmod/vfs_fat_fileio1: Add test for calling file obj finaliser.

This commit is contained in:
Damien George 2018-02-28 15:27:51 +11:00
parent 09be031e04
commit 90e719a232
2 changed files with 18 additions and 0 deletions

View File

@ -125,3 +125,17 @@ try:
except MemoryError: except MemoryError:
print('MemoryError') print('MemoryError')
micropython.heap_unlock() micropython.heap_unlock()
# Here we test that the finaliser is actually called during a garbage collection.
import gc
N = 4
for i in range(N):
n = 'x%d' % i
f = vfs.open(n, 'w')
f.write(n)
f = None # release f without closing
[0, 1, 2, 3] # use up Python stack so f is really gone
gc.collect() # should finalise all N files by closing them
for i in range(N):
with vfs.open('x%d' % i, 'r') as f:
print(f.read())

View File

@ -12,3 +12,7 @@ d
True True
[('foo_dir', 16384, 0)] [('foo_dir', 16384, 0)]
MemoryError MemoryError
x0
x1
x2
x3