PythonExtra/tests/extmod/uselect_poll_basic.py
stijn 06643a0df4 tests/extmod: Skip uselect test when CPython doesn't have poll().
CPython does not have an implementation of select.poll() on some
operating systems (Windows, OSX depending on version) so skip the
test in those cases instead of failing it.
2018-10-30 14:49:23 +11:00

36 lines
887 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

try:
import usocket as socket, uselect as select, uerrno as errno
except ImportError:
try:
import socket, select, errno
select.poll # Raises AttributeError for CPython implementations without poll()
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
poller = select.poll()
s = socket.socket()
poller.register(s)
# https://docs.python.org/3/library/select.html#select.poll.register
# "Registering a file descriptor thats already registered is not an error,
# and has the same effect as registering the descriptor exactly once."
poller.register(s)
# 2 args are mandatory unlike register()
try:
poller.modify(s)
except TypeError:
print("modify:TypeError")
poller.modify(s, select.POLLIN)
poller.unregister(s)
try:
poller.modify(s, select.POLLIN)
except OSError as e:
assert e.args[0] == errno.ENOENT