mirror of
https://github.com/python/cpython.git
synced 2024-12-25 09:44:37 +08:00
836baa53d8
svn+ssh://pythondev@svn.python.org/python/trunk ........ r61063 | andrew.kuchling | 2008-02-25 17:29:19 +0100 (Mon, 25 Feb 2008) | 1 line Move .setupterm() output so that we don't try to call endwin() if it fails ........ r61064 | andrew.kuchling | 2008-02-25 17:29:58 +0100 (Mon, 25 Feb 2008) | 1 line Use file descriptor for real stdout ........ r61067 | facundo.batista | 2008-02-25 19:06:00 +0100 (Mon, 25 Feb 2008) | 4 lines Issue 2117. Update compiler module to handle class decorators. Thanks Thomas Herve ........ r61069 | georg.brandl | 2008-02-25 21:17:56 +0100 (Mon, 25 Feb 2008) | 2 lines Rename sphinx.addons to sphinx.ext. ........ r61071 | georg.brandl | 2008-02-25 21:20:45 +0100 (Mon, 25 Feb 2008) | 2 lines Revert r61029. ........ r61072 | facundo.batista | 2008-02-25 23:33:55 +0100 (Mon, 25 Feb 2008) | 4 lines Issue 2168. gdbm and dbm needs to be iterable; this fixes a failure in the shelve module. Thanks Thomas Herve. ........ r61073 | raymond.hettinger | 2008-02-25 23:42:32 +0100 (Mon, 25 Feb 2008) | 1 line Make sure the itertools filter functions give the same performance for func=bool as func=None. ........ r61074 | raymond.hettinger | 2008-02-26 00:17:41 +0100 (Tue, 26 Feb 2008) | 1 line Revert part of r60927 which made invalid assumptions about the API offered by db modules. ........ r61075 | facundo.batista | 2008-02-26 00:46:02 +0100 (Tue, 26 Feb 2008) | 3 lines Coerced PyBool_Type to be able to compare it. ........ r61076 | raymond.hettinger | 2008-02-26 03:46:54 +0100 (Tue, 26 Feb 2008) | 1 line Docs for itertools.combinations(). Implementation in forthcoming checkin. ........ r61077 | neal.norwitz | 2008-02-26 05:50:37 +0100 (Tue, 26 Feb 2008) | 3 lines Don't use a hard coded port. This test could hang/fail if the port is in use. Speed this test up by avoiding a sleep and using the event. ........ r61078 | neal.norwitz | 2008-02-26 06:12:50 +0100 (Tue, 26 Feb 2008) | 1 line Whitespace normalization ........ r61079 | neal.norwitz | 2008-02-26 06:23:51 +0100 (Tue, 26 Feb 2008) | 1 line Whitespace normalization ........ r61080 | georg.brandl | 2008-02-26 07:40:10 +0100 (Tue, 26 Feb 2008) | 2 lines Banish tab. ........
116 lines
3.1 KiB
Python
116 lines
3.1 KiB
Python
import socket
|
|
import threading
|
|
import ftplib
|
|
import time
|
|
|
|
from unittest import TestCase
|
|
from test import test_support
|
|
|
|
server_port = None
|
|
|
|
# This function sets the evt 3 times:
|
|
# 1) when the connection is ready to be accepted.
|
|
# 2) when it is safe for the caller to close the connection
|
|
# 3) when we have closed the socket
|
|
def server(evt):
|
|
global server_port
|
|
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
serv.settimeout(3)
|
|
serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
server_port = test_support.bind_port(serv, "", 9091)
|
|
serv.listen(5)
|
|
|
|
# (1) Signal the caller that we are ready to accept the connection.
|
|
evt.set()
|
|
try:
|
|
conn, addr = serv.accept()
|
|
except socket.timeout:
|
|
pass
|
|
else:
|
|
conn.send(b"1 Hola mundo\n")
|
|
# (2) Signal the caller that it is safe to close the socket.
|
|
evt.set()
|
|
conn.close()
|
|
finally:
|
|
serv.close()
|
|
# (3) Signal the caller that we are done.
|
|
evt.set()
|
|
|
|
class GeneralTests(TestCase):
|
|
|
|
def setUp(self):
|
|
self.evt = threading.Event()
|
|
threading.Thread(target=server, args=(self.evt,)).start()
|
|
# Wait for the server to be ready.
|
|
self.evt.wait()
|
|
self.evt.clear()
|
|
ftplib.FTP.port = server_port
|
|
|
|
def tearDown(self):
|
|
# Wait on the closing of the socket (this shouldn't be necessary).
|
|
self.evt.wait()
|
|
|
|
def testBasic(self):
|
|
# do nothing
|
|
ftplib.FTP()
|
|
|
|
# connects
|
|
ftp = ftplib.FTP("localhost")
|
|
self.evt.wait()
|
|
ftp.sock.close()
|
|
|
|
def testTimeoutDefault(self):
|
|
# default
|
|
ftp = ftplib.FTP("localhost")
|
|
self.assertTrue(ftp.sock.gettimeout() is None)
|
|
self.evt.wait()
|
|
ftp.sock.close()
|
|
|
|
def testTimeoutValue(self):
|
|
# a value
|
|
ftp = ftplib.FTP("localhost", timeout=30)
|
|
self.assertEqual(ftp.sock.gettimeout(), 30)
|
|
self.evt.wait()
|
|
ftp.sock.close()
|
|
|
|
def testTimeoutConnect(self):
|
|
ftp = ftplib.FTP()
|
|
ftp.connect("localhost", timeout=30)
|
|
self.assertEqual(ftp.sock.gettimeout(), 30)
|
|
self.evt.wait()
|
|
ftp.sock.close()
|
|
|
|
def testTimeoutDifferentOrder(self):
|
|
ftp = ftplib.FTP(timeout=30)
|
|
ftp.connect("localhost")
|
|
self.assertEqual(ftp.sock.gettimeout(), 30)
|
|
self.evt.wait()
|
|
ftp.sock.close()
|
|
|
|
def testTimeoutDirectAccess(self):
|
|
ftp = ftplib.FTP()
|
|
ftp.timeout = 30
|
|
ftp.connect("localhost")
|
|
self.assertEqual(ftp.sock.gettimeout(), 30)
|
|
self.evt.wait()
|
|
ftp.sock.close()
|
|
|
|
def testTimeoutNone(self):
|
|
# None, having other default
|
|
previous = socket.getdefaulttimeout()
|
|
socket.setdefaulttimeout(30)
|
|
try:
|
|
ftp = ftplib.FTP("localhost", timeout=None)
|
|
finally:
|
|
socket.setdefaulttimeout(previous)
|
|
self.assertEqual(ftp.sock.gettimeout(), 30)
|
|
self.evt.wait()
|
|
ftp.close()
|
|
|
|
|
|
def test_main(verbose=None):
|
|
test_support.run_unittest(GeneralTests)
|
|
|
|
if __name__ == '__main__':
|
|
test_main()
|