summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-02-28 15:27:51 +1100
committerDamien George <damien.p.george@gmail.com>2018-02-28 15:27:51 +1100
commit90e719a232dbf4039085d4fea2faf1358e408e40 (patch)
treea3e1146aa6a535e743bce31943708c67ca955583
parent09be031e047f0e7ba77620c29c5abbdbd5e3d055 (diff)
tests/extmod/vfs_fat_fileio1: Add test for calling file obj finaliser.
-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