Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions python-stdlib/errno/errno.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion python-stdlib/errno/manifest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
metadata(version="0.2.0")
metadata(version="0.3.0")

module("errno.py")
38 changes: 38 additions & 0 deletions python-stdlib/errno/test_errno.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tools/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Loading