summaryrefslogtreecommitdiff
path: root/tests/extmod/select_poll_basic.py
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2022-08-18 16:57:45 +1000
committerJim Mussared <jim.mussared@gmail.com>2023-06-08 17:54:24 +1000
commit4216bc7d1351feb8199e4ebbff1a9598aa1c5b02 (patch)
tree5085738ef65ab377c221f290c7fa90ec2acd4d29 /tests/extmod/select_poll_basic.py
parent5e50975a6dd9466afafbcd012c00078093fe1f57 (diff)
tests: Replace umodule with module everywhere.
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'tests/extmod/select_poll_basic.py')
-rw-r--r--tests/extmod/select_poll_basic.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/extmod/select_poll_basic.py b/tests/extmod/select_poll_basic.py
new file mode 100644
index 000000000..b36e16f01
--- /dev/null
+++ b/tests/extmod/select_poll_basic.py
@@ -0,0 +1,39 @@
+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 that’s 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.errno == errno.ENOENT
+
+# poll after closing the socket, should return POLLNVAL
+poller.register(s)
+s.close()
+p = poller.poll(0)
+print(len(p), p[0][-1])