MCPcopy Index your code
hub / github.com/RustPython/RustPython / testSockName

Method testSockName

Lib/test/test_socket.py:1507–1534  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1505 # XXX The following don't test module-level functionality...
1506
1507 def testSockName(self):
1508 # Testing getsockname()
1509 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1510 self.addCleanup(sock.close)
1511
1512 # Since find_unused_port() is inherently subject to race conditions, we
1513 # call it a couple times if necessary.
1514 for i in itertools.count():
1515 port = socket_helper.find_unused_port()
1516 try:
1517 sock.bind(("0.0.0.0", port))
1518 except OSError as e:
1519 if e.errno != errno.EADDRINUSE or i == 5:
1520 raise
1521 else:
1522 break
1523
1524 name = sock.getsockname()
1525 # XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate
1526 # it reasonable to get the host's addr in addition to 0.0.0.0.
1527 # At least for eCos. This is required for the S/390 to pass.
1528 try:
1529 my_ip_addr = socket.gethostbyname(socket.gethostname())
1530 except OSError:
1531 # Probably name lookup wasn't set up right; skip this test
1532 self.skipTest('name lookup failure')
1533 self.assertIn(name[0], ("0.0.0.0", my_ip_addr), '%s invalid' % name[0])
1534 self.assertEqual(name[1], port)
1535
1536 def testGetSockOpt(self):
1537 # Testing getsockopt()

Callers

nothing calls this directly

Calls 8

socketMethod · 0.80
addCleanupMethod · 0.80
skipTestMethod · 0.80
assertInMethod · 0.80
countMethod · 0.45
bindMethod · 0.45
getsocknameMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected