MCPcopy
hub / github.com/pyodide/pyodide / test_socket_getsockname

Function test_socket_getsockname

src/tests/test_python_socket.py:191–215  ·  view source on GitHub ↗

Test socket.getsockname() returns local address info.

(selenium_nodesock)

Source from the content-addressed store, hash-verified

189
190
191def test_socket_getsockname(selenium_nodesock):
192 """Test socket.getsockname() returns local address info."""
193
194 def handler(conn, _addr):
195 conn.recv(1024)
196 conn.sendall(b"OK")
197
198 @run_in_pyodide
199 def run(selenium, host, port):
200 import socket
201
202 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
203 s.connect((host, port))
204
205 local = s.getsockname()
206 s.sendall(b"test")
207 s.recv(1024)
208 s.close()
209 return local
210
211 with tcp_server(handler) as (host, port):
212 result = run(selenium_nodesock, host, port)
213 assert len(result) == 2
214 assert isinstance(result[0], str) # IP
215 assert isinstance(result[1], int) # Port
216
217
218def test_socket_connection_refused(selenium_nodesock):

Callers

nothing calls this directly

Calls 2

tcp_serverFunction · 0.85
runFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…