From a44b5a332620c8fc0fcf25f81025e5f9d832a5e2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 27 Apr 2010 23:14:58 +0000 Subject: Issue #7449, part 9: fix test_xmlrpclib for missing threading module * Skip testcases using threads if threading module is missing * Use "http://" instead of URL in ServerProxyTestCase if threading is missing because URL is not set in this case --- Lib/test/test_xmlrpc.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index 94c5825..2a3b2d9 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -5,7 +5,6 @@ import time import unittest import xmlrpclib import SimpleXMLRPCServer -import threading import mimetools import httplib import socket @@ -15,6 +14,11 @@ import re from test import test_support try: + import threading +except ImportError: + threading = None + +try: unicode except NameError: have_unicode = False @@ -410,10 +414,12 @@ def is_unavailable_exception(e): return False +@unittest.skipUnless(threading, 'Threading required for this test.') class BaseServerTestCase(unittest.TestCase): requestHandler = None request_count = 1 threadFunc = staticmethod(http_server) + def setUp(self): # enable traceback reporting SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True @@ -692,6 +698,9 @@ class GzipServerTestCase(BaseServerTestCase): connection.putheader("Content-Encoding", "gzip") return xmlrpclib.Transport.send_content(self, connection, body) + def setUp(self): + BaseServerTestCase.setUp(self) + def test_gzip_request(self): t = self.Transport() t.encode_threshold = None @@ -728,13 +737,23 @@ class GzipServerTestCase(BaseServerTestCase): #Test special attributes of the ServerProxy object class ServerProxyTestCase(unittest.TestCase): + def setUp(self): + unittest.TestCase.setUp(self) + if threading: + self.url = URL + else: + # Without threading, http_server() and http_multi_server() will not + # be executed and URL is still equal to None. 'http://' is a just + # enough to choose the scheme (HTTP) + self.url = 'http://' + def test_close(self): - p = xmlrpclib.ServerProxy(URL) + p = xmlrpclib.ServerProxy(self.url) self.assertEqual(p('close')(), None) def test_transport(self): t = xmlrpclib.Transport() - p = xmlrpclib.ServerProxy(URL, transport=t) + p = xmlrpclib.ServerProxy(self.url, transport=t) self.assertEqual(p('transport'), t) # This is a contrived way to make a failure occur on the server side @@ -747,6 +766,7 @@ class FailingMessageClass(mimetools.Message): return mimetools.Message.__getitem__(self, key) +@unittest.skipUnless(threading, 'Threading required for this test.') class FailingServerTestCase(unittest.TestCase): def setUp(self): self.evt = threading.Event() -- cgit v0.12