diff options
Diffstat (limited to 'tests/extmod/vfs_lfs_file.py')
-rw-r--r-- | tests/extmod/vfs_lfs_file.py | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/tests/extmod/vfs_lfs_file.py b/tests/extmod/vfs_lfs_file.py index 477a62e2f..774cca296 100644 --- a/tests/extmod/vfs_lfs_file.py +++ b/tests/extmod/vfs_lfs_file.py @@ -2,12 +2,14 @@ try: import uos + uos.VfsLfs1 uos.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit + class RAMBlockDevice: ERASE_BLOCK_SIZE = 1024 @@ -25,15 +27,16 @@ class RAMBlockDevice: self.data[addr + i] = buf[i] def ioctl(self, op, arg): - if op == 4: # block count + if op == 4: # block count return len(self.data) // self.ERASE_BLOCK_SIZE - if op == 5: # block size + if op == 5: # block size return self.ERASE_BLOCK_SIZE - if op == 6: # erase block + if op == 6: # erase block return 0 + def test(bdev, vfs_class): - print('test', vfs_class) + print("test", vfs_class) # mkfs vfs_class.mkfs(bdev) @@ -42,57 +45,57 @@ def test(bdev, vfs_class): vfs = vfs_class(bdev) # create text, print, write, close - f = vfs.open('test.txt', 'wt') + f = vfs.open("test.txt", "wt") print(f) - f.write('littlefs') + f.write("littlefs") f.close() # close already-closed file f.close() # create binary, print, write, flush, close - f = vfs.open('test.bin', 'wb') + f = vfs.open("test.bin", "wb") print(f) - f.write('littlefs') + f.write("littlefs") f.flush() f.close() # create for append - f = vfs.open('test.bin', 'ab') - f.write('more') + f = vfs.open("test.bin", "ab") + f.write("more") f.close() # create exclusive - f = vfs.open('test2.bin', 'xb') + f = vfs.open("test2.bin", "xb") f.close() # create exclusive with error try: - vfs.open('test2.bin', 'x') + vfs.open("test2.bin", "x") except OSError: - print('open OSError') + print("open OSError") # read default - with vfs.open('test.txt', '') as f: + with vfs.open("test.txt", "") as f: print(f.read()) # read text - with vfs.open('test.txt', 'rt') as f: + with vfs.open("test.txt", "rt") as f: print(f.read()) # read binary - with vfs.open('test.bin', 'rb') as f: + with vfs.open("test.bin", "rb") as f: print(f.read()) # create read and write - with vfs.open('test.bin', 'r+b') as f: + with vfs.open("test.bin", "r+b") as f: print(f.read(8)) - f.write('MORE') - with vfs.open('test.bin', 'rb') as f: + f.write("MORE") + with vfs.open("test.bin", "rb") as f: print(f.read()) # seek and tell - f = vfs.open('test.txt', 'r') + f = vfs.open("test.txt", "r") print(f.tell()) f.seek(3, 0) print(f.tell()) @@ -100,18 +103,19 @@ def test(bdev, vfs_class): # open nonexistent try: - vfs.open('noexist', 'r') + vfs.open("noexist", "r") except OSError: - print('open OSError') + print("open OSError") # open multiple files at the same time - f1 = vfs.open('test.txt', '') - f2 = vfs.open('test.bin', 'b') + f1 = vfs.open("test.txt", "") + f2 = vfs.open("test.bin", "b") print(f1.read()) print(f2.read()) f1.close() f2.close() + bdev = RAMBlockDevice(30) test(bdev, uos.VfsLfs1) test(bdev, uos.VfsLfs2) |