當前位置: 首頁>>代碼示例>>Python>>正文


Python test_support.find_unused_port方法代碼示例

本文整理匯總了Python中test.test_support.find_unused_port方法的典型用法代碼示例。如果您正苦於以下問題:Python test_support.find_unused_port方法的具體用法?Python test_support.find_unused_port怎麽用?Python test_support.find_unused_port使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在test.test_support的用法示例。


在下文中一共展示了test_support.find_unused_port方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_getsockaddrarg

# 需要導入模塊: from test import test_support [as 別名]
# 或者: from test.test_support import find_unused_port [as 別名]
def test_getsockaddrarg(self):
        sock = socket.socket()
        self.addCleanup(sock.close)
        port = test_support.find_unused_port()
        big_port = port + 65536
        neg_port = port - 65536
        self.assertRaises(OverflowError, sock.bind, (HOST, big_port))
        self.assertRaises(OverflowError, sock.bind, (HOST, neg_port))
        # Since find_unused_port() is inherently subject to race conditions, we
        # call it a couple times if necessary.
        for i in itertools.count():
            port = test_support.find_unused_port()
            try:
                sock.bind((HOST, port))
            except OSError as e:
                if e.errno != errno.EADDRINUSE or i == 5:
                    raise
            else:
                break 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_socket.py

示例2: test_connect

# 需要導入模塊: from test import test_support [as 別名]
# 或者: from test.test_support import find_unused_port [as 別名]
def test_connect(self):
        port = test_support.find_unused_port()
        cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.addCleanup(cli.close)
        with self.assertRaises(socket.error) as cm:
            cli.connect((HOST, port))
        self.assertEqual(cm.exception.errno, errno.ECONNREFUSED) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_socket.py

示例3: test_create_connection

# 需要導入模塊: from test import test_support [as 別名]
# 或者: from test.test_support import find_unused_port [as 別名]
def test_create_connection(self):
        # Issue #9792: errors raised by create_connection() should have
        # a proper errno attribute.
        port = test_support.find_unused_port()
        with self.assertRaises(socket.error) as cm:
            socket.create_connection((HOST, port))

        # Issue #16257: create_connection() calls getaddrinfo() against
        # 'localhost'.  This may result in an IPV6 addr being returned
        # as well as an IPV4 one:
        #   >>> socket.getaddrinfo('localhost', port, 0, SOCK_STREAM)
        #   >>> [(2,  2, 0, '', ('127.0.0.1', 41230)),
        #        (26, 2, 0, '', ('::1', 41230, 0, 0))]
        #
        # create_connection() enumerates through all the addresses returned
        # and if it doesn't successfully bind to any of them, it propagates
        # the last exception it encountered.
        #
        # On Solaris, ENETUNREACH is returned in this circumstance instead
        # of ECONNREFUSED.  So, if that errno exists, add it to our list of
        # expected errnos.
        expected_errnos = [ errno.ECONNREFUSED, ]
        if hasattr(errno, 'ENETUNREACH'):
            expected_errnos.append(errno.ENETUNREACH)
        if hasattr(errno, 'EADDRNOTAVAIL'):
            # bpo-31910: socket.create_connection() fails randomly
            # with EADDRNOTAVAIL on Travis CI
            expected_errnos.append(errno.EADDRNOTAVAIL)

        self.assertIn(cm.exception.errno, expected_errnos) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:32,代碼來源:test_socket.py

示例4: clientSetUp

# 需要導入模塊: from test import test_support [as 別名]
# 或者: from test.test_support import find_unused_port [as 別名]
def clientSetUp(self):
        self.source_port = test_support.find_unused_port() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:4,代碼來源:test_socket.py

示例5: setUp

# 需要導入模塊: from test import test_support [as 別名]
# 或者: from test.test_support import find_unused_port [as 別名]
def setUp(self):
        self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.port = test_support.bind_port(self.serv)
        self.source_port = test_support.find_unused_port()
        self.serv.listen(5)
        self.conn = None 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_httplib.py

示例6: test_create_connection

# 需要導入模塊: from test import test_support [as 別名]
# 或者: from test.test_support import find_unused_port [as 別名]
def test_create_connection(self):
        # Issue #9792: errors raised by create_connection() should have
        # a proper errno attribute.
        port = test_support.find_unused_port()
        with self.assertRaises(socket.error) as cm:
            socket.create_connection((HOST, port))

        # Issue #16257: create_connection() calls getaddrinfo() against
        # 'localhost'.  This may result in an IPV6 addr being returned
        # as well as an IPV4 one:
        #   >>> socket.getaddrinfo('localhost', port, 0, SOCK_STREAM)
        #   >>> [(2,  2, 0, '', ('127.0.0.1', 41230)),
        #        (26, 2, 0, '', ('::1', 41230, 0, 0))]
        #
        # create_connection() enumerates through all the addresses returned
        # and if it doesn't successfully bind to any of them, it propagates
        # the last exception it encountered.
        #
        # On Solaris, ENETUNREACH is returned in this circumstance instead
        # of ECONNREFUSED.  So, if that errno exists, add it to our list of
        # expected errnos.
        expected_errnos = [ errno.ECONNREFUSED, ]
        if hasattr(errno, 'ENETUNREACH'):
            expected_errnos.append(errno.ENETUNREACH)

        self.assertIn(cm.exception.errno, expected_errnos) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:28,代碼來源:test_socket.py


注:本文中的test.test_support.find_unused_port方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。