tests: Use vfs module instead of os.

Signed-off-by: Damien George <damien@micropython.org>
pull/13584/head
Damien George 2023-11-20 23:04:55 +11:00
rodzic 5804aa0204
commit b87bbaeb43
34 zmienionych plików z 419 dodań i 468 usunięć

Wyświetl plik

@ -1,10 +1,8 @@
# test VFS functionality without any particular filesystem type
try:
import os
os.mount
except (ImportError, AttributeError):
import os, vfs
except ImportError:
print("SKIP")
raise SystemExit
@ -59,11 +57,11 @@ class Filesystem:
# first we umount any existing mount points the target may have
try:
os.umount("/")
vfs.umount("/")
except OSError:
pass
for path in os.listdir("/"):
os.umount("/" + path)
vfs.umount("/" + path)
# stat root dir
print(os.stat("/"))
@ -83,7 +81,7 @@ for func in ("chdir", "listdir", "mkdir", "remove", "rmdir", "stat"):
print(func, arg, "OSError")
# basic mounting and listdir
os.mount(Filesystem(1), "/test_mnt")
vfs.mount(Filesystem(1), "/test_mnt")
print(os.listdir())
# ilistdir
@ -103,13 +101,13 @@ print(os.listdir("test_mnt"))
print(os.listdir("/test_mnt"))
# mounting another filesystem
os.mount(Filesystem(2), "/test_mnt2", readonly=True)
vfs.mount(Filesystem(2), "/test_mnt2", readonly=True)
print(os.listdir())
print(os.listdir("/test_mnt2"))
# mounting over an existing mount point
try:
os.mount(Filesystem(3), "/test_mnt2")
vfs.mount(Filesystem(3), "/test_mnt2")
except OSError:
print("OSError")
@ -139,23 +137,23 @@ open("test_file")
open("test_file", "wb")
# umount
os.umount("/test_mnt")
os.umount("/test_mnt2")
vfs.umount("/test_mnt")
vfs.umount("/test_mnt2")
# umount a non-existent mount point
try:
os.umount("/test_mnt")
vfs.umount("/test_mnt")
except OSError:
print("OSError")
# root dir
os.mount(Filesystem(3), "/")
vfs.mount(Filesystem(3), "/")
print(os.stat("/"))
print(os.statvfs("/"))
print(os.listdir())
open("test")
os.mount(Filesystem(4), "/mnt")
vfs.mount(Filesystem(4), "/mnt")
print(os.listdir())
print(os.listdir("/mnt"))
os.chdir("/mnt")
@ -166,9 +164,9 @@ os.chdir("/subdir")
print(os.listdir())
os.chdir("/")
os.umount("/")
vfs.umount("/")
print(os.listdir("/"))
os.umount("/mnt")
vfs.umount("/mnt")
# chdir to a non-existent mount point (current directory should remain unchanged)
try:
@ -178,7 +176,7 @@ except OSError:
print(os.getcwd())
# chdir to a non-existent subdirectory in a mounted filesystem
os.mount(Filesystem(5, 1), "/mnt")
vfs.mount(Filesystem(5, 1), "/mnt")
try:
os.chdir("/mnt/subdir")
except OSError:

Wyświetl plik

@ -1,10 +1,10 @@
# Test for behaviour of combined standard and extended block device
try:
import os
import vfs
os.VfsFat
os.VfsLfs2
vfs.VfsFat
vfs.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -65,12 +65,10 @@ def test(bdev, vfs_class):
try:
import os
bdev = RAMBlockDevice(50)
except MemoryError:
print("SKIP")
raise SystemExit
test(bdev, os.VfsFat)
test(bdev, os.VfsLfs2)
test(bdev, vfs.VfsFat)
test(bdev, vfs.VfsLfs2)

Wyświetl plik

@ -1,13 +1,8 @@
try:
import errno
import os
except ImportError:
print("SKIP")
raise SystemExit
import errno, os, vfs
try:
os.VfsFat
except AttributeError:
vfs.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -38,13 +33,13 @@ class RAMFS:
try:
bdev = RAMFS(50)
os.VfsFat.mkfs(bdev)
vfs.VfsFat.mkfs(bdev)
except MemoryError:
print("SKIP")
raise SystemExit
vfs = os.VfsFat(bdev)
os.mount(vfs, "/ramdisk")
fs = vfs.VfsFat(bdev)
vfs.mount(fs, "/ramdisk")
os.chdir("/ramdisk")
# file IO
@ -99,12 +94,12 @@ with open("foo_file.txt") as f2:
# print(f.read())
# dirs
vfs.mkdir("foo_dir")
fs.mkdir("foo_dir")
try:
vfs.rmdir("foo_file.txt")
fs.rmdir("foo_file.txt")
except OSError as e:
print(e.errno == 20) # errno.ENOTDIR
vfs.remove("foo_file.txt")
print(list(vfs.ilistdir()))
fs.remove("foo_file.txt")
print(list(fs.ilistdir()))

Wyświetl plik

@ -1,13 +1,8 @@
try:
import errno
import os
except ImportError:
print("SKIP")
raise SystemExit
import errno, os, vfs
try:
os.VfsFat
except AttributeError:
vfs.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -38,32 +33,32 @@ class RAMFS:
try:
bdev = RAMFS(50)
os.VfsFat.mkfs(bdev)
vfs.VfsFat.mkfs(bdev)
except MemoryError:
print("SKIP")
raise SystemExit
vfs = os.VfsFat(bdev)
os.mount(vfs, "/ramdisk")
fs = vfs.VfsFat(bdev)
vfs.mount(fs, "/ramdisk")
os.chdir("/ramdisk")
try:
vfs.mkdir("foo_dir")
fs.mkdir("foo_dir")
except OSError as e:
print(e.errno == errno.EEXIST)
try:
vfs.remove("foo_dir")
fs.remove("foo_dir")
except OSError as e:
print(e.errno == errno.EISDIR)
try:
vfs.remove("no_file.txt")
fs.remove("no_file.txt")
except OSError as e:
print(e.errno == errno.ENOENT)
try:
vfs.rename("foo_dir", "/null/file")
fs.rename("foo_dir", "/null/file")
except OSError as e:
print(e.errno == errno.ENOENT)
@ -79,34 +74,34 @@ with open("foo_dir/sub_file.txt", "w") as f:
# directory not empty
try:
vfs.rmdir("foo_dir")
fs.rmdir("foo_dir")
except OSError as e:
print(e.errno == errno.EACCES)
# trim full path
vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt")
print(list(vfs.ilistdir("foo_dir")))
fs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt")
print(list(fs.ilistdir("foo_dir")))
vfs.rename("foo_dir/file.txt", "moved-to-root.txt")
print(list(vfs.ilistdir()))
fs.rename("foo_dir/file.txt", "moved-to-root.txt")
print(list(fs.ilistdir()))
# check that renaming to existing file will overwrite it
with open("temp", "w") as f:
f.write("new text")
vfs.rename("temp", "moved-to-root.txt")
print(list(vfs.ilistdir()))
fs.rename("temp", "moved-to-root.txt")
print(list(fs.ilistdir()))
with open("moved-to-root.txt") as f:
print(f.read())
# valid removes
vfs.remove("foo_dir/sub_file.txt")
vfs.rmdir("foo_dir")
print(list(vfs.ilistdir()))
fs.remove("foo_dir/sub_file.txt")
fs.rmdir("foo_dir")
print(list(fs.ilistdir()))
# disk full
try:
bsize = vfs.statvfs("/ramdisk")[0]
free = vfs.statvfs("/ramdisk")[2] + 1
bsize = fs.statvfs("/ramdisk")[0]
free = fs.statvfs("/ramdisk")[2] + 1
f = open("large_file.txt", "wb")
f.write(bytearray(bsize * free))
except OSError as e:

Wyświetl plik

@ -1,9 +1,9 @@
# Test VfsFat class and its finaliser
try:
import errno, os
import errno, os, vfs
os.VfsFat
vfs.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -39,8 +39,8 @@ except MemoryError:
raise SystemExit
# Format block device and create VFS object
os.VfsFat.mkfs(bdev)
vfs = os.VfsFat(bdev)
vfs.VfsFat.mkfs(bdev)
fs = vfs.VfsFat(bdev)
# Here we test that opening a file with the heap locked fails correctly. This
# is a special case because file objects use a finaliser and allocating with a
@ -52,7 +52,7 @@ micropython.heap_lock()
try:
import errno, os
vfs.open("x", "r")
fs.open("x", "r")
except MemoryError:
print("MemoryError")
micropython.heap_unlock()
@ -77,10 +77,10 @@ for i in range(1024):
# Only read back N-1 files because the last one may not be finalised due to
# references to it being left on the C stack.
for n in names:
f = vfs.open(n, "w")
f = fs.open(n, "w")
f.write(n)
f = None # release f without closing
gc.collect() # should finalise at least the first N-1 files by closing them
for n in names[:-1]:
with vfs.open(n, "r") as f:
with fs.open(n, "r") as f:
print(f.read())

Wyświetl plik

@ -2,9 +2,9 @@
import gc
try:
import os
import os, vfs
os.VfsFat
vfs.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -37,29 +37,29 @@ class RAMBlockDevice:
def test(bdev, vfs_class):
vfs_class.mkfs(bdev)
vfs = vfs_class(bdev)
vfs.mkdir("/test_d1")
vfs.mkdir("/test_d2")
vfs.mkdir("/test_d3")
fs = vfs_class(bdev)
fs.mkdir("/test_d1")
fs.mkdir("/test_d2")
fs.mkdir("/test_d3")
for i in range(10):
print(i)
# We want to partially iterate the ilistdir iterator to leave it in an
# open state, which will then test the finaliser when it's garbage collected.
idir = vfs.ilistdir("/")
idir = fs.ilistdir("/")
print(any(idir))
# Alternate way of partially iterating the ilistdir object, modifying the
# filesystem while it's open.
for dname, *_ in vfs.ilistdir("/"):
vfs.rmdir(dname)
for dname, *_ in fs.ilistdir("/"):
fs.rmdir(dname)
break
vfs.mkdir(dname)
fs.mkdir(dname)
# Also create a fully drained iterator and ensure trying to reuse it
# throws the correct exception.
idir_emptied = vfs.ilistdir("/")
idir_emptied = fs.ilistdir("/")
l = list(idir_emptied)
print(len(l))
try:
@ -68,7 +68,7 @@ def test(bdev, vfs_class):
pass
gc.collect()
vfs.open("/test", "w").close()
fs.open("/test", "w").close()
try:
@ -77,4 +77,4 @@ except MemoryError:
print("SKIP")
raise SystemExit
test(bdev, os.VfsFat)
test(bdev, vfs.VfsFat)

Wyświetl plik

@ -1,12 +1,8 @@
try:
import os
except ImportError:
print("SKIP")
raise SystemExit
import os, vfs
try:
os.VfsFat
except AttributeError:
vfs.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -44,14 +40,14 @@ except MemoryError:
# first we umount any existing mount points the target may have
try:
os.umount("/")
vfs.umount("/")
except OSError:
pass
for path in os.listdir("/"):
os.umount("/" + path)
vfs.umount("/" + path)
os.VfsFat.mkfs(bdev)
os.mount(bdev, "/")
vfs.VfsFat.mkfs(bdev)
vfs.mount(bdev, "/")
print(os.getcwd())
@ -94,8 +90,8 @@ for exist in ("", "/", "dir", "/dir", "dir/subdir"):
os.chdir("/")
print(os.stat("test5.txt")[:-3])
os.VfsFat.mkfs(bdev2)
os.mount(bdev2, "/sys")
vfs.VfsFat.mkfs(bdev2)
vfs.mount(bdev2, "/sys")
print(os.listdir())
print(os.listdir("sys"))
print(os.listdir("/sys"))
@ -104,7 +100,7 @@ os.rmdir("dir2")
os.remove("test5.txt")
print(os.listdir())
os.umount("/")
vfs.umount("/")
print(os.getcwd())
print(os.listdir())
print(os.listdir("sys"))

Wyświetl plik

@ -1,11 +1,11 @@
# Test for VfsFat using a RAM device, mtime feature
try:
import time, os
import time, os, vfs
time.time
time.sleep
os.VfsFat
vfs.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -41,21 +41,21 @@ def test(bdev, vfs_class):
vfs_class.mkfs(bdev)
# construction
vfs = vfs_class(bdev)
fs = vfs_class(bdev)
# Create an empty file, should have a timestamp.
current_time = int(time.time())
vfs.open("test1", "wt").close()
fs.open("test1", "wt").close()
# Wait 2 seconds so mtime will increase (FAT has 2 second resolution).
time.sleep(2)
# Create another empty file, should have a timestamp.
vfs.open("test2", "wt").close()
fs.open("test2", "wt").close()
# Stat the files and check mtime is non-zero.
stat1 = vfs.stat("test1")
stat2 = vfs.stat("test2")
stat1 = fs.stat("test1")
stat2 = fs.stat("test2")
print(stat1[8] != 0, stat2[8] != 0)
# Check that test1 has mtime which matches time.time() at point of creation.
@ -67,8 +67,8 @@ def test(bdev, vfs_class):
print(stat1[8] < stat2[8])
# Unmount.
vfs.umount()
fs.umount()
bdev = RAMBlockDevice(50)
test(bdev, os.VfsFat)
test(bdev, vfs.VfsFat)

Wyświetl plik

@ -1,13 +1,8 @@
try:
import errno
import os
except ImportError:
print("SKIP")
raise SystemExit
import errno, os, vfs
try:
os.VfsFat
except AttributeError:
vfs.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -41,18 +36,18 @@ except MemoryError:
print("SKIP")
raise SystemExit
os.VfsFat.mkfs(bdev)
vfs = os.VfsFat(bdev)
os.mount(vfs, "/ramdisk")
vfs.VfsFat.mkfs(bdev)
fs = vfs.VfsFat(bdev)
vfs.mount(fs, "/ramdisk")
# file io
with vfs.open("file.txt", "w") as f:
with fs.open("file.txt", "w") as f:
f.write("hello!")
print(list(vfs.ilistdir()))
print(list(fs.ilistdir()))
with vfs.open("file.txt", "r") as f:
with fs.open("file.txt", "r") as f:
print(f.read())
vfs.remove("file.txt")
print(list(vfs.ilistdir()))
fs.remove("file.txt")
print(list(fs.ilistdir()))

Wyświetl plik

@ -1,13 +1,8 @@
try:
import errno
import os
except ImportError:
print("SKIP")
raise SystemExit
import errno, os, vfs
try:
os.VfsFat
except AttributeError:
vfs.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -38,7 +33,7 @@ class RAMFS:
try:
bdev = RAMFS(50)
os.VfsFat.mkfs(bdev)
vfs.VfsFat.mkfs(bdev)
except MemoryError:
print("SKIP")
raise SystemExit
@ -46,50 +41,50 @@ except MemoryError:
print(b"FOO_FILETXT" not in bdev.data)
print(b"hello!" not in bdev.data)
vfs = os.VfsFat(bdev)
os.mount(vfs, "/ramdisk")
fs = vfs.VfsFat(bdev)
vfs.mount(fs, "/ramdisk")
print("statvfs:", vfs.statvfs("/ramdisk"))
print("getcwd:", vfs.getcwd())
print("statvfs:", fs.statvfs("/ramdisk"))
print("getcwd:", fs.getcwd())
try:
vfs.stat("no_file.txt")
fs.stat("no_file.txt")
except OSError as e:
print(e.errno == errno.ENOENT)
with vfs.open("foo_file.txt", "w") as f:
with fs.open("foo_file.txt", "w") as f:
f.write("hello!")
print(list(vfs.ilistdir()))
print(list(fs.ilistdir()))
print("stat root:", vfs.stat("/")[:-3]) # timestamps differ across runs
print("stat file:", vfs.stat("foo_file.txt")[:-3]) # timestamps differ across runs
print("stat root:", fs.stat("/")[:-3]) # timestamps differ across runs
print("stat file:", fs.stat("foo_file.txt")[:-3]) # timestamps differ across runs
print(b"FOO_FILETXT" in bdev.data)
print(b"hello!" in bdev.data)
vfs.mkdir("foo_dir")
vfs.chdir("foo_dir")
print("getcwd:", vfs.getcwd())
print(list(vfs.ilistdir()))
fs.mkdir("foo_dir")
fs.chdir("foo_dir")
print("getcwd:", fs.getcwd())
print(list(fs.ilistdir()))
with vfs.open("sub_file.txt", "w") as f:
with fs.open("sub_file.txt", "w") as f:
f.write("subdir file")
try:
vfs.chdir("sub_file.txt")
fs.chdir("sub_file.txt")
except OSError as e:
print(e.errno == errno.ENOENT)
vfs.chdir("..")
print("getcwd:", vfs.getcwd())
fs.chdir("..")
print("getcwd:", fs.getcwd())
os.umount(vfs)
vfs.umount(fs)
vfs = os.VfsFat(bdev)
print(list(vfs.ilistdir(b"")))
fs = vfs.VfsFat(bdev)
print(list(fs.ilistdir(b"")))
# list a non-existent directory
try:
vfs.ilistdir(b"no_exist")
fs.ilistdir(b"no_exist")
except OSError as e:
print("ENOENT:", e.errno == errno.ENOENT)

Wyświetl plik

@ -1,14 +1,10 @@
# test making a FAT filesystem on a very large block device
try:
import os
except ImportError:
print("SKIP")
raise SystemExit
import os, vfs
try:
os.VfsFat
except AttributeError:
vfs.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -46,24 +42,24 @@ class RAMBDevSparse:
try:
bdev = RAMBDevSparse(4 * 1024 * 1024 * 1024 // RAMBDevSparse.SEC_SIZE)
os.VfsFat.mkfs(bdev)
vfs.VfsFat.mkfs(bdev)
except MemoryError:
print("SKIP")
raise SystemExit
vfs = os.VfsFat(bdev)
os.mount(vfs, "/ramdisk")
fs = vfs.VfsFat(bdev)
vfs.mount(fs, "/ramdisk")
print("statvfs:", vfs.statvfs("/ramdisk"))
print("statvfs:", fs.statvfs("/ramdisk"))
f = open("/ramdisk/test.txt", "w")
f.write("test file")
f.close()
print("statvfs:", vfs.statvfs("/ramdisk"))
print("statvfs:", fs.statvfs("/ramdisk"))
f = open("/ramdisk/test.txt")
print(f.read())
f.close()
os.umount(vfs)
vfs.umount(fs)

Wyświetl plik

@ -1,10 +1,10 @@
# Test for VfsLittle using a RAM device
try:
import os
import os, vfs
os.VfsLfs1
os.VfsLfs2
vfs.VfsLfs1
vfs.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -47,44 +47,44 @@ def test(bdev, vfs_class):
vfs_class.mkfs(bdev)
# construction
vfs = vfs_class(bdev)
fs = vfs_class(bdev)
# statvfs
print(vfs.statvfs("/"))
print(fs.statvfs("/"))
# open, write close
f = vfs.open("test", "w")
f = fs.open("test", "w")
f.write("littlefs")
f.close()
# statvfs after creating a file
print(vfs.statvfs("/"))
print(fs.statvfs("/"))
# ilistdir
print(list(vfs.ilistdir()))
print(list(vfs.ilistdir("/")))
print(list(vfs.ilistdir(b"/")))
print(list(fs.ilistdir()))
print(list(fs.ilistdir("/")))
print(list(fs.ilistdir(b"/")))
# mkdir, rmdir
vfs.mkdir("testdir")
print(list(vfs.ilistdir()))
print(sorted(list(vfs.ilistdir("testdir"))))
vfs.rmdir("testdir")
print(list(vfs.ilistdir()))
vfs.mkdir("testdir")
fs.mkdir("testdir")
print(list(fs.ilistdir()))
print(sorted(list(fs.ilistdir("testdir"))))
fs.rmdir("testdir")
print(list(fs.ilistdir()))
fs.mkdir("testdir")
# stat a file
print_stat(vfs.stat("test"))
print_stat(fs.stat("test"))
# stat a dir (size seems to vary on LFS2 so don't print that)
print_stat(vfs.stat("testdir"), False)
print_stat(fs.stat("testdir"), False)
# read
with vfs.open("test", "r") as f:
with fs.open("test", "r") as f:
print(f.read())
# create large file
with vfs.open("testbig", "w") as f:
with fs.open("testbig", "w") as f:
data = "large012" * 32 * 16
print("data length:", len(data))
for i in range(4):
@ -92,63 +92,63 @@ def test(bdev, vfs_class):
f.write(data)
# stat after creating large file
print(vfs.statvfs("/"))
print(fs.statvfs("/"))
# rename
vfs.rename("testbig", "testbig2")
print(sorted(list(vfs.ilistdir())))
vfs.chdir("testdir")
vfs.rename("/testbig2", "testbig2")
print(sorted(list(vfs.ilistdir())))
vfs.rename("testbig2", "/testbig2")
vfs.chdir("/")
print(sorted(list(vfs.ilistdir())))
fs.rename("testbig", "testbig2")
print(sorted(list(fs.ilistdir())))
fs.chdir("testdir")
fs.rename("/testbig2", "testbig2")
print(sorted(list(fs.ilistdir())))
fs.rename("testbig2", "/testbig2")
fs.chdir("/")
print(sorted(list(fs.ilistdir())))
# remove
vfs.remove("testbig2")
print(sorted(list(vfs.ilistdir())))
fs.remove("testbig2")
print(sorted(list(fs.ilistdir())))
# getcwd, chdir
vfs.mkdir("/testdir2")
vfs.mkdir("/testdir/subdir")
print(vfs.getcwd())
vfs.chdir("/testdir")
print(vfs.getcwd())
fs.mkdir("/testdir2")
fs.mkdir("/testdir/subdir")
print(fs.getcwd())
fs.chdir("/testdir")
print(fs.getcwd())
# create file in directory to make sure paths are relative
vfs.open("test2", "w").close()
print_stat(vfs.stat("test2"))
print_stat(vfs.stat("/testdir/test2"))
vfs.remove("test2")
fs.open("test2", "w").close()
print_stat(fs.stat("test2"))
print_stat(fs.stat("/testdir/test2"))
fs.remove("test2")
# chdir back to root and remove testdir
vfs.chdir("/")
print(vfs.getcwd())
vfs.chdir("testdir")
print(vfs.getcwd())
vfs.chdir("..")
print(vfs.getcwd())
vfs.chdir("testdir/subdir")
print(vfs.getcwd())
vfs.chdir("../..")
print(vfs.getcwd())
vfs.chdir("/./testdir2")
print(vfs.getcwd())
vfs.chdir("../testdir")
print(vfs.getcwd())
vfs.chdir("../..")
print(vfs.getcwd())
vfs.chdir(".//testdir")
print(vfs.getcwd())
vfs.chdir("subdir/./")
print(vfs.getcwd())
vfs.chdir("/")
print(vfs.getcwd())
vfs.rmdir("testdir/subdir")
vfs.rmdir("testdir")
vfs.rmdir("testdir2")
fs.chdir("/")
print(fs.getcwd())
fs.chdir("testdir")
print(fs.getcwd())
fs.chdir("..")
print(fs.getcwd())
fs.chdir("testdir/subdir")
print(fs.getcwd())
fs.chdir("../..")
print(fs.getcwd())
fs.chdir("/./testdir2")
print(fs.getcwd())
fs.chdir("../testdir")
print(fs.getcwd())
fs.chdir("../..")
print(fs.getcwd())
fs.chdir(".//testdir")
print(fs.getcwd())
fs.chdir("subdir/./")
print(fs.getcwd())
fs.chdir("/")
print(fs.getcwd())
fs.rmdir("testdir/subdir")
fs.rmdir("testdir")
fs.rmdir("testdir2")
bdev = RAMBlockDevice(30)
test(bdev, os.VfsLfs1)
test(bdev, os.VfsLfs2)
test(bdev, vfs.VfsLfs1)
test(bdev, vfs.VfsLfs2)

Wyświetl plik

@ -1,10 +1,10 @@
# Test for VfsLittle using a RAM device, testing error handling from corrupt block device
try:
import os
import vfs
os.VfsLfs1
os.VfsLfs2
vfs.VfsLfs1
vfs.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -47,28 +47,28 @@ def corrupt(bdev, block):
def create_vfs(bdev, vfs_class):
bdev.ret = 0
vfs_class.mkfs(bdev)
vfs = vfs_class(bdev)
with vfs.open("f", "w") as f:
fs = vfs_class(bdev)
with fs.open("f", "w") as f:
for i in range(100):
f.write("test")
return vfs
return fs
def test(bdev, vfs_class):
print("test", vfs_class)
# statvfs
vfs = create_vfs(bdev, vfs_class)
fs = create_vfs(bdev, vfs_class)
corrupt(bdev, 0)
corrupt(bdev, 1)
try:
print(vfs.statvfs(""))
print(fs.statvfs(""))
except OSError:
print("statvfs OSError")
# error during read
vfs = create_vfs(bdev, vfs_class)
f = vfs.open("f", "r")
fs = create_vfs(bdev, vfs_class)
f = fs.open("f", "r")
bdev.ret = -5 # EIO
try:
f.read(10)
@ -76,8 +76,8 @@ def test(bdev, vfs_class):
print("read OSError")
# error during write
vfs = create_vfs(bdev, vfs_class)
f = vfs.open("f", "a")
fs = create_vfs(bdev, vfs_class)
f = fs.open("f", "a")
bdev.ret = -5 # EIO
try:
f.write("test")
@ -85,8 +85,8 @@ def test(bdev, vfs_class):
print("write OSError")
# error during close
vfs = create_vfs(bdev, vfs_class)
f = vfs.open("f", "w")
fs = create_vfs(bdev, vfs_class)
f = fs.open("f", "w")
f.write("test")
bdev.ret = -5 # EIO
try:
@ -95,8 +95,8 @@ def test(bdev, vfs_class):
print("close OSError")
# error during flush
vfs = create_vfs(bdev, vfs_class)
f = vfs.open("f", "w")
fs = create_vfs(bdev, vfs_class)
f = fs.open("f", "w")
f.write("test")
bdev.ret = -5 # EIO
try:
@ -108,5 +108,5 @@ def test(bdev, vfs_class):
bdev = RAMBlockDevice(30)
test(bdev, os.VfsLfs1)
test(bdev, os.VfsLfs2)
test(bdev, vfs.VfsLfs1)
test(bdev, vfs.VfsLfs2)

Wyświetl plik

@ -1,10 +1,10 @@
# Test for VfsLittle using a RAM device, testing error handling
try:
import os
import vfs
os.VfsLfs1
os.VfsLfs2
vfs.VfsLfs1
vfs.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -52,63 +52,63 @@ def test(bdev, vfs_class):
# set up for following tests
vfs_class.mkfs(bdev)
vfs = vfs_class(bdev)
with vfs.open("testfile", "w") as f:
fs = vfs_class(bdev)
with fs.open("testfile", "w") as f:
f.write("test")
vfs.mkdir("testdir")
fs.mkdir("testdir")
# ilistdir
try:
vfs.ilistdir("noexist")
fs.ilistdir("noexist")
except OSError:
print("ilistdir OSError")
# remove
try:
vfs.remove("noexist")
fs.remove("noexist")
except OSError:
print("remove OSError")
# rmdir
try:
vfs.rmdir("noexist")
fs.rmdir("noexist")
except OSError:
print("rmdir OSError")
# rename
try:
vfs.rename("noexist", "somethingelse")
fs.rename("noexist", "somethingelse")
except OSError:
print("rename OSError")
# mkdir
try:
vfs.mkdir("testdir")
fs.mkdir("testdir")
except OSError:
print("mkdir OSError")
# chdir to nonexistent
try:
vfs.chdir("noexist")
fs.chdir("noexist")
except OSError:
print("chdir OSError")
print(vfs.getcwd()) # check still at root
print(fs.getcwd()) # check still at root
# chdir to file
try:
vfs.chdir("testfile")
fs.chdir("testfile")
except OSError:
print("chdir OSError")
print(vfs.getcwd()) # check still at root
print(fs.getcwd()) # check still at root
# stat
try:
vfs.stat("noexist")
fs.stat("noexist")
except OSError:
print("stat OSError")
# error during seek
with vfs.open("testfile", "r") as f:
with fs.open("testfile", "r") as f:
f.seek(1 << 30) # SEEK_SET
try:
f.seek(1 << 30, 1) # SEEK_CUR
@ -117,5 +117,5 @@ def test(bdev, vfs_class):
bdev = RAMBlockDevice(30)
test(bdev, os.VfsLfs1)
test(bdev, os.VfsLfs2)
test(bdev, vfs.VfsLfs1)
test(bdev, vfs.VfsLfs2)

Wyświetl plik

@ -1,10 +1,10 @@
# Test for VfsLittle using a RAM device, file IO
try:
import os
import vfs
os.VfsLfs1
os.VfsLfs2
vfs.VfsLfs1
vfs.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -42,10 +42,10 @@ def test(bdev, vfs_class):
vfs_class.mkfs(bdev)
# construction
vfs = vfs_class(bdev)
fs = vfs_class(bdev)
# create text, print, write, close
f = vfs.open("test.txt", "wt")
f = fs.open("test.txt", "wt")
print(f)
f.write("littlefs")
f.close()
@ -54,48 +54,48 @@ def test(bdev, vfs_class):
f.close()
# create binary, print, write, flush, close
f = vfs.open("test.bin", "wb")
f = fs.open("test.bin", "wb")
print(f)
f.write("littlefs")
f.flush()
f.close()
# create for append
f = vfs.open("test.bin", "ab")
f = fs.open("test.bin", "ab")
f.write("more")
f.close()
# create exclusive
f = vfs.open("test2.bin", "xb")
f = fs.open("test2.bin", "xb")
f.close()
# create exclusive with error
try:
vfs.open("test2.bin", "x")
fs.open("test2.bin", "x")
except OSError:
print("open OSError")
# read default
with vfs.open("test.txt", "") as f:
with fs.open("test.txt", "") as f:
print(f.read())
# read text
with vfs.open("test.txt", "rt") as f:
with fs.open("test.txt", "rt") as f:
print(f.read())
# read binary
with vfs.open("test.bin", "rb") as f:
with fs.open("test.bin", "rb") as f:
print(f.read())
# create read and write
with vfs.open("test.bin", "r+b") as f:
with fs.open("test.bin", "r+b") as f:
print(f.read(8))
f.write("MORE")
with vfs.open("test.bin", "rb") as f:
with fs.open("test.bin", "rb") as f:
print(f.read())
# seek and tell
f = vfs.open("test.txt", "r")
f = fs.open("test.txt", "r")
print(f.tell())
f.seek(3, 0)
print(f.tell())
@ -103,13 +103,13 @@ def test(bdev, vfs_class):
# open nonexistent
try:
vfs.open("noexist", "r")
fs.open("noexist", "r")
except OSError:
print("open OSError")
# open multiple files at the same time
f1 = vfs.open("test.txt", "")
f2 = vfs.open("test.bin", "b")
f1 = fs.open("test.txt", "")
f2 = fs.open("test.bin", "b")
print(f1.read())
print(f2.read())
f1.close()
@ -117,5 +117,5 @@ def test(bdev, vfs_class):
bdev = RAMBlockDevice(30)
test(bdev, os.VfsLfs1)
test(bdev, os.VfsLfs2)
test(bdev, vfs.VfsLfs1)
test(bdev, vfs.VfsLfs2)

Wyświetl plik

@ -2,9 +2,9 @@
import gc
try:
import os
import vfs
os.VfsLfs2
vfs.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -37,29 +37,29 @@ class RAMBlockDevice:
def test(bdev, vfs_class):
vfs_class.mkfs(bdev)
vfs = vfs_class(bdev)
vfs.mkdir("/test_d1")
vfs.mkdir("/test_d2")
vfs.mkdir("/test_d3")
fs = vfs_class(bdev)
fs.mkdir("/test_d1")
fs.mkdir("/test_d2")
fs.mkdir("/test_d3")
for i in range(10):
print(i)
# We want to partially iterate the ilistdir iterator to leave it in an
# open state, which will then test the finaliser when it's garbage collected.
idir = vfs.ilistdir("/")
idir = fs.ilistdir("/")
print(any(idir))
# Alternate way of partially iterating the ilistdir object, modifying the
# filesystem while it's open.
for dname, *_ in vfs.ilistdir("/"):
vfs.rmdir(dname)
for dname, *_ in fs.ilistdir("/"):
fs.rmdir(dname)
break
vfs.mkdir(dname)
fs.mkdir(dname)
# Also create a fully drained iterator and ensure trying to reuse it
# throws the correct exception.
idir_emptied = vfs.ilistdir("/")
idir_emptied = fs.ilistdir("/")
l = list(idir_emptied)
print(len(l))
try:
@ -68,8 +68,8 @@ def test(bdev, vfs_class):
pass
gc.collect()
vfs.open("/test", "w").close()
fs.open("/test", "w").close()
bdev = RAMBlockDevice(30)
test(bdev, os.VfsLfs2)
test(bdev, vfs.VfsLfs2)

Wyświetl plik

@ -1,10 +1,10 @@
# Test for VfsLittle using a RAM device, with mount/umount
try:
import os
import os, vfs
os.VfsLfs1
os.VfsLfs2
vfs.VfsLfs1
vfs.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -42,7 +42,7 @@ def test(vfs_class):
# mount bdev unformatted
try:
os.mount(bdev, "/lfs")
vfs.mount(bdev, "/lfs")
except Exception as er:
print(repr(er))
@ -50,10 +50,10 @@ def test(vfs_class):
vfs_class.mkfs(bdev)
# construction
vfs = vfs_class(bdev)
fs = vfs_class(bdev)
# mount
os.mount(vfs, "/lfs")
vfs.mount(fs, "/lfs")
# import
with open("/lfs/lfsmod.py", "w") as f:
@ -73,11 +73,11 @@ def test(vfs_class):
import lfsmod2
# umount
os.umount("/lfs")
vfs.umount("/lfs")
# mount read-only
vfs = vfs_class(bdev)
os.mount(vfs, "/lfs", readonly=True)
fs = vfs_class(bdev)
vfs.mount(fs, "/lfs", readonly=True)
# test reading works
with open("/lfs/subdir/lfsmod2.py") as f:
@ -90,13 +90,13 @@ def test(vfs_class):
print(repr(er))
# umount
os.umount("/lfs")
vfs.umount("/lfs")
# mount bdev again
os.mount(bdev, "/lfs")
vfs.mount(bdev, "/lfs")
# umount
os.umount("/lfs")
vfs.umount("/lfs")
# clear imported modules
sys.modules.clear()
@ -110,5 +110,5 @@ sys.path.append("/lfs")
sys.path.append("")
# run tests
test(os.VfsLfs1)
test(os.VfsLfs2)
test(vfs.VfsLfs1)
test(vfs.VfsLfs2)

Wyświetl plik

@ -1,11 +1,11 @@
# Test for VfsLfs using a RAM device, mtime feature
try:
import time, os
import time, vfs
time.time
time.sleep
os.VfsLfs2
vfs.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -44,21 +44,21 @@ def test(bdev, vfs_class):
# construction
print("mtime=True")
vfs = vfs_class(bdev, mtime=True)
fs = vfs_class(bdev, mtime=True)
# Create an empty file, should have a timestamp.
current_time = int(time.time())
vfs.open("test1", "wt").close()
fs.open("test1", "wt").close()
# Wait 1 second so mtime will increase by at least 1.
time.sleep(1)
# Create another empty file, should have a timestamp.
vfs.open("test2", "wt").close()
fs.open("test2", "wt").close()
# Stat the files and check mtime is non-zero.
stat1 = vfs.stat("test1")
stat2 = vfs.stat("test2")
stat1 = fs.stat("test1")
stat2 = fs.stat("test2")
print(stat1[8] != 0, stat2[8] != 0)
# Check that test1 has mtime which matches time.time() at point of creation.
@ -71,34 +71,34 @@ def test(bdev, vfs_class):
time.sleep(1)
# Open test1 for reading and ensure mtime did not change.
vfs.open("test1", "rt").close()
print(vfs.stat("test1") == stat1)
fs.open("test1", "rt").close()
print(fs.stat("test1") == stat1)
# Open test1 for writing and ensure mtime increased from the previous value.
vfs.open("test1", "wt").close()
fs.open("test1", "wt").close()
stat1_old = stat1
stat1 = vfs.stat("test1")
stat1 = fs.stat("test1")
print(stat1_old[8] < stat1[8])
# Unmount.
vfs.umount()
fs.umount()
# Check that remounting with mtime=False can read the timestamps.
print("mtime=False")
vfs = vfs_class(bdev, mtime=False)
print(vfs.stat("test1") == stat1)
print(vfs.stat("test2") == stat2)
f = vfs.open("test1", "wt")
fs = vfs_class(bdev, mtime=False)
print(fs.stat("test1") == stat1)
print(fs.stat("test2") == stat2)
f = fs.open("test1", "wt")
f.close()
print(vfs.stat("test1") == stat1)
vfs.umount()
print(fs.stat("test1") == stat1)
fs.umount()
# Check that remounting with mtime=True still has the timestamps.
print("mtime=True")
vfs = vfs_class(bdev, mtime=True)
print(vfs.stat("test1") == stat1)
print(vfs.stat("test2") == stat2)
vfs.umount()
fs = vfs_class(bdev, mtime=True)
print(fs.stat("test1") == stat1)
print(fs.stat("test2") == stat2)
fs.umount()
try:
@ -107,4 +107,4 @@ except MemoryError:
print("SKIP")
raise SystemExit
test(bdev, os.VfsLfs2)
test(bdev, vfs.VfsLfs2)

Wyświetl plik

@ -1,9 +1,9 @@
# Test for VfsLfs using a RAM device, when the first superblock does not exist
try:
import os
import os, vfs
os.VfsLfs2
vfs.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -36,12 +36,12 @@ lfs2_data = b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x
bdev = RAMBlockDevice(64, lfs2_data)
# Create the VFS explicitly, no auto-detection is needed for this.
vfs = os.VfsLfs2(bdev)
print(list(vfs.ilistdir()))
fs = vfs.VfsLfs2(bdev)
print(list(fs.ilistdir()))
# Mount the block device directly; this relies on auto-detection.
os.mount(bdev, "/userfs")
vfs.mount(bdev, "/userfs")
print(os.listdir("/userfs"))
# Clean up.
os.umount("/userfs")
vfs.umount("/userfs")

Wyświetl plik

@ -1,10 +1,9 @@
# Test for VfsPosix
try:
import gc
import os
import gc, os, vfs
os.VfsPosix
vfs.VfsPosix
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -13,8 +12,6 @@ except (ImportError, AttributeError):
# Skip the test if it does exist.
temp_dir = "micropy_test_dir"
try:
import os
os.stat(temp_dir)
print("SKIP")
raise SystemExit
@ -87,35 +84,35 @@ os.rename(temp_dir + "/test", temp_dir + "/test2")
print(os.listdir(temp_dir))
# construct new VfsPosix with path argument
vfs = os.VfsPosix(temp_dir)
# when VfsPosix is used the intended way via os.mount(), it can only be called
fs = vfs.VfsPosix(temp_dir)
# when VfsPosix is used the intended way via vfs.mount(), it can only be called
# with relative paths when the CWD is inside or at its root, so simulate that
os.chdir(temp_dir)
print(list(i[0] for i in vfs.ilistdir(".")))
print(list(i[0] for i in fs.ilistdir(".")))
# stat, statvfs (statvfs may not exist)
print(type(vfs.stat(".")))
if hasattr(vfs, "statvfs"):
assert type(vfs.statvfs(".")) is tuple
print(type(fs.stat(".")))
if hasattr(fs, "statvfs"):
assert type(fs.statvfs(".")) is tuple
# check types of ilistdir with str/bytes arguments
print(type(list(vfs.ilistdir("."))[0][0]))
print(type(list(vfs.ilistdir(b"."))[0][0]))
print(type(list(fs.ilistdir("."))[0][0]))
print(type(list(fs.ilistdir(b"."))[0][0]))
# chdir should not affect absolute paths (regression test)
vfs.mkdir("/subdir")
vfs.mkdir("/subdir/micropy_test_dir")
with vfs.open("/subdir/micropy_test_dir/test2", "w") as f:
fs.mkdir("/subdir")
fs.mkdir("/subdir/micropy_test_dir")
with fs.open("/subdir/micropy_test_dir/test2", "w") as f:
f.write("wrong")
vfs.chdir("/subdir")
with vfs.open("/test2", "r") as f:
fs.chdir("/subdir")
with fs.open("/test2", "r") as f:
print(f.read())
os.chdir(curdir)
vfs.remove("/subdir/micropy_test_dir/test2")
vfs.rmdir("/subdir/micropy_test_dir")
vfs.rmdir("/subdir")
fs.remove("/subdir/micropy_test_dir/test2")
fs.rmdir("/subdir/micropy_test_dir")
fs.rmdir("/subdir")
# done with vfs, restore CWD
# done with fs, restore CWD
os.chdir(curdir)
# remove

Wyświetl plik

@ -1,10 +1,9 @@
# Test for VfsPosix error conditions
try:
import os
import sys
import os, sys, vfs
os.VfsPosix
vfs.VfsPosix
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -36,7 +35,7 @@ except OSError as e:
print("getcwd():", repr(e))
try:
print("VfsPosix():", os.VfsPosix("something"))
print("VfsPosix():", vfs.VfsPosix("something"))
except OSError as e:
# expecting ENOENT = 2
print("VfsPosix():", repr(e))

Wyświetl plik

@ -2,9 +2,9 @@
import gc
try:
import os
import os, vfs
os.VfsPosix
vfs.VfsPosix
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -12,34 +12,34 @@ except (ImportError, AttributeError):
def test(testdir):
curdir = os.getcwd()
vfs = os.VfsPosix(testdir)
# When VfsPosix is used the intended way via os.mount(), it can only be called
fs = vfs.VfsPosix(testdir)
# When VfsPosix is used the intended way via vfs.mount(), it can only be called
# with relative paths when the CWD is inside or at its root, so simulate that.
# (Although perhaps calling with a relative path was an oversight in this case
# and the respective line below was meant to read `vfs.rmdir("/" + dname)`.)
# and the respective line below was meant to read `fs.rmdir("/" + dname)`.)
os.chdir(testdir)
vfs.mkdir("/test_d1")
vfs.mkdir("/test_d2")
vfs.mkdir("/test_d3")
fs.mkdir("/test_d1")
fs.mkdir("/test_d2")
fs.mkdir("/test_d3")
for i in range(10):
print(i)
# We want to partially iterate the ilistdir iterator to leave it in an
# open state, which will then test the finaliser when it's garbage collected.
idir = vfs.ilistdir("/")
idir = fs.ilistdir("/")
print(any(idir))
# Alternate way of partially iterating the ilistdir object, modifying the
# filesystem while it's open.
for dname, *_ in vfs.ilistdir("/"):
vfs.rmdir(dname)
for dname, *_ in fs.ilistdir("/"):
fs.rmdir(dname)
break
vfs.mkdir(dname)
fs.mkdir(dname)
# Also create a fully drained iterator and ensure trying to reuse it
# throws the correct exception.
idir_emptied = vfs.ilistdir("/")
idir_emptied = fs.ilistdir("/")
l = list(idir_emptied)
print(len(l))
try:
@ -51,10 +51,10 @@ def test(testdir):
# Create and delete a file, try to flush out any filesystem
# corruption that may be caused over the loops.
vfs.open("/test", "w").close()
vfs.remove("/test")
fs.open("/test", "w").close()
fs.remove("/test")
# Done with vfs, restore CWD.
# Done with fs, restore CWD.
os.chdir(curdir)

Wyświetl plik

@ -1,9 +1,9 @@
# Test ilistdir filter of . and .. for VfsPosix.
try:
import os
import os, vfs
os.VfsPosix
vfs.VfsPosix
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -11,24 +11,24 @@ except (ImportError, AttributeError):
def test(testdir):
curdir = os.getcwd()
vfs = os.VfsPosix(testdir)
# When VfsPosix is used the intended way via os.mount(), it can only be called
fs = vfs.VfsPosix(testdir)
# When VfsPosix is used the intended way via vfs.mount(), it can only be called
# with relative paths when the CWD is inside or at its root, so simulate that.
os.chdir(testdir)
dirs = [".a", "..a", "...a", "a.b", "a..b"]
for dir in dirs:
vfs.mkdir(dir)
fs.mkdir(dir)
dirs = []
for entry in vfs.ilistdir("/"):
for entry in fs.ilistdir("/"):
dirs.append(entry[0])
dirs.sort()
print(dirs)
# Done with vfs, restore CWD.
# Done with fs, restore CWD.
os.chdir(curdir)

Wyświetl plik

@ -1,9 +1,9 @@
# Test for VfsPosix with relative paths
try:
import os
import os, vfs
os.VfsPosix
vfs.VfsPosix
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -12,8 +12,6 @@ except (ImportError, AttributeError):
# Skip the test if it does exist.
temp_dir = "vfs_posix_paths_test_dir"
try:
import os
os.stat(temp_dir)
print("SKIP")
raise SystemExit
@ -25,26 +23,26 @@ os.mkdir(temp_dir)
# construct new VfsPosix with absolute path argument
temp_dir_abs = os.getcwd() + os.sep + temp_dir
vfs = os.VfsPosix(temp_dir_abs)
# when VfsPosix is used the intended way via os.mount(), it can only be called
fs = vfs.VfsPosix(temp_dir_abs)
# when VfsPosix is used the intended way via vfs.mount(), it can only be called
# with relative paths when the CWD is inside or at its root, so simulate that
os.chdir(temp_dir_abs)
vfs.mkdir("subdir")
vfs.mkdir("subdir/one")
print('listdir("/"):', sorted(i[0] for i in vfs.ilistdir("/")))
print('listdir("."):', sorted(i[0] for i in vfs.ilistdir(".")))
print('getcwd() in {"", "/"}:', vfs.getcwd() in {"", "/"})
print('chdir("subdir"):', vfs.chdir("subdir"))
print("getcwd():", vfs.getcwd())
print('mkdir("two"):', vfs.mkdir("two"))
f = vfs.open("file.py", "w")
fs.mkdir("subdir")
fs.mkdir("subdir/one")
print('listdir("/"):', sorted(i[0] for i in fs.ilistdir("/")))
print('listdir("."):', sorted(i[0] for i in fs.ilistdir(".")))
print('getcwd() in {"", "/"}:', fs.getcwd() in {"", "/"})
print('chdir("subdir"):', fs.chdir("subdir"))
print("getcwd():", fs.getcwd())
print('mkdir("two"):', fs.mkdir("two"))
f = fs.open("file.py", "w")
f.write("print('hello')")
f.close()
print('listdir("/"):', sorted(i[0] for i in vfs.ilistdir("/")))
print('listdir("/subdir"):', sorted(i[0] for i in vfs.ilistdir("/subdir")))
print('listdir("."):', sorted(i[0] for i in vfs.ilistdir(".")))
print('listdir("/"):', sorted(i[0] for i in fs.ilistdir("/")))
print('listdir("/subdir"):', sorted(i[0] for i in fs.ilistdir("/subdir")))
print('listdir("."):', sorted(i[0] for i in fs.ilistdir(".")))
try:
f = vfs.open("/subdir/file.py", "r")
f = fs.open("/subdir/file.py", "r")
print(f.read())
f.close()
except Exception as e:
@ -59,17 +57,17 @@ try:
except Exception as e:
print(e)
del sys.path[0]
vfs.remove("file.py")
vfs.rmdir("two")
vfs.rmdir("/subdir/one")
vfs.chdir("/")
vfs.rmdir("/subdir")
fs.remove("file.py")
fs.rmdir("two")
fs.rmdir("/subdir/one")
fs.chdir("/")
fs.rmdir("/subdir")
# done with vfs, restore CWD
# done with fs, restore CWD
os.chdir(curdir)
# some integration tests with a mounted VFS
os.mount(os.VfsPosix(temp_dir_abs), "/mnt")
vfs.mount(vfs.VfsPosix(temp_dir_abs), "/mnt")
os.mkdir("/mnt/dir")
print('chdir("/mnt/dir"):', os.chdir("/mnt/dir"))
print("getcwd():", os.getcwd())
@ -82,7 +80,7 @@ print("getcwd():", os.getcwd())
print('chdir(".."):', os.chdir(".."))
print("getcwd():", os.getcwd())
os.rmdir("/mnt/dir")
os.umount("/mnt")
vfs.umount("/mnt")
# restore CWD
os.chdir(curdir)

Wyświetl plik

@ -4,12 +4,9 @@
import sys
try:
import io
import io, vfs
io.IOBase
import os
os.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -79,7 +76,7 @@ user_files = {
"/usermod5.py": b"print('in usermod5')",
"/usermod6.py": b"print('in usermod6')",
}
os.mount(UserFS(user_files), "/userfs")
vfs.mount(UserFS(user_files), "/userfs")
# open and read a file
f = open("/userfs/data.txt")
@ -110,5 +107,5 @@ UserFile.buffer_size = 1024
import usermod6
# unmount and undo path addition
os.umount("/userfs")
vfs.umount("/userfs")
sys.path.pop()

Wyświetl plik

@ -1,11 +1,10 @@
# Test builtin execfile function using VFS.
try:
import io, os
import io, os, vfs
execfile
io.IOBase
os.mount
except (ImportError, NameError, AttributeError):
print("SKIP")
raise SystemExit
@ -44,25 +43,21 @@ class Filesystem:
# First umount any existing mount points the target may have.
try:
import io, os
os.umount("/")
vfs.umount("/")
except OSError:
pass
for path in os.listdir("/"):
os.umount("/" + path)
vfs.umount("/" + path)
# Create and mount the VFS object.
files = {
"/test.py": "print(123)",
}
fs = Filesystem(files)
os.mount(fs, "/test_mnt")
vfs.mount(fs, "/test_mnt")
# Test execfile with a file that doesn't exist.
try:
import io, os
execfile("/test_mnt/noexist.py")
except OSError:
print("OSError")
@ -77,4 +72,4 @@ except TypeError:
print("TypeError")
# Unmount the VFS object.
os.umount(fs)
vfs.umount(fs)

Wyświetl plik

@ -1,10 +1,9 @@
# test importing of invalid .mpy files
try:
import sys, io, os
import sys, io, vfs
io.IOBase
os.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -52,7 +51,7 @@ user_files = {
}
# create and mount a user filesystem
os.mount(UserFS(user_files), "/userfs")
vfs.mount(UserFS(user_files), "/userfs")
sys.path.append("/userfs")
# import .mpy files from the user filesystem
@ -64,5 +63,5 @@ for i in range(len(user_files)):
print(mod, "ValueError", er)
# unmount and undo path addition
os.umount("/userfs")
vfs.umount("/userfs")
sys.path.pop()

Wyświetl plik

@ -1,11 +1,10 @@
# test importing of .mpy files with native code
try:
import sys, io, os
import sys, io, vfs
sys.implementation._mpy
io.IOBase
os.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -110,7 +109,7 @@ user_files = {
# fmt: on
# create and mount a user filesystem
os.mount(UserFS(user_files), "/userfs")
vfs.mount(UserFS(user_files), "/userfs")
sys.path.append("/userfs")
# import .mpy files from the user filesystem
@ -123,5 +122,5 @@ for i in range(len(user_files)):
print(mod, "ValueError", er)
# unmount and undo path addition
os.umount("/userfs")
vfs.umount("/userfs")
sys.path.pop()

Wyświetl plik

@ -1,11 +1,10 @@
# Test that native code loaded from a .mpy file is retained after a GC.
try:
import gc, sys, io, os
import gc, sys, io, vfs
sys.implementation._mpy
io.IOBase
os.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
@ -72,7 +71,7 @@ if sys_implementation_mpy not in features0_file_contents:
user_files = {"/features0.mpy": features0_file_contents[sys_implementation_mpy]}
# Create and mount a user filesystem.
os.mount(UserFS(user_files), "/userfs")
vfs.mount(UserFS(user_files), "/userfs")
sys.path.append("/userfs")
# Import the native function.
@ -93,5 +92,5 @@ for i in range(1000):
print(factorial(10))
# Unmount and undo path addition.
os.umount("/userfs")
vfs.umount("/userfs")
sys.path.pop()

Wyświetl plik

@ -1,8 +1,8 @@
# Test performance of importing an .mpy file many times.
import sys, io, os
import sys, io, vfs
if not (hasattr(io, "IOBase") and hasattr(os, "mount")):
if not hasattr(io, "IOBase"):
print("SKIP")
raise SystemExit
@ -57,7 +57,7 @@ class FS:
def mount():
os.mount(FS(), "/__remote")
vfs.mount(FS(), "/__remote")
sys.path.insert(0, "/__remote")

Wyświetl plik

@ -2,9 +2,9 @@
# The first import of a module will intern strings that don't already exist, and
# this test should be representative of what happens in a real application.
import io, os, sys
import sys, io, vfs
if not (hasattr(io, "IOBase") and hasattr(os, "mount")):
if not hasattr(io, "IOBase"):
print("SKIP")
raise SystemExit
@ -112,7 +112,7 @@ class FS:
def mount():
os.mount(FS(), "/__remote")
vfs.mount(FS(), "/__remote")
sys.path.insert(0, "/__remote")

Wyświetl plik

@ -3,7 +3,7 @@ os module test for the CC3200 based boards
"""
from machine import SD
import os
import os, vfs
mch = os.uname().machine
if "LaunchPad" in mch:
@ -15,7 +15,7 @@ else:
sd = SD(pins=sd_pins)
os.mount(sd, "/sd")
vfs.mount(sd, "/sd")
os.mkfs("/sd")
os.chdir("/flash")
print(os.listdir())
@ -88,7 +88,7 @@ print(os.listdir("/"))
os.unmount("/sd")
print(os.listdir("/"))
os.mkfs(sd)
os.mount(sd, "/sd")
vfs.mount(sd, "/sd")
print(os.listdir("/"))
os.chdir("/flash")
@ -104,12 +104,12 @@ sd.init()
print(os.listdir("/sd"))
try:
os.mount(sd, "/sd")
vfs.mount(sd, "/sd")
except:
print("Exception")
try:
os.mount(sd, "/sd2")
vfs.mount(sd, "/sd2")
except:
print("Exception")
@ -159,6 +159,6 @@ try:
except:
print("Exception")
os.mount(sd, "/sd")
vfs.mount(sd, "/sd")
print(os.listdir("/"))
os.unmount("/sd")

Wyświetl plik

@ -30,7 +30,7 @@ TEST_MAPPINGS = {
# Code to allow a target MicroPython to import an .mpy from RAM
injected_import_hook_code = """\
import sys, os, io
import sys, io, vfs
class __File(io.IOBase):
def __init__(self):
self.off = 0
@ -52,7 +52,7 @@ class __FS:
raise OSError(-2) # ENOENT
def open(self, path, mode):
return __File()
os.mount(__FS(), '/__remote')
vfs.mount(__FS(), '/__remote')
sys.path.insert(0, '/__remote')
sys.modules['{}'] = __import__('__injected')
"""

Wyświetl plik

@ -59,7 +59,7 @@ os.environ["PYTHONIOENCODING"] = "utf-8"
# Code to allow a target MicroPython to import an .mpy from RAM
injected_import_hook_code = """\
import sys, os, io
import sys, os, io, vfs
class __File(io.IOBase):
def __init__(self):
self.off = 0
@ -83,7 +83,7 @@ class __FS:
raise OSError(-2) # ENOENT
def open(self, path, mode):
return __File()
os.mount(__FS(), '/__vfstest')
vfs.mount(__FS(), '/__vfstest')
os.chdir('/__vfstest')
__import__('__injected_test')
"""