MCPcopy
hub / github.com/python-trio/trio / test_init

Function test_init

src/trio/_tests/test_fakenet.py:288–317  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

286
287
288async def test_init() -> None:
289 fn()
290 with pytest.raises(
291 NotImplementedError,
292 match=re.escape(
293 f"FakeNet doesn't (yet) support type={trio.socket.SOCK_STREAM}",
294 ),
295 ):
296 s1 = trio.socket.socket()
297
298 # getsockname on unbound ipv4 socket
299 s1 = trio.socket.socket(type=trio.socket.SOCK_DGRAM)
300 assert s1.getsockname() == ("0.0.0.0", 0)
301
302 # getsockname on bound ipv4 socket
303 await s1.bind(("0.0.0.0", 0))
304 ip, port = s1.getsockname()
305 assert ip == "127.0.0.1"
306 assert port != 0
307
308 # getsockname on unbound ipv6 socket
309 s2 = trio.socket.socket(family=socket.AF_INET6, type=socket.SOCK_DGRAM)
310 assert s2.getsockname() == ("::", 0)
311
312 # getsockname on bound ipv6 socket
313 await s2.bind(("::", 0))
314 ip, port, *_ = s2.getsockname()
315 assert ip == "::1"
316 assert port != 0
317 assert _ == [0, 0]

Callers

nothing calls this directly

Calls 4

fnFunction · 0.70
socketMethod · 0.45
getsocknameMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…