mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	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]
This commit is contained in:
		
							parent
							
								
									54ec61ea6e
								
							
						
					
					
						commit
						c65a5f1b14
					
				
					 1 changed files with 52 additions and 25 deletions
				
			
		| 
						 | 
					@ -352,29 +352,46 @@ def tearDown(self):
 | 
				
			||||||
        SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = False
 | 
					        SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_simple1(self):
 | 
					    def test_simple1(self):
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
					            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
				
			||||||
            self.assertEqual(p.pow(6,8), 6**8)
 | 
					            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):
 | 
					    def test_introspection1(self):
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
					            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
				
			||||||
            meth = p.system.listMethods()
 | 
					            meth = p.system.listMethods()
 | 
				
			||||||
            expected_methods = set(['pow', 'div', 'add', 'system.listMethods',
 | 
					            expected_methods = set(['pow', 'div', 'add', 'system.listMethods',
 | 
				
			||||||
                'system.methodHelp', 'system.methodSignature', 'system.multicall'])
 | 
					                'system.methodHelp', 'system.methodSignature', 'system.multicall'])
 | 
				
			||||||
            self.assertEqual(set(meth), expected_methods)
 | 
					            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):
 | 
					    def test_introspection2(self):
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
					            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
				
			||||||
            divhelp = p.system.methodHelp('div')
 | 
					            divhelp = p.system.methodHelp('div')
 | 
				
			||||||
            self.assertEqual(divhelp, 'This is the div function')
 | 
					            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):
 | 
					    def test_introspection3(self):
 | 
				
			||||||
        # the SimpleXMLRPCServer doesn't support signatures, but
 | 
					        # the SimpleXMLRPCServer doesn't support signatures, but
 | 
				
			||||||
        # at least check that we can try
 | 
					        # at least check that we can try
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
					            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
				
			||||||
            divsig = p.system.methodSignature('div')
 | 
					            divsig = p.system.methodSignature('div')
 | 
				
			||||||
            self.assertEqual(divsig, 'signatures not supported')
 | 
					            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):
 | 
					    def test_multicall(self):
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
					            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
				
			||||||
            multicall = xmlrpclib.MultiCall(p)
 | 
					            multicall = xmlrpclib.MultiCall(p)
 | 
				
			||||||
            multicall.add(2,3)
 | 
					            multicall.add(2,3)
 | 
				
			||||||
| 
						 | 
					@ -384,6 +401,9 @@ def test_multicall(self):
 | 
				
			||||||
            self.assertEqual(add_result, 2+3)
 | 
					            self.assertEqual(add_result, 2+3)
 | 
				
			||||||
            self.assertEqual(pow_result, 6**8)
 | 
					            self.assertEqual(pow_result, 6**8)
 | 
				
			||||||
            self.assertEqual(div_result, 127//42)
 | 
					            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
 | 
					# This is a contrived way to make a failure occur on the server side
 | 
				
			||||||
| 
						 | 
					@ -424,9 +444,16 @@ def test_basic(self):
 | 
				
			||||||
        flagval = SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header
 | 
					        flagval = SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header
 | 
				
			||||||
        self.assertEqual(flagval, False)
 | 
					        self.assertEqual(flagval, False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # test a call that won't fail just as a smoke test
 | 
					        # 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)
 | 
					            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
				
			||||||
            self.assertEqual(p.pow(6,8), 6**8)
 | 
					            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):
 | 
					    def test_fail_no_info(self):
 | 
				
			||||||
        # use the broken message class
 | 
					        # use the broken message class
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue