summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-01-18 21:02:37 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-01-18 21:02:37 (GMT)
commite1cdfd78d823c50a592a7cf67e14f0786c65ead9 (patch)
tree51ae77036c556a796e49b533400421a467fd40dc /Lib
parent7e15845faa99b5570c1460f03c356e7a6e4d91f4 (diff)
downloadcpython-e1cdfd78d823c50a592a7cf67e14f0786c65ead9.zip
cpython-e1cdfd78d823c50a592a7cf67e14f0786c65ead9.tar.gz
cpython-e1cdfd78d823c50a592a7cf67e14f0786c65ead9.tar.bz2
Merged revisions 68547,68607,68610,68618,68621-68622,68649,68722 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r68547 | kristjan.jonsson | 2009-01-12 12:09:27 -0600 (Mon, 12 Jan 2009) | 1 line Add tests for invalid format specifiers in strftime, and for handling of invalid file descriptors in the os module. ........ r68607 | kristjan.jonsson | 2009-01-14 04:50:57 -0600 (Wed, 14 Jan 2009) | 2 lines Re-enable all tests for windows platforms. Also, explicitly connect to the IPV4 address. On windows platforms supporting AF_INET6, the SocketProxy would connect using socket.create_connection('localhost', port) which would cycle through all address families and try to connect. It would try connecting using AF_INET6 first and this would cause a delay of up to a second. ........ r68610 | kristjan.jonsson | 2009-01-15 03:09:13 -0600 (Thu, 15 Jan 2009) | 3 lines Fix recently introduced test cases. For datetime, gentoo didn't seem to mind the %e format for strftime. So, we just excercise those instead making sure that we don't crash. For test_os, two cases were incorrect. ........ r68618 | kristjan.jonsson | 2009-01-15 11:20:21 -0600 (Thu, 15 Jan 2009) | 1 line Issue 4929: Handle socket errors when receiving ........ r68621 | kristjan.jonsson | 2009-01-15 16:40:03 -0600 (Thu, 15 Jan 2009) | 1 line Fix two test cases in test_os. ftruncate raises IOError unlike all the others which raise OSError. And close() on some platforms doesn't complain when given an invalid file descriptor. ........ r68622 | kristjan.jonsson | 2009-01-15 16:46:26 -0600 (Thu, 15 Jan 2009) | 1 line Make all the invalid fd tests for os subject to the function being available. ........ r68649 | benjamin.peterson | 2009-01-16 22:39:05 -0600 (Fri, 16 Jan 2009) | 1 line trying to find some fpathconf() settings that all unixs support... ........ r68722 | kristjan.jonsson | 2009-01-18 04:58:44 -0600 (Sun, 18 Jan 2009) | 1 line issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16. ........
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/smtplib.py5
-rw-r--r--Lib/test/test_capi.py39
-rw-r--r--Lib/test/test_datetime.py17
-rw-r--r--Lib/test/test_os.py61
-rw-r--r--Lib/test/test_xmlrpc.py49
5 files changed, 136 insertions, 35 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index d59e6b1..0a12a97 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -336,7 +336,10 @@ class SMTP:
if self.file is None:
self.file = self.sock.makefile('rb')
while 1:
- line = self.file.readline()
+ try:
+ line = self.file.readline()
+ except socket.error:
+ line = ''
if not line:
self.close()
raise SMTPServerDisconnected("Connection unexpectedly closed")
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 4d37687..bf8b8a8 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -1,6 +1,7 @@
# Run the _testcapi module tests (tests for the Python/C API): by defn,
# these are all functions _testcapi exports whose name begins with 'test_'.
+from __future__ import with_statement
import sys
import time
import random
@@ -49,39 +50,61 @@ class TestPendingCalls(unittest.TestCase):
if _testcapi._pending_threadfunc(callback):
break;
- def pendingcalls_wait(self, l, n):
+ def pendingcalls_wait(self, l, n, context = None):
#now, stick around until l[0] has grown to 10
count = 0;
while len(l) != n:
#this busy loop is where we expect to be interrupted to
#run our callbacks. Note that callbacks are only run on the
#main thread
- if False and test_support.verbose:
+ if False and support.verbose:
print("(%i)"%(len(l),),)
for i in range(1000):
a = i*i
+ if context and not context.event.is_set():
+ continue
count += 1
self.failUnless(count < 10000,
"timeout waiting for %i callbacks, got %i"%(n, len(l)))
- if False and test_support.verbose:
+ if False and support.verbose:
print("(%i)"%(len(l),))
def test_pendingcalls_threaded(self):
- l = []
#do every callback on a separate thread
- n = 32
+ n = 32 #total callbacks
threads = []
- for i in range(n):
- t = threading.Thread(target=self.pendingcalls_submit, args = (l, 1))
+ class foo(object):pass
+ context = foo()
+ context.l = []
+ context.n = 2 #submits per thread
+ context.nThreads = n // context.n
+ context.nFinished = 0
+ context.lock = threading.Lock()
+ context.event = threading.Event()
+
+ for i in range(context.nThreads):
+ t = threading.Thread(target=self.pendingcalls_thread, args = (context,))
t.start()
threads.append(t)
- self.pendingcalls_wait(l, n)
+ self.pendingcalls_wait(context.l, n, context)
for t in threads:
t.join()
+ def pendingcalls_thread(self, context):
+ try:
+ self.pendingcalls_submit(context.l, context.n)
+ finally:
+ with context.lock:
+ context.nFinished += 1
+ nFinished = context.nFinished
+ if False and support.verbose:
+ print("finished threads: ", nFinished)
+ if nFinished == context.nThreads:
+ context.event.set()
+
def test_pendingcalls_non_threaded(self):
#again, just using the main thread, likely they will all be dispathced at
#once. It is ok to ask for too many, because we loop until we find a slot.
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index ead4b1c..797800f 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -851,6 +851,23 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
# A naive object replaces %z and %Z w/ empty strings.
self.assertEqual(t.strftime("'%z' '%Z'"), "'' ''")
+ #make sure that invalid format specifiers are handled correctly
+ #self.assertRaises(ValueError, t.strftime, "%e")
+ #self.assertRaises(ValueError, t.strftime, "%")
+ #self.assertRaises(ValueError, t.strftime, "%#")
+
+ #oh well, some systems just ignore those invalid ones.
+ #at least, excercise them to make sure that no crashes
+ #are generated
+ for f in ["%e", "%", "%#"]:
+ try:
+ t.strftime(f)
+ except ValueError:
+ pass
+
+ #check that this standard extension works
+ t.strftime("%f")
+
def test_format(self):
dt = self.theclass(2007, 9, 10)
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 4897aaf..7373334 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -587,6 +587,64 @@ class Win32ErrorTests(unittest.TestCase):
def test_chmod(self):
self.assertRaises(WindowsError, os.utime, support.TESTFN, 0)
+class TestInvalidFD(unittest.TestCase):
+ singles = ["fchdir", "dup", "fdatasync", "fstat",
+ "fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
+ #singles.append("close")
+ #We omit close because it doesn'r raise an exception on some platforms
+ def get_single(f):
+ def helper(self):
+ if getattr(os, f, None):
+ self.assertRaises(OSError, getattr(os, f), 10)
+ return helper
+ for f in singles:
+ locals()["test_"+f] = get_single(f)
+
+ def test_isatty(self):
+ if hasattr(os, "isatty"):
+ self.assertEqual(os.isatty(10), False)
+
+ def test_closerange(self):
+ if hasattr(os, "closerange"):
+ self.assertEqual(os.closerange(10, 20), None)
+
+ def test_dup2(self):
+ if hasattr(os, "dup2"):
+ self.assertRaises(OSError, os.dup2, 10, 20)
+
+ def test_fchmod(self):
+ if hasattr(os, "fchmod"):
+ self.assertRaises(OSError, os.fchmod, 10, 0)
+
+ def test_fchown(self):
+ if hasattr(os, "fchown"):
+ self.assertRaises(OSError, os.fchown, 10, -1, -1)
+
+ def test_fpathconf(self):
+ if hasattr(os, "fpathconf"):
+ self.assertRaises(OSError, os.fpathconf, 10, "PC_NAME_MAX")
+
+ #this is a weird one, it raises IOError unlike the others
+ def test_ftruncate(self):
+ if hasattr(os, "ftruncate"):
+ self.assertRaises(IOError, os.ftruncate, 10, 0)
+
+ def test_lseek(self):
+ if hasattr(os, "lseek"):
+ self.assertRaises(OSError, os.lseek, 10, 0, 0)
+
+ def test_read(self):
+ if hasattr(os, "read"):
+ self.assertRaises(OSError, os.read, 10, 1)
+
+ def test_tcsetpgrpt(self):
+ if hasattr(os, "tcsetpgrp"):
+ self.assertRaises(OSError, os.tcsetpgrp, 10, 0)
+
+ def test_write(self):
+ if hasattr(os, "write"):
+ self.assertRaises(OSError, os.write, 10, b" ")
+
if sys.platform != 'win32':
class Win32ErrorTests(unittest.TestCase):
pass
@@ -601,7 +659,8 @@ def test_main():
DevNullTests,
URandomTests,
ExecTests,
- Win32ErrorTests
+ Win32ErrorTests,
+ TestInvalidFD
)
if __name__ == "__main__":
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index e285809..7c68e4c 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -232,7 +232,7 @@ class BinaryTestCase(unittest.TestCase):
self.assertEqual(str(t2), str(d, "latin-1"))
-PORT = None
+ADDR = PORT = URL = None
# The evt is set twice. First when the server is ready to serve.
# Second when the server has been shutdown. The user must clear
@@ -258,12 +258,17 @@ def http_server(evt, numrequests):
s.setblocking(True)
return s, port
+ serv = MyXMLRPCServer(("localhost", 0),
+ logRequests=False, bind_and_activate=False)
try:
- serv = MyXMLRPCServer(("localhost", 0),
- logRequests=False, bind_and_activate=False)
serv.server_bind()
- global PORT
- PORT = serv.socket.getsockname()[1]
+ global ADDR, PORT, URL
+ ADDR, PORT = serv.socket.getsockname()
+ #connect to IP address directly. This avoids socket.create_connection()
+ #trying to connect to to "localhost" using all address families, which
+ #causes slowdown e.g. on vista which supports AF_INET6. The server listens
+ #on AF_INET only.
+ URL = "http://%s:%d"%(ADDR, PORT)
serv.server_activate()
serv.register_introspection_functions()
serv.register_multicall_functions()
@@ -331,7 +336,7 @@ class SimpleServerTestCase(unittest.TestCase):
def test_simple1(self):
try:
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ p = xmlrpclib.ServerProxy(URL)
self.assertEqual(p.pow(6,8), 6**8)
except (xmlrpclib.ProtocolError, socket.error) as e:
# ignore failures due to non-blocking socket 'unavailable' errors
@@ -343,7 +348,7 @@ class SimpleServerTestCase(unittest.TestCase):
def XXXtest_404(self):
# send POST with http.client, it should return 404 header and
# 'Not Found' message.
- conn = http.client.HTTPConnection('localhost', PORT)
+ conn = httplib.client.HTTPConnection(ADDR, PORT)
conn.request('POST', '/this-is-not-valid')
response = conn.getresponse()
conn.close()
@@ -356,7 +361,7 @@ class SimpleServerTestCase(unittest.TestCase):
'system.listMethods', 'system.methodHelp',
'system.methodSignature', 'system.multicall'])
try:
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ p = xmlrpclib.ServerProxy(URL)
meth = p.system.listMethods()
self.assertEqual(set(meth), expected_methods)
except (xmlrpclib.ProtocolError, socket.error) as e:
@@ -369,7 +374,7 @@ class SimpleServerTestCase(unittest.TestCase):
def test_introspection2(self):
try:
# test _methodHelp()
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ p = xmlrpclib.ServerProxy(URL)
divhelp = p.system.methodHelp('div')
self.assertEqual(divhelp, 'This is the div function')
except (xmlrpclib.ProtocolError, socket.error) as e:
@@ -381,7 +386,7 @@ class SimpleServerTestCase(unittest.TestCase):
def test_introspection3(self):
try:
# test native doc
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ p = xmlrpclib.ServerProxy(URL)
myfunction = p.system.methodHelp('my_function')
self.assertEqual(myfunction, 'This is my function')
except (xmlrpclib.ProtocolError, socket.error) as e:
@@ -394,7 +399,7 @@ class SimpleServerTestCase(unittest.TestCase):
# the SimpleXMLRPCServer doesn't support signatures, but
# at least check that we can try making the call
try:
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ p = xmlrpclib.ServerProxy(URL)
divsig = p.system.methodSignature('div')
self.assertEqual(divsig, 'signatures not supported')
except (xmlrpclib.ProtocolError, socket.error) as e:
@@ -405,7 +410,7 @@ class SimpleServerTestCase(unittest.TestCase):
def test_multicall(self):
try:
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ p = xmlrpclib.ServerProxy(URL)
multicall = xmlrpclib.MultiCall(p)
multicall.add(2,3)
multicall.pow(6,8)
@@ -422,7 +427,7 @@ class SimpleServerTestCase(unittest.TestCase):
def test_non_existing_multicall(self):
try:
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ p = xmlrpclib.ServerProxy(URL)
multicall = xmlrpclib.MultiCall(p)
multicall.this_is_not_exists()
result = multicall()
@@ -491,7 +496,7 @@ class FailingServerTestCase(unittest.TestCase):
# test a call that shouldn't fail just as a smoke test
try:
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ p = xmlrpclib.ServerProxy(URL)
self.assertEqual(p.pow(6,8), 6**8)
except (xmlrpclib.ProtocolError, socket.error) as e:
# ignore failures due to non-blocking socket 'unavailable' errors
@@ -504,7 +509,7 @@ class FailingServerTestCase(unittest.TestCase):
xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass
try:
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ p = xmlrpclib.ServerProxy(URL)
p.pow(6,8)
except (xmlrpclib.ProtocolError, socket.error) as e:
# ignore failures due to non-blocking socket 'unavailable' errors
@@ -524,7 +529,7 @@ class FailingServerTestCase(unittest.TestCase):
xmlrpc.server.SimpleXMLRPCServer._send_traceback_header = True
try:
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ p = xmlrpclib.ServerProxy(URL)
p.pow(6,8)
except (xmlrpclib.ProtocolError, socket.error) as e:
# ignore failures due to non-blocking socket 'unavailable' errors
@@ -605,15 +610,9 @@ class CGIHandlerTestCase(unittest.TestCase):
def test_main():
xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase,
BinaryTestCase, FaultTestCase]
-
- # The test cases against a SimpleXMLRPCServer raise a socket error
- # 10035 (WSAEWOULDBLOCK) in the server thread handle_request call when
- # run on Windows. This only happens on the first test to run, but it
- # fails every time and so these tests are skipped on win32 platforms.
- if sys.platform != 'win32':
- xmlrpc_tests.append(SimpleServerTestCase)
- xmlrpc_tests.append(FailingServerTestCase)
- xmlrpc_tests.append(CGIHandlerTestCase)
+ xmlrpc_tests.append(SimpleServerTestCase)
+ xmlrpc_tests.append(FailingServerTestCase)
+ xmlrpc_tests.append(CGIHandlerTestCase)
support.run_unittest(*xmlrpc_tests)