summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_datetime.py4
-rw-r--r--Lib/test/test_ftplib.py43
-rw-r--r--Lib/test/test_httplib.py29
-rw-r--r--Lib/test/test_math.py2
-rw-r--r--Lib/test/test_poplib.py25
-rw-r--r--Lib/test/test_smtplib.py34
-rw-r--r--Lib/test/test_socket.py32
-rw-r--r--Lib/test/test_telnetlib.py34
-rw-r--r--Lib/test/test_urllib.py40
-rw-r--r--Lib/test/test_urllib2.py8
-rw-r--r--Lib/test/test_urllib2net.py46
11 files changed, 172 insertions, 125 deletions
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index 2048fa0..4b8ae82 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -845,9 +845,13 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
self.assertRaises(TypeError, t.strftime, "one", "two") # too many args
self.assertRaises(TypeError, t.strftime, 42) # arg wrong type
+ # test that unicode input is allowed (issue 2782)
+ self.assertEqual(t.strftime("%m"), "03")
+
# A naive object replaces %z and %Z w/ empty strings.
self.assertEqual(t.strftime("'%z' '%Z'"), "'' ''")
+
def test_format(self):
dt = self.theclass(2007, 9, 10)
self.assertEqual(dt.__format__(''), str(dt))
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index b91588a..35e4746 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -54,35 +54,52 @@ class GeneralTests(TestCase):
# connects
ftp = ftplib.FTP(HOST)
self.evt.wait()
- ftp.sock.close()
+ ftp.close()
def testTimeoutDefault(self):
- # default
- ftp = ftplib.FTP(HOST)
+ # default -- use global socket timeout
+ self.assert_(socket.getdefaulttimeout() is None)
+ socket.setdefaulttimeout(30)
+ try:
+ ftp = ftplib.FTP("localhost")
+ finally:
+ socket.setdefaulttimeout(None)
+ self.assertEqual(ftp.sock.gettimeout(), 30)
+ self.evt.wait()
+ ftp.close()
+
+ def testTimeoutNone(self):
+ # no timeout -- do not use global socket timeout
+ self.assert_(socket.getdefaulttimeout() is None)
+ socket.setdefaulttimeout(30)
+ try:
+ ftp = ftplib.FTP("localhost", timeout=None)
+ finally:
+ socket.setdefaulttimeout(None)
self.assertTrue(ftp.sock.gettimeout() is None)
self.evt.wait()
- ftp.sock.close()
+ ftp.close()
def testTimeoutValue(self):
# a value
ftp = ftplib.FTP(HOST, timeout=30)
self.assertEqual(ftp.sock.gettimeout(), 30)
self.evt.wait()
- ftp.sock.close()
+ ftp.close()
def testTimeoutConnect(self):
ftp = ftplib.FTP()
ftp.connect(HOST, timeout=30)
self.assertEqual(ftp.sock.gettimeout(), 30)
self.evt.wait()
- ftp.sock.close()
+ ftp.close()
def testTimeoutDifferentOrder(self):
ftp = ftplib.FTP(timeout=30)
ftp.connect(HOST)
self.assertEqual(ftp.sock.gettimeout(), 30)
self.evt.wait()
- ftp.sock.close()
+ ftp.close()
def testTimeoutDirectAccess(self):
ftp = ftplib.FTP()
@@ -90,18 +107,6 @@ class GeneralTests(TestCase):
ftp.connect(HOST)
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(HOST, timeout=None)
- finally:
- socket.setdefaulttimeout(previous)
- self.assertEqual(ftp.sock.gettimeout(), 30)
- self.evt.wait()
ftp.close()
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index ff4cf9b..054825a 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -215,27 +215,32 @@ class TimeoutTest(TestCase):
# This will prove that the timeout gets through HTTPConnection
# and into the socket.
- # default
- httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT)
- httpConn.connect()
- self.assertTrue(httpConn.sock.gettimeout() is None)
- httpConn.close()
-
- # a value
- httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT, timeout=30)
- httpConn.connect()
+ # default -- use global socket timeout
+ self.assert_(socket.getdefaulttimeout() is None)
+ socket.setdefaulttimeout(30)
+ try:
+ httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT)
+ httpConn.connect()
+ finally:
+ socket.setdefaulttimeout(None)
self.assertEqual(httpConn.sock.gettimeout(), 30)
httpConn.close()
- # None, having other default
- previous = socket.getdefaulttimeout()
+ # no timeout -- do not use global socket default
+ self.assert_(socket.getdefaulttimeout() is None)
socket.setdefaulttimeout(30)
try:
httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT,
timeout=None)
httpConn.connect()
finally:
- socket.setdefaulttimeout(previous)
+ socket.setdefaulttimeout(None)
+ self.assertEqual(httpConn.sock.gettimeout(), None)
+ httpConn.close()
+
+ # a value
+ httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT, timeout=30)
+ httpConn.connect()
self.assertEqual(httpConn.sock.gettimeout(), 30)
httpConn.close()
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index ae29cda..f4c27bb 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -736,7 +736,7 @@ class MathTests(unittest.TestCase):
OverflowError),
([2.**1023, 2.**1023, -1e307], OverflowError),
([1e16, 1., 1e-16], 10000000000000002.0),
- ([1e16-2., 1.-2.**53, -(1e16-2.), -(1.-2.**53)], 0.0),
+ ([1e16-2., 1.-2.**-53, -(1e16-2.), -(1.-2.**-53)], 0.0),
]
for i, (vals, s) in enumerate(test_values):
diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py
index 14b46e3..f9c52f9 100644
--- a/Lib/test/test_poplib.py
+++ b/Lib/test/test_poplib.py
@@ -40,28 +40,29 @@ class GeneralTests(TestCase):
pop.sock.close()
def testTimeoutDefault(self):
- # default
- pop = poplib.POP3(HOST, self.port)
- self.assertTrue(pop.sock.gettimeout() is None)
- pop.sock.close()
-
- def testTimeoutValue(self):
- # a value
- pop = poplib.POP3(HOST, self.port, timeout=30)
+ self.assertTrue(socket.getdefaulttimeout() is None)
+ socket.setdefaulttimeout(30)
+ try:
+ pop = poplib.POP3("localhost", self.port)
+ finally:
+ socket.setdefaulttimeout(None)
self.assertEqual(pop.sock.gettimeout(), 30)
pop.sock.close()
def testTimeoutNone(self):
- # None, having other default
- previous = socket.getdefaulttimeout()
+ self.assertTrue(socket.getdefaulttimeout() is None)
socket.setdefaulttimeout(30)
try:
pop = poplib.POP3(HOST, self.port, timeout=None)
finally:
- socket.setdefaulttimeout(previous)
- self.assertEqual(pop.sock.gettimeout(), 30)
+ socket.setdefaulttimeout(None)
+ self.assertTrue(pop.sock.gettimeout() is None)
pop.sock.close()
+ def testTimeoutValue(self):
+ pop = poplib.POP3("localhost", self.port, timeout=30)
+ self.assertEqual(pop.sock.gettimeout(), 30)
+ pop.sock.close()
def test_main(verbose=None):
diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py
index 3d38d89..8130252 100644
--- a/Lib/test/test_smtplib.py
+++ b/Lib/test/test_smtplib.py
@@ -54,41 +54,43 @@ class GeneralTests(TestCase):
def testBasic1(self):
# connects
smtp = smtplib.SMTP(HOST, self.port)
- smtp.sock.close()
+ smtp.close()
def testBasic2(self):
# connects, include port in host name
smtp = smtplib.SMTP("%s:%s" % (HOST, self.port))
- smtp.sock.close()
+ smtp.close()
def testLocalHostName(self):
# check that supplied local_hostname is used
smtp = smtplib.SMTP(HOST, self.port, local_hostname="testhost")
self.assertEqual(smtp.local_hostname, "testhost")
- smtp.sock.close()
+ smtp.close()
def testTimeoutDefault(self):
- # default
- smtp = smtplib.SMTP(HOST, self.port)
- self.assertTrue(smtp.sock.gettimeout() is None)
- smtp.sock.close()
-
- def testTimeoutValue(self):
- # a value
- smtp = smtplib.SMTP(HOST, self.port, timeout=30)
+ self.assertTrue(socket.getdefaulttimeout() is None)
+ socket.setdefaulttimeout(30)
+ try:
+ smtp = smtplib.SMTP(HOST, self.port)
+ finally:
+ socket.setdefaulttimeout(None)
self.assertEqual(smtp.sock.gettimeout(), 30)
- smtp.sock.close()
+ smtp.close()
def testTimeoutNone(self):
- # None, having other default
- previous = socket.getdefaulttimeout()
+ self.assertTrue(socket.getdefaulttimeout() is None)
socket.setdefaulttimeout(30)
try:
smtp = smtplib.SMTP(HOST, self.port, timeout=None)
finally:
- socket.setdefaulttimeout(previous)
+ socket.setdefaulttimeout(None)
+ self.assertTrue(smtp.sock.gettimeout() is None)
+ smtp.close()
+
+ def testTimeoutValue(self):
+ smtp = smtplib.SMTP(HOST, self.port, timeout=30)
self.assertEqual(smtp.sock.gettimeout(), 30)
- smtp.sock.close()
+ smtp.close()
# Test server thread using the specified SMTP server class
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index d664582..e62788e 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -929,8 +929,25 @@ class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest):
testTimeoutDefault = _justAccept
def _testTimeoutDefault(self):
- self.cli = socket.create_connection((HOST, self.port))
- self.assertTrue(self.cli.gettimeout() is None)
+ # passing no explicit timeout uses socket's global default
+ self.assert_(socket.getdefaulttimeout() is None)
+ socket.setdefaulttimeout(42)
+ try:
+ self.cli = socket.create_connection((HOST, self.port))
+ finally:
+ socket.setdefaulttimeout(None)
+ self.assertEquals(self.cli.gettimeout(), 42)
+
+ testTimeoutNone = _justAccept
+ def _testTimeoutNone(self):
+ # None timeout means the same as sock.settimeout(None)
+ self.assert_(socket.getdefaulttimeout() is None)
+ socket.setdefaulttimeout(30)
+ try:
+ self.cli = socket.create_connection((HOST, self.port), timeout=None)
+ finally:
+ socket.setdefaulttimeout(None)
+ self.assertEqual(self.cli.gettimeout(), None)
testTimeoutValueNamed = _justAccept
def _testTimeoutValueNamed(self):
@@ -942,17 +959,6 @@ class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest):
self.cli = socket.create_connection((HOST, self.port), 30)
self.assertEqual(self.cli.gettimeout(), 30)
- testTimeoutNone = _justAccept
- def _testTimeoutNone(self):
- previous = socket.getdefaulttimeout()
- socket.setdefaulttimeout(30)
- try:
- self.cli = socket.create_connection((HOST, self.port), timeout=None)
- finally:
- socket.setdefaulttimeout(previous)
- self.assertEqual(self.cli.gettimeout(), 30)
-
-
class NetworkConnectionBehaviourTest(SocketTCPTest, ThreadableTest):
def __init__(self, methodName='runTest'):
diff --git a/Lib/test/test_telnetlib.py b/Lib/test/test_telnetlib.py
index c24d41d..4ae6222 100644
--- a/Lib/test/test_telnetlib.py
+++ b/Lib/test/test_telnetlib.py
@@ -40,34 +40,36 @@ class GeneralTests(TestCase):
telnet.sock.close()
def testTimeoutDefault(self):
- # default
- telnet = telnetlib.Telnet(HOST, self.port)
- self.assertTrue(telnet.sock.gettimeout() is None)
- telnet.sock.close()
-
- def testTimeoutValue(self):
- # a value
- telnet = telnetlib.Telnet(HOST, self.port, timeout=30)
- self.assertEqual(telnet.sock.gettimeout(), 30)
- telnet.sock.close()
-
- def testTimeoutDifferentOrder(self):
- telnet = telnetlib.Telnet(timeout=30)
- telnet.open(HOST, self.port)
+ self.assertTrue(socket.getdefaulttimeout() is None)
+ socket.setdefaulttimeout(30)
+ try:
+ telnet = telnetlib.Telnet("localhost", self.port)
+ finally:
+ socket.setdefaulttimeout(None)
self.assertEqual(telnet.sock.gettimeout(), 30)
telnet.sock.close()
def testTimeoutNone(self):
# None, having other default
- previous = socket.getdefaulttimeout()
+ self.assertTrue(socket.getdefaulttimeout() is None)
socket.setdefaulttimeout(30)
try:
telnet = telnetlib.Telnet(HOST, self.port, timeout=None)
finally:
- socket.setdefaulttimeout(previous)
+ socket.setdefaulttimeout(None)
+ self.assertTrue(telnet.sock.gettimeout() is None)
+ telnet.sock.close()
+
+ def testTimeoutValue(self):
+ telnet = telnetlib.Telnet("localhost", self.port, timeout=30)
self.assertEqual(telnet.sock.gettimeout(), 30)
telnet.sock.close()
+ def testTimeoutOpen(self):
+ telnet = telnetlib.Telnet()
+ telnet.open("localhost", self.port, timeout=30)
+ self.assertEqual(telnet.sock.gettimeout(), 30)
+ telnet.sock.close()
def test_main(verbose=None):
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index b14510f..26b51cb 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -568,6 +568,7 @@ class Pathname_Tests(unittest.TestCase):
# . Facundo
#
# def server(evt):
+# import socket, time
# serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# serv.settimeout(3)
# serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@@ -592,6 +593,7 @@ class Pathname_Tests(unittest.TestCase):
# class FTPWrapperTests(unittest.TestCase):
#
# def setUp(self):
+# import ftplib, time, threading
# ftplib.FTP.port = 9093
# self.evt = threading.Event()
# threading.Thread(target=server, args=(self.evt,)).start()
@@ -603,31 +605,37 @@ class Pathname_Tests(unittest.TestCase):
# def testBasic(self):
# # connects
# ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
-# ftp.ftp.sock.close()
+# ftp.close()
#
-# def testTimeoutDefault(self):
-# # default
-# ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
-# self.assertTrue(ftp.ftp.sock.gettimeout() is None)
-# ftp.ftp.sock.close()
-#
-# def testTimeoutValue(self):
-# # a value
-# ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [], timeout=30)
+# def testTimeoutNone(self):
+# # global default timeout is ignored
+# import socket
+# self.assert_(socket.getdefaulttimeout() is None)
+# socket.setdefaulttimeout(30)
+# try:
+# ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
+# finally:
+# socket.setdefaulttimeout(None)
# self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
-# ftp.ftp.sock.close()
+# ftp.close()
#
-# def testTimeoutNone(self):
-# # None, having other default
-# previous = socket.getdefaulttimeout()
+# def testTimeoutDefault(self):
+# # global default timeout is used
+# import socket
+# self.assert_(socket.getdefaulttimeout() is None)
# socket.setdefaulttimeout(30)
# try:
# ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
# finally:
-# socket.setdefaulttimeout(previous)
+# socket.setdefaulttimeout(None)
# self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
-# ftp.ftp.close()
+# ftp.close()
#
+# def testTimeoutValue(self):
+# ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [],
+# timeout=30)
+# self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
+# ftp.close()
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 3386800..c2d594b 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -3,6 +3,7 @@ from test import support
import os
import io
+import socket
import urllib2
from urllib2 import Request, OpenerDirector
@@ -546,14 +547,15 @@ class HandlerTests(unittest.TestCase):
class NullFTPHandler(urllib2.FTPHandler):
def __init__(self, data): self.data = data
- def connect_ftp(self, user, passwd, host, port, dirs, timeout=None):
+ def connect_ftp(self, user, passwd, host, port, dirs,
+ timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
self.user, self.passwd = user, passwd
self.host, self.port = host, port
self.dirs = dirs
self.ftpwrapper = MockFTPWrapper(self.data)
return self.ftpwrapper
- import ftplib, socket
+ import ftplib
data = "rheum rhaponicum"
h = NullFTPHandler(data)
o = h.parent = MockOpener()
@@ -686,7 +688,7 @@ class HandlerTests(unittest.TestCase):
self.req_headers = []
self.data = None
self.raise_on_endheaders = False
- def __call__(self, host, timeout=None):
+ def __call__(self, host, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
self.host = host
self.timeout = timeout
return self
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py
index 990d3da..752406c 100644
--- a/Lib/test/test_urllib2net.py
+++ b/Lib/test/test_urllib2net.py
@@ -188,46 +188,58 @@ class OtherNetworkTests(unittest.TestCase):
class TimeoutTest(unittest.TestCase):
def test_http_basic(self):
+ self.assertTrue(socket.getdefaulttimeout() is None)
u = _urlopen_with_retry("http://www.python.org")
self.assertTrue(u.fp.raw.fp._sock.gettimeout() is None)
- def test_http_NoneWithdefault(self):
- prev = socket.getdefaulttimeout()
+ def test_http_default_timeout(self):
+ self.assertTrue(socket.getdefaulttimeout() is None)
+ socket.setdefaulttimeout(60)
+ try:
+ u = _urlopen_with_retry("http://www.python.org")
+ finally:
+ socket.setdefaulttimeout(None)
+ self.assertEqual(u.fp.raw.fp._sock.gettimeout(), 60)
+
+ def test_http_no_timeout(self):
+ self.assertTrue(socket.getdefaulttimeout() is None)
socket.setdefaulttimeout(60)
try:
u = _urlopen_with_retry("http://www.python.org", timeout=None)
- self.assertTrue(u.fp.raw.fp._sock.gettimeout(), 60)
finally:
- socket.setdefaulttimeout(prev)
+ socket.setdefaulttimeout(None)
+ self.assertTrue(u.fp.raw.fp._sock.gettimeout() is None)
- def test_http_Value(self):
+ def test_http_timeout(self):
u = _urlopen_with_retry("http://www.python.org", timeout=120)
self.assertEqual(u.fp.raw.fp._sock.gettimeout(), 120)
- def test_http_NoneNodefault(self):
- u = _urlopen_with_retry("http://www.python.org", timeout=None)
- self.assertTrue(u.fp.raw.fp._sock.gettimeout() is None)
-
FTP_HOST = "ftp://ftp.mirror.nl/pub/mirror/gnu/"
def test_ftp_basic(self):
+ self.assertTrue(socket.getdefaulttimeout() is None)
u = _urlopen_with_retry(self.FTP_HOST)
self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
- def test_ftp_NoneWithdefault(self):
- prev = socket.getdefaulttimeout()
+ def test_ftp_default_timeout(self):
+ self.assertTrue(socket.getdefaulttimeout() is None)
socket.setdefaulttimeout(60)
try:
- u = _urlopen_with_retry(self.FTP_HOST, timeout=None)
- self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)
+ u = _urlopen_with_retry(self.FTP_HOST)
finally:
- socket.setdefaulttimeout(prev)
+ socket.setdefaulttimeout(None)
+ self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)
- def test_ftp_NoneNodefault(self):
- u = _urlopen_with_retry(self.FTP_HOST, timeout=None)
+ def test_ftp_no_timeout(self):
+ self.assertTrue(socket.getdefaulttimeout() is None)
+ socket.setdefaulttimeout(60)
+ try:
+ u = _urlopen_with_retry(self.FTP_HOST, timeout=None)
+ finally:
+ socket.setdefaulttimeout(None)
self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
- def test_ftp_Value(self):
+ def test_ftp_timeout(self):
u = _urlopen_with_retry(self.FTP_HOST, timeout=60)
self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)