summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/extmod/vfs_fat_fileio1.py14
-rw-r--r--tests/extmod/vfs_fat_fileio1.py.exp4
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/extmod/vfs_fat_fileio1.py b/tests/extmod/vfs_fat_fileio1.py
index 8c8ec5747..f1f4639ab 100644
--- a/tests/extmod/vfs_fat_fileio1.py
+++ b/tests/extmod/vfs_fat_fileio1.py
@@ -125,3 +125,17 @@ try:
except MemoryError:
print('MemoryError')
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())
diff --git a/tests/extmod/vfs_fat_fileio1.py.exp b/tests/extmod/vfs_fat_fileio1.py.exp
index a304c75d9..2d4792aa3 100644
--- a/tests/extmod/vfs_fat_fileio1.py.exp
+++ b/tests/extmod/vfs_fat_fileio1.py.exp
@@ -12,3 +12,7 @@ d
True
[('foo_dir', 16384, 0)]
MemoryError
+x0
+x1
+x2
+x3