summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2007-08-21 00:16:21 (GMT)
committerFacundo Batista <facundobatista@gmail.com>2007-08-21 00:16:21 (GMT)
commitc65a5f1b14ff6bd995d7cb102e5b4577ce0f16e2 (patch)
tree57fc2471bd3f2cf277794adfc3d73b143811316e
parent54ec61ea6e0e5eab62309f1c238af19dda77b607 (diff)
downloadcpython-c65a5f1b14ff6bd995d7cb102e5b4577ce0f16e2.zip
cpython-c65a5f1b14ff6bd995d7cb102e5b4577ce0f16e2.tar.gz
cpython-c65a5f1b14ff6bd995d7cb102e5b4577ce0f16e2.tar.bz2
Catch ProtocolError exceptions and include the header information in
test output (to make it easier to debug test failures caused by problems in the server). [GSoC - Alan McIntyre]
-rw-r--r--Lib/test/test_xmlrpc.py77
1 files changed, 52 insertions, 25 deletions
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index 512b28c..a933c0e 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -352,38 +352,58 @@ class SimpleServerTestCase(unittest.TestCase):
SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = False
def test_simple1(self):
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
- self.assertEqual(p.pow(6,8), 6**8)
+ try:
+ p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ self.assertEqual(p.pow(6,8), 6**8)
+ except xmlrpclib.ProtocolError, e:
+ # protocol error; provide additional information in test output
+ self.fail("%s\n%s" % (e, e.headers))
def test_introspection1(self):
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
- meth = p.system.listMethods()
- expected_methods = set(['pow', 'div', 'add', 'system.listMethods',
- 'system.methodHelp', 'system.methodSignature', 'system.multicall'])
- self.assertEqual(set(meth), expected_methods)
+ try:
+ p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ meth = p.system.listMethods()
+ expected_methods = set(['pow', 'div', 'add', 'system.listMethods',
+ 'system.methodHelp', 'system.methodSignature', 'system.multicall'])
+ self.assertEqual(set(meth), expected_methods)
+ except xmlrpclib.ProtocolError, e:
+ # protocol error; provide additional information in test output
+ self.fail("%s\n%s" % (e, e.headers))
def test_introspection2(self):
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
- divhelp = p.system.methodHelp('div')
- self.assertEqual(divhelp, 'This is the div function')
+ try:
+ p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ divhelp = p.system.methodHelp('div')
+ self.assertEqual(divhelp, 'This is the div function')
+ except xmlrpclib.ProtocolError, e:
+ # protocol error; provide additional information in test output
+ self.fail("%s\n%s" % (e, e.headers))
def test_introspection3(self):
# the SimpleXMLRPCServer doesn't support signatures, but
# at least check that we can try
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
- divsig = p.system.methodSignature('div')
- self.assertEqual(divsig, 'signatures not supported')
+ try:
+ p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ divsig = p.system.methodSignature('div')
+ self.assertEqual(divsig, 'signatures not supported')
+ except xmlrpclib.ProtocolError, e:
+ # protocol error; provide additional information in test output
+ self.fail("%s\n%s" % (e, e.headers))
def test_multicall(self):
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
- multicall = xmlrpclib.MultiCall(p)
- multicall.add(2,3)
- multicall.pow(6,8)
- multicall.div(127,42)
- add_result, pow_result, div_result = multicall()
- self.assertEqual(add_result, 2+3)
- self.assertEqual(pow_result, 6**8)
- self.assertEqual(div_result, 127//42)
+ try:
+ p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ multicall = xmlrpclib.MultiCall(p)
+ multicall.add(2,3)
+ multicall.pow(6,8)
+ multicall.div(127,42)
+ add_result, pow_result, div_result = multicall()
+ self.assertEqual(add_result, 2+3)
+ self.assertEqual(pow_result, 6**8)
+ self.assertEqual(div_result, 127//42)
+ except xmlrpclib.ProtocolError, e:
+ # protocol error; provide additional information in test output
+ self.fail("%s\n%s" % (e, e.headers))
# This is a contrived way to make a failure occur on the server side
@@ -424,9 +444,16 @@ class FailingServerTestCase(unittest.TestCase):
flagval = SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header
self.assertEqual(flagval, False)
- # test a call that won't fail just as a smoke test
- p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
- self.assertEqual(p.pow(6,8), 6**8)
+ # enable traceback reporting
+ SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True
+
+ # test a call that shouldn't fail just as a smoke test
+ try:
+ p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
+ self.assertEqual(p.pow(6,8), 6**8)
+ except xmlrpclib.ProtocolError, e:
+ # protocol error; provide additional information in test output
+ self.fail("%s\n%s" % (e, e.headers))
def test_fail_no_info(self):
# use the broken message class