MCPcopy Index your code
hub / github.com/python/cpython / testSockName

Method testSockName

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

Source from the content-addressed store, hash-verified

1522 # XXX The following don't test module-level functionality...
1523
1524 def testSockName(self):
1525 # Testing getsockname()
1526 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1527 self.addCleanup(sock.close)
1528
1529 # Since find_unused_port() is inherently subject to race conditions, we
1530 # call it a couple times if necessary.
1531 for i in itertools.count():
1532 port = socket_helper.find_unused_port()
1533 try:
1534 sock.bind(("0.0.0.0", port))
1535 except OSError as e:
1536 if e.errno != errno.EADDRINUSE or i == 5:
1537 raise
1538 else:
1539 break
1540
1541 name = sock.getsockname()
1542 # XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate
1543 # it reasonable to get the host's addr in addition to 0.0.0.0.
1544 # At least for eCos. This is required for the S/390 to pass.
1545 try:
1546 my_ip_addr = socket.gethostbyname(socket.gethostname())
1547 except OSError:
1548 # Probably name lookup wasn't set up right; skip this test
1549 self.skipTest('name lookup failure')
1550 self.assertIn(name[0], ("0.0.0.0", my_ip_addr), '%s invalid' % name[0])
1551 self.assertEqual(name[1], port)
1552
1553 def testGetSockOpt(self):
1554 # 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