tests/extmod/vfs_lfs_error.py: Test value of all OSError's errno.

To make sure they have the correct value.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-05-13 12:55:01 +10:00
parent 62d26bfc15
commit 44bcfe53de
2 changed files with 45 additions and 45 deletions

View File

@@ -1,7 +1,7 @@
# Test for VfsLittle using a RAM device, testing error handling # Test for VfsLittle using a RAM device, testing error handling
try: try:
import vfs import errno, vfs
vfs.VfsLfs1 vfs.VfsLfs1
vfs.VfsLfs2 vfs.VfsLfs2
@@ -41,14 +41,14 @@ def test(bdev, vfs_class):
# mkfs with too-small block device # mkfs with too-small block device
try: try:
vfs_class.mkfs(RAMBlockDevice(1)) vfs_class.mkfs(RAMBlockDevice(1))
except OSError: except OSError as er:
print("mkfs OSError") print("mkfs OSError", er.errno > 0)
# mount with invalid filesystem # mount with invalid filesystem
try: try:
vfs_class(bdev) vfs_class(bdev)
except OSError: except OSError as er:
print("mount OSError") print("mount OSError", er.errno > 0)
# set up for following tests # set up for following tests
vfs_class.mkfs(bdev) vfs_class.mkfs(bdev)
@@ -60,60 +60,60 @@ def test(bdev, vfs_class):
# ilistdir # ilistdir
try: try:
fs.ilistdir("noexist") fs.ilistdir("noexist")
except OSError: except OSError as er:
print("ilistdir OSError") print("ilistdir OSError", er)
# remove # remove
try: try:
fs.remove("noexist") fs.remove("noexist")
except OSError: except OSError as er:
print("remove OSError") print("remove OSError", er)
# rmdir # rmdir
try: try:
fs.rmdir("noexist") fs.rmdir("noexist")
except OSError: except OSError as er:
print("rmdir OSError") print("rmdir OSError", er)
# rename # rename
try: try:
fs.rename("noexist", "somethingelse") fs.rename("noexist", "somethingelse")
except OSError: except OSError as er:
print("rename OSError") print("rename OSError", er)
# mkdir # mkdir
try: try:
fs.mkdir("testdir") fs.mkdir("testdir")
except OSError: except OSError as er:
print("mkdir OSError") print("mkdir OSError", er)
# chdir to nonexistent # chdir to nonexistent
try: try:
fs.chdir("noexist") fs.chdir("noexist")
except OSError: except OSError as er:
print("chdir OSError") print("chdir OSError", er)
print(fs.getcwd()) # check still at root print(fs.getcwd()) # check still at root
# chdir to file # chdir to file
try: try:
fs.chdir("testfile") fs.chdir("testfile")
except OSError: except OSError as er:
print("chdir OSError") print("chdir OSError", er)
print(fs.getcwd()) # check still at root print(fs.getcwd()) # check still at root
# stat # stat
try: try:
fs.stat("noexist") fs.stat("noexist")
except OSError: except OSError as er:
print("stat OSError") print("stat OSError", er)
# error during seek # error during seek
with fs.open("testfile", "r") as f: with fs.open("testfile", "r") as f:
f.seek(1 << 30) # SEEK_SET f.seek(1 << 30) # SEEK_SET
try: try:
f.seek(1 << 30, 1) # SEEK_CUR f.seek(1 << 30, 1) # SEEK_CUR
except OSError: except OSError as er:
print("seek OSError") print("seek OSError", er)
bdev = RAMBlockDevice(30) bdev = RAMBlockDevice(30)

View File

@@ -1,28 +1,28 @@
test <class 'VfsLfs1'> test <class 'VfsLfs1'>
mkfs OSError mkfs OSError True
mount OSError mount OSError True
ilistdir OSError ilistdir OSError [Errno 2] ENOENT
remove OSError remove OSError [Errno 2] ENOENT
rmdir OSError rmdir OSError [Errno 2] ENOENT
rename OSError rename OSError [Errno 2] ENOENT
mkdir OSError mkdir OSError [Errno 17] EEXIST
chdir OSError chdir OSError [Errno 2] ENOENT
/ /
chdir OSError chdir OSError [Errno 2] ENOENT
/ /
stat OSError stat OSError [Errno 2] ENOENT
seek OSError seek OSError [Errno 22] EINVAL
test <class 'VfsLfs2'> test <class 'VfsLfs2'>
mkfs OSError mkfs OSError True
mount OSError mount OSError True
ilistdir OSError ilistdir OSError [Errno 2] ENOENT
remove OSError remove OSError [Errno 2] ENOENT
rmdir OSError rmdir OSError [Errno 2] ENOENT
rename OSError rename OSError [Errno 2] ENOENT
mkdir OSError mkdir OSError [Errno 17] EEXIST
chdir OSError chdir OSError [Errno 2] ENOENT
/ /
chdir OSError chdir OSError [Errno 2] ENOENT
/ /
stat OSError stat OSError [Errno 2] ENOENT
seek OSError seek OSError [Errno 22] EINVAL