summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socketserver.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_socketserver.py')
-rw-r--r--Lib/test/test_socketserver.py85
1 files changed, 46 insertions, 39 deletions
diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py
index 464057e..59d8e5d 100644
--- a/Lib/test/test_socketserver.py
+++ b/Lib/test/test_socketserver.py
@@ -27,7 +27,10 @@ TEST_STR = b"hello world\n"
HOST = test.support.HOST
HAVE_UNIX_SOCKETS = hasattr(socket, "AF_UNIX")
+requires_unix_sockets = unittest.skipUnless(HAVE_UNIX_SOCKETS,
+ 'requires Unix sockets')
HAVE_FORKING = hasattr(os, "fork") and os.name != "os2"
+requires_forking = unittest.skipUnless(HAVE_FORKING, 'requires forking')
def signal_alarm(n):
"""Call signal.alarm when it exists (i.e. not on Windows)."""
@@ -189,31 +192,33 @@ class SocketServerTest(unittest.TestCase):
socketserver.StreamRequestHandler,
self.stream_examine)
- if HAVE_FORKING:
- def test_ForkingTCPServer(self):
- with simple_subprocess(self):
- self.run_server(socketserver.ForkingTCPServer,
- socketserver.StreamRequestHandler,
- self.stream_examine)
-
- if HAVE_UNIX_SOCKETS:
- def test_UnixStreamServer(self):
- self.run_server(socketserver.UnixStreamServer,
+ @requires_forking
+ def test_ForkingTCPServer(self):
+ with simple_subprocess(self):
+ self.run_server(socketserver.ForkingTCPServer,
socketserver.StreamRequestHandler,
self.stream_examine)
- def test_ThreadingUnixStreamServer(self):
- self.run_server(socketserver.ThreadingUnixStreamServer,
+ @requires_unix_sockets
+ def test_UnixStreamServer(self):
+ self.run_server(socketserver.UnixStreamServer,
+ socketserver.StreamRequestHandler,
+ self.stream_examine)
+
+ @requires_unix_sockets
+ def test_ThreadingUnixStreamServer(self):
+ self.run_server(socketserver.ThreadingUnixStreamServer,
+ socketserver.StreamRequestHandler,
+ self.stream_examine)
+
+ @requires_unix_sockets
+ @requires_forking
+ def test_ForkingUnixStreamServer(self):
+ with simple_subprocess(self):
+ self.run_server(ForkingUnixStreamServer,
socketserver.StreamRequestHandler,
self.stream_examine)
- if HAVE_FORKING:
- def test_ForkingUnixStreamServer(self):
- with simple_subprocess(self):
- self.run_server(ForkingUnixStreamServer,
- socketserver.StreamRequestHandler,
- self.stream_examine)
-
def test_UDPServer(self):
self.run_server(socketserver.UDPServer,
socketserver.DatagramRequestHandler,
@@ -224,12 +229,12 @@ class SocketServerTest(unittest.TestCase):
socketserver.DatagramRequestHandler,
self.dgram_examine)
- if HAVE_FORKING:
- def test_ForkingUDPServer(self):
- with simple_subprocess(self):
- self.run_server(socketserver.ForkingUDPServer,
- socketserver.DatagramRequestHandler,
- self.dgram_examine)
+ @requires_forking
+ def test_ForkingUDPServer(self):
+ with simple_subprocess(self):
+ self.run_server(socketserver.ForkingUDPServer,
+ socketserver.DatagramRequestHandler,
+ self.dgram_examine)
@contextlib.contextmanager
def mocked_select_module(self):
@@ -266,22 +271,24 @@ class SocketServerTest(unittest.TestCase):
# Alas, on Linux (at least) recvfrom() doesn't return a meaningful
# client address so this cannot work:
- # if HAVE_UNIX_SOCKETS:
- # def test_UnixDatagramServer(self):
- # self.run_server(socketserver.UnixDatagramServer,
- # socketserver.DatagramRequestHandler,
- # self.dgram_examine)
+ # @requires_unix_sockets
+ # def test_UnixDatagramServer(self):
+ # self.run_server(socketserver.UnixDatagramServer,
+ # socketserver.DatagramRequestHandler,
+ # self.dgram_examine)
#
- # def test_ThreadingUnixDatagramServer(self):
- # self.run_server(socketserver.ThreadingUnixDatagramServer,
- # socketserver.DatagramRequestHandler,
- # self.dgram_examine)
+ # @requires_unix_sockets
+ # def test_ThreadingUnixDatagramServer(self):
+ # self.run_server(socketserver.ThreadingUnixDatagramServer,
+ # socketserver.DatagramRequestHandler,
+ # self.dgram_examine)
#
- # if HAVE_FORKING:
- # def test_ForkingUnixDatagramServer(self):
- # self.run_server(socketserver.ForkingUnixDatagramServer,
- # socketserver.DatagramRequestHandler,
- # self.dgram_examine)
+ # @requires_unix_sockets
+ # @requires_forking
+ # def test_ForkingUnixDatagramServer(self):
+ # self.run_server(socketserver.ForkingUnixDatagramServer,
+ # socketserver.DatagramRequestHandler,
+ # self.dgram_examine)
@reap_threads
def test_shutdown(self):