MCPcopy
hub / github.com/pyodide/pyodide / test_socket_getpeername

Function test_socket_getpeername

src/tests/test_python_socket.py:163–188  ·  view source on GitHub ↗

Test socket.getpeername() returns correct remote address.

(selenium_nodesock)

Source from the content-addressed store, hash-verified

161
162
163def test_socket_getpeername(selenium_nodesock):
164 """Test socket.getpeername() returns correct remote address."""
165
166 def handler(conn, _addr):
167 conn.recv(1024)
168 conn.sendall(b"OK")
169
170 @run_in_pyodide
171 def run(selenium, host, port):
172 import socket
173
174 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
175 s.connect((host, port))
176
177 peer = s.getpeername()
178 s.sendall(b"test")
179 s.recv(1024)
180 s.close()
181 return peer
182
183 with tcp_server(handler) as (host, port):
184 result = run(selenium_nodesock, host, port)
185 assert result[1] == port
186 assert isinstance(result[0], str) and len(result[0]) > 0, (
187 f"Expected non-empty host string, got: {result[0]}"
188 )
189
190
191def test_socket_getsockname(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…