mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 03:30:14 +01:00
tests/cpydiff: Document lack of OSError errno subtype mapping.
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
This commit is contained in:
committed by
Damien George
parent
7630ef0240
commit
8e6cd4b58e
48
tests/cpydiff/types_oserror_errnomap.py
Normal file
48
tests/cpydiff/types_oserror_errnomap.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
categories: Types,OSError
|
||||
description: OSError constructor returns a plain OSError for all errno values, rather than a relevant subtype.
|
||||
cause: MicroPython does not include the CPython-standard OSError subclasses.
|
||||
workaround: Catch OSError and use its errno attribute to discriminate the cause.
|
||||
"""
|
||||
|
||||
import errno
|
||||
|
||||
errno_list = [ # i.e. the set implemented by micropython
|
||||
errno.EPERM,
|
||||
errno.ENOENT,
|
||||
errno.EIO,
|
||||
errno.EBADF,
|
||||
errno.EAGAIN,
|
||||
errno.ENOMEM,
|
||||
errno.EACCES,
|
||||
errno.EEXIST,
|
||||
errno.ENODEV,
|
||||
errno.EISDIR,
|
||||
errno.EINVAL,
|
||||
errno.EOPNOTSUPP,
|
||||
errno.EADDRINUSE,
|
||||
errno.ECONNABORTED,
|
||||
errno.ECONNRESET,
|
||||
errno.ENOBUFS,
|
||||
errno.ENOTCONN,
|
||||
errno.ETIMEDOUT,
|
||||
errno.ECONNREFUSED,
|
||||
errno.EHOSTUNREACH,
|
||||
errno.EALREADY,
|
||||
errno.EINPROGRESS,
|
||||
]
|
||||
|
||||
|
||||
def errno_output_type(n):
|
||||
try:
|
||||
raise OSError(n, "")
|
||||
except OSError as e:
|
||||
return f"{type(e).__name__}"
|
||||
except Exception as e:
|
||||
return f"non-OSError {type(e).__name__}"
|
||||
else:
|
||||
return "no error"
|
||||
|
||||
|
||||
for n in errno_list:
|
||||
print(errno.errorcode[n], "=", errno_output_type(n))
|
||||
Reference in New Issue
Block a user