diff options
Diffstat (limited to 'tests/extmod/vfs_fat_finaliser.py')
-rw-r--r-- | tests/extmod/vfs_fat_finaliser.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/tests/extmod/vfs_fat_finaliser.py b/tests/extmod/vfs_fat_finaliser.py index c7254c5f0..e30f42f84 100644 --- a/tests/extmod/vfs_fat_finaliser.py +++ b/tests/extmod/vfs_fat_finaliser.py @@ -2,6 +2,7 @@ try: import uerrno, uos + uos.VfsFat except (ImportError, AttributeError): print("SKIP") @@ -22,9 +23,9 @@ class RAMBlockDevice: self.data[n * self.sec_size + i] = buf[i] def ioctl(self, op, arg): - if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT + if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT return len(self.data) // self.sec_size - if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE + if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE return self.sec_size @@ -44,23 +45,25 @@ vfs = uos.VfsFat(bdev) # finaliser is a different path to normal allocation. It would be better to # test this in the core tests but there are no core objects that use finaliser. import micropython + micropython.heap_lock() try: - vfs.open('x', 'r') + vfs.open("x", "r") except MemoryError: - print('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') + 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 + 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: + with vfs.open("x%d" % i, "r") as f: print(f.read()) |