Commit a44b5a33 authored by Victor Stinner's avatar Victor Stinner

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
parent 09227b91
...@@ -5,7 +5,6 @@ import time ...@@ -5,7 +5,6 @@ import time
import unittest import unittest
import xmlrpclib import xmlrpclib
import SimpleXMLRPCServer import SimpleXMLRPCServer
import threading
import mimetools import mimetools
import httplib import httplib
import socket import socket
...@@ -14,6 +13,11 @@ import os ...@@ -14,6 +13,11 @@ import os
import re import re
from test import test_support from test import test_support
try:
import threading
except ImportError:
threading = None
try: try:
unicode unicode
except NameError: except NameError:
...@@ -410,10 +414,12 @@ def is_unavailable_exception(e): ...@@ -410,10 +414,12 @@ def is_unavailable_exception(e):
return False return False
@unittest.skipUnless(threading, 'Threading required for this test.')
class BaseServerTestCase(unittest.TestCase): class BaseServerTestCase(unittest.TestCase):
requestHandler = None requestHandler = None
request_count = 1 request_count = 1
threadFunc = staticmethod(http_server) threadFunc = staticmethod(http_server)
def setUp(self): def setUp(self):
# enable traceback reporting # enable traceback reporting
SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True
...@@ -692,6 +698,9 @@ class GzipServerTestCase(BaseServerTestCase): ...@@ -692,6 +698,9 @@ class GzipServerTestCase(BaseServerTestCase):
connection.putheader("Content-Encoding", "gzip") connection.putheader("Content-Encoding", "gzip")
return xmlrpclib.Transport.send_content(self, connection, body) return xmlrpclib.Transport.send_content(self, connection, body)
def setUp(self):
BaseServerTestCase.setUp(self)
def test_gzip_request(self): def test_gzip_request(self):
t = self.Transport() t = self.Transport()
t.encode_threshold = None t.encode_threshold = None
...@@ -728,13 +737,23 @@ class GzipServerTestCase(BaseServerTestCase): ...@@ -728,13 +737,23 @@ class GzipServerTestCase(BaseServerTestCase):
#Test special attributes of the ServerProxy object #Test special attributes of the ServerProxy object
class ServerProxyTestCase(unittest.TestCase): 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): def test_close(self):
p = xmlrpclib.ServerProxy(URL) p = xmlrpclib.ServerProxy(self.url)
self.assertEqual(p('close')(), None) self.assertEqual(p('close')(), None)
def test_transport(self): def test_transport(self):
t = xmlrpclib.Transport() t = xmlrpclib.Transport()
p = xmlrpclib.ServerProxy(URL, transport=t) p = xmlrpclib.ServerProxy(self.url, transport=t)
self.assertEqual(p('transport'), t) self.assertEqual(p('transport'), t)
# 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
...@@ -747,6 +766,7 @@ class FailingMessageClass(mimetools.Message): ...@@ -747,6 +766,7 @@ class FailingMessageClass(mimetools.Message):
return mimetools.Message.__getitem__(self, key) return mimetools.Message.__getitem__(self, key)
@unittest.skipUnless(threading, 'Threading required for this test.')
class FailingServerTestCase(unittest.TestCase): class FailingServerTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.evt = threading.Event() self.evt = threading.Event()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment