コード例 #1
0
ファイル: test_full_socket.py プロジェクト: inercia/evy
 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)
コード例 #2
0
ファイル: test_full_socket.py プロジェクト: inercia/evy
 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))
     self.assertEqual(cm.exception.errno, errno.ECONNREFUSED)
コード例 #3
0
ファイル: test_ssl.py プロジェクト: Cinnz/python
        def testRudeShutdown(self):

            listener_ready = threading.Event()
            listener_gone = threading.Event()
            port = test_support.find_unused_port()

            # `listener` runs in a thread.  It opens a socket listening on
            # PORT, and sits in an accept() until the main thread connects.
            # Then it rudely closes the socket, and sets Event `listener_gone`
            # to let the main thread know the socket is gone.
            def listener():
                s = socket.socket()
                s.bind((HOST, port))
                s.listen(5)
                listener_ready.set()
                s.accept()
                s = None  # reclaim the socket object, which also closes it
                listener_gone.set()

            def connector():
                listener_ready.wait()
                s = socket.socket()
                s.connect((HOST, port))
                listener_gone.wait()
                try:
                    ssl_sock = ssl.wrap_socket(s)
                except IOError:
                    pass
                else:
                    raise test_support.TestFailed("connecting to closed SSL socket should have failed")

            t = threading.Thread(target=listener)
            t.start()
            connector()
            t.join()
コード例 #4
0
 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)
コード例 #5
0
 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))
     self.assertEqual(cm.exception.errno, errno.ECONNREFUSED)
コード例 #6
0
ファイル: test_ssl.py プロジェクト: Cinnz/python
def test_main(verbose=False):
    if skip_expected:
        raise test_support.TestSkipped("No SSL support")

    global CERTFILE, SVN_PYTHON_ORG_ROOT_CERT
    CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "keycert.pem")
    SVN_PYTHON_ORG_ROOT_CERT = os.path.join(os.path.dirname(__file__) or os.curdir, "https_svn_python_org_root.pem")

    if not os.path.exists(CERTFILE) or not os.path.exists(SVN_PYTHON_ORG_ROOT_CERT):
        raise test_support.TestFailed("Can't read certificate files!")

    TESTPORT = test_support.find_unused_port()
    if not TESTPORT:
        raise test_support.TestFailed("Can't find open port to test servers on!")

    tests = [BasicTests]

    if test_support.is_resource_enabled("network"):
        tests.append(NetworkedTests)

    if _have_threads:
        thread_info = test_support.threading_setup()
        if thread_info and test_support.is_resource_enabled("network"):
            tests.append(ThreadedTests)

    test_support.run_unittest(*tests)

    if _have_threads:
        test_support.threading_cleanup(*thread_info)
コード例 #7
0
def test_main(verbose=False):
    if skip_expected:
        raise test_support.TestSkipped("No SSL support")

    global CERTFILE, SVN_PYTHON_ORG_ROOT_CERT
    CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir,
                            "keycert.pem")
    SVN_PYTHON_ORG_ROOT_CERT = os.path.join(
        os.path.dirname(__file__) or os.curdir,
        "https_svn_python_org_root.pem")

    if (not os.path.exists(CERTFILE) or
        not os.path.exists(SVN_PYTHON_ORG_ROOT_CERT)):
        raise test_support.TestFailed("Can't read certificate files!")

    TESTPORT = test_support.find_unused_port()
    if not TESTPORT:
        raise test_support.TestFailed("Can't find open port to test servers on!")

    tests = [BasicTests]

    if test_support.is_resource_enabled('network'):
        tests.append(NetworkedTests)

    if _have_threads:
        thread_info = test_support.threading_setup()
        if thread_info and test_support.is_resource_enabled('network'):
            tests.append(ThreadedTests)

    test_support.run_unittest(*tests)

    if _have_threads:
        test_support.threading_cleanup(*thread_info)
コード例 #8
0
ファイル: test_ssl.py プロジェクト: Cinnz/python
 def __init__(self, certfile):
     self.flag = None
     self.active = False
     self.RootedHTTPRequestHandler.root = os.path.split(CERTFILE)[0]
     self.port = test_support.find_unused_port()
     self.server = self.HTTPSServer((HOST, self.port), self.RootedHTTPRequestHandler, certfile)
     threading.Thread.__init__(self)
     self.daemon = True
コード例 #9
0
 def __init__(self, certfile):
     self.flag = None
     self.active = False
     self.RootedHTTPRequestHandler.root = os.path.split(CERTFILE)[0]
     self.port = test_support.find_unused_port()
     self.server = self.HTTPSServer(
         (HOST, self.port), self.RootedHTTPRequestHandler, certfile)
     threading.Thread.__init__(self)
     self.daemon = True
コード例 #10
0
ファイル: test_smtplib.py プロジェクト: pharrera/CS008
    def setUp(self):
        self.serv_evt = threading.Event()
        self.client_evt = threading.Event()
        self.port = test_support.find_unused_port()
        self.serv = SimSMTPServer((HOST, self.port), ('nowhere', -1))
        serv_args = (self.serv, self.serv_evt, self.client_evt)
        threading.Thread(target=debugging_server, args=serv_args).start()

        # wait until server thread has assigned a port number
        self.serv_evt.wait()
        self.serv_evt.clear()
コード例 #11
0
ファイル: test_smtplib.py プロジェクト: Vignesh2736/IncPy
    def setUp(self):
        self.serv_evt = threading.Event()
        self.client_evt = threading.Event()
        self.port = test_support.find_unused_port()
        self.serv = SimSMTPServer((HOST, self.port), ('nowhere', -1))
        serv_args = (self.serv, self.serv_evt, self.client_evt)
        threading.Thread(target=debugging_server, args=serv_args).start()

        # wait until server thread has assigned a port number
        self.serv_evt.wait()
        self.serv_evt.clear()
コード例 #12
0
ファイル: test_smtplib.py プロジェクト: pharrera/CS008
    def setUp(self):
        # temporarily replace sys.stdout to capture DebuggingServer output
        self.old_stdout = sys.stdout
        self.output = StringIO.StringIO()
        sys.stdout = self.output

        self.serv_evt = threading.Event()
        self.client_evt = threading.Event()
        self.port = test_support.find_unused_port()
        self.serv = smtpd.DebuggingServer((HOST, self.port), ('nowhere', -1))
        serv_args = (self.serv, self.serv_evt, self.client_evt)
        threading.Thread(target=debugging_server, args=serv_args).start()

        # wait until server thread has assigned a port number
        self.serv_evt.wait()
        self.serv_evt.clear()
コード例 #13
0
ファイル: test_smtplib.py プロジェクト: Vignesh2736/IncPy
    def setUp(self):
        # temporarily replace sys.stdout to capture DebuggingServer output
        self.old_stdout = sys.stdout
        self.output = StringIO.StringIO()
        sys.stdout = self.output

        self.serv_evt = threading.Event()
        self.client_evt = threading.Event()
        self.port = test_support.find_unused_port()
        self.serv = smtpd.DebuggingServer((HOST, self.port), ('nowhere', -1))
        serv_args = (self.serv, self.serv_evt, self.client_evt)
        threading.Thread(target=debugging_server, args=serv_args).start()

        # wait until server thread has assigned a port number
        self.serv_evt.wait()
        self.serv_evt.clear()
コード例 #14
0
        def testRudeShutdown(self):

            listener_ready = threading.Event()
            listener_gone = threading.Event()
            port = test_support.find_unused_port()

            # `listener` runs in a thread.  It opens a socket listening on
            # PORT, and sits in an accept() until the main thread connects.
            # Then it rudely closes the socket, and sets Event `listener_gone`
            # to let the main thread know the socket is gone.
            def listener():
                s = socket.socket()
                s.bind((HOST, port))
                s.listen(5)
                listener_ready.set()
                s.accept()
                s = None # reclaim the socket object, which also closes it
                listener_gone.set()

            def connector():
                listener_ready.wait()
                s = socket.socket()
                s.connect((HOST, port))
                listener_gone.wait()
                try:
                    ssl_sock = ssl.wrap_socket(s)
                except IOError:
                    pass
                else:
                    raise test_support.TestFailed(
                          'connecting to closed SSL socket should have failed')

            t = threading.Thread(target=listener)
            t.start()
            connector()
            t.join()
コード例 #15
0
 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
コード例 #16
0
 def clientSetUp(self):
     self.source_port = test_support.find_unused_port()
コード例 #17
0
ファイル: test_httplib.py プロジェクト: Kelauni22/Meeple
 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
コード例 #18
0
ファイル: test_socket.py プロジェクト: 1310701102/sl4a
 def testWithoutServer(self):
     port = test_support.find_unused_port()
     self.failUnlessRaises(
         socket.error,
         lambda: socket.create_connection((HOST, port))
     )
コード例 #19
0
ファイル: test_socket.py プロジェクト: slide/main
 def clientSetUp(self):
     self.source_port = test_support.find_unused_port()
コード例 #20
0
 def testWithoutServer(self):
     port = test_support.find_unused_port()
     self.failUnlessRaises(socket.error, lambda: socket.create_connection(
         (HOST, port)))