diff --git a/python-stdlib/errno/errno.py b/python-stdlib/errno/errno.py index c513a7f14..91d844a80 100644 --- a/python-stdlib/errno/errno.py +++ b/python-stdlib/errno/errno.py @@ -32,8 +32,15 @@ EPIPE = 32 # Broken pipe EDOM = 33 # Math argument out of domain of func ERANGE = 34 # Math result not representable -EAFNOSUPPORT = 97 # Address family not supported by protocol -ECONNRESET = 104 # Connection timed out -ENOTCONN = 107 # Not connected +ECONNRESET = 104 # Connection reset by peer +ENOTCONN = 107 # Transport endpoint is not connected ETIMEDOUT = 110 # Connection timed out EINPROGRESS = 115 # Operation now in progress + +# Override the table above with the built-in module's values, which come from +# this port's system headers. The u-prefix reaches the built-in module. +try: + from uerrno import * +except ImportError: + # Built without MICROPY_PY_ERRNO. + pass diff --git a/python-stdlib/errno/manifest.py b/python-stdlib/errno/manifest.py index 075d3403d..3a71c2d82 100644 --- a/python-stdlib/errno/manifest.py +++ b/python-stdlib/errno/manifest.py @@ -1,3 +1,3 @@ -metadata(version="0.2.0") +metadata(version="0.3.0") module("errno.py") diff --git a/python-stdlib/errno/test_errno.py b/python-stdlib/errno/test_errno.py new file mode 100644 index 000000000..2b39257e5 --- /dev/null +++ b/python-stdlib/errno/test_errno.py @@ -0,0 +1,38 @@ +# The values the built-in errno module provides come from the system headers +# the port was built against, and they differ between operating systems and +# between architectures: ETIMEDOUT is 110 on Linux/x86, 145 on Linux/mips and +# 60 on macOS. This module must not override them with a table of its own. + +import errno + +try: + import uerrno +except ImportError: + # Built without MICROPY_PY_ERRNO, so there is nothing to compare against. + print("SKIP") + raise SystemExit + + +# Every name the built-in module provides has to come through unchanged. +names = [name for name in dir(uerrno) if name.startswith("E")] +assert names, dir(uerrno) +for name in names: + theirs = getattr(uerrno, name) + ours = getattr(errno, name, None) + assert ours is not None, "errno.%s is missing, uerrno.%s is %d" % (name, name, theirs) + assert ours == theirs, "errno.%s is %d, uerrno.%s is %d" % (name, ours, name, theirs) + +# errorcode has to survive too: mp_errno_to_str() looks names up in it, and it +# is what makes str(OSError(errno.ENOENT)) readable. +if hasattr(uerrno, "errorcode"): + assert isinstance(errno.errorcode, dict), errno.errorcode + for code, name in errno.errorcode.items(): + assert getattr(errno, name) == code, "errorcode[%d] is %s" % (code, name) + +# The names the built-in module does not provide are filled in by this module. +# Codes 1 to 34 are the same on every platform MicroPython runs on. +assert errno.EPERM == 1, errno.EPERM +assert errno.ESRCH == 3, errno.ESRCH +assert errno.ENOTBLK == 15, errno.ENOTBLK +assert errno.EDOM == 33, errno.EDOM +assert errno.ERANGE == 34, errno.ERANGE diff --git a/tools/ci.sh b/tools/ci.sh index 7ee7eb4d1..10f16b6ae 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -65,6 +65,7 @@ function ci_package_tests_run { python-stdlib/base64/test_base64.py \ python-stdlib/binascii/test_binascii.py \ python-stdlib/collections-defaultdict/test_defaultdict.py \ + python-stdlib/errno/test_errno.py \ python-stdlib/functools/test_partial.py \ python-stdlib/functools/test_reduce.py \ python-stdlib/heapq/test_heapq.py \