[PATCH 2 of 6] socketserver: fix check related tests
Jun Wu
quark at fb.com
Sun May 8 20:06:21 EDT 2016
# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1462501539 -3600
# Fri May 06 03:25:39 2016 +0100
# Node ID d94e32fbb8c35c2b536a74780f54d563a48e19c5
# Parent fff86624fbfa0c2e78bb2874d68e6dd191c371cd
socketserver: fix check related tests
It's bad to make test-check tests complaining about socketserver.py. Fix
issues to make these tests green.
diff --git a/mercurial/socketserver.py b/mercurial/socketserver.py
--- a/mercurial/socketserver.py
+++ b/mercurial/socketserver.py
@@ -125,18 +125,22 @@
# standard regression test.
# To run it manually, run Lib/test/test_socketserver.py.
+# no-check-code -- backported from Python 3
+
+from __future__ import absolute_import, print_function
+
__version__ = "0.4"
-
+import errno
+import os
import socket
-import selectors
-import os
-import errno
try:
import threading
except ImportError:
import dummy_threading as threading
-from time import monotonic as time
+
+import time as timemod
+time = timemod.monotonic
__all__ = ["BaseServer", "TCPServer", "UDPServer", "ForkingUDPServer",
"ForkingTCPServer", "ThreadingUDPServer", "ThreadingTCPServer",
@@ -147,6 +151,19 @@
"ThreadingUnixStreamServer",
"ThreadingUnixDatagramServer"])
+try:
+ ChildProcessError
+except NameError:
+ # Python 2 does not have ChildProcessError
+ class ChildProcessError(OSError):
+ pass
+
+try:
+ import selectors
+except ImportError:
+ # Python 2 does not have selectors
+ pass
+
# poll/select have the advantage of not requiring any extra file descriptor,
# contrarily to epoll/kqueue (also, they require a single syscall).
if hasattr(selectors, 'PollSelector'):
@@ -754,10 +771,10 @@
"""Define self.rfile and self.wfile for datagram sockets."""
def setup(self):
- from io import BytesIO
+ import io
self.packet, self.socket = self.request
- self.rfile = BytesIO(self.packet)
- self.wfile = BytesIO()
+ self.rfile = io.BytesIO(self.packet)
+ self.wfile = io.BytesIO()
def finish(self):
self.socket.sendto(self.wfile.getvalue(), self.client_address)
diff --git a/tests/test-check-code.t b/tests/test-check-code.t
--- a/tests/test-check-code.t
+++ b/tests/test-check-code.t
@@ -17,3 +17,4 @@
Skipping mercurial/httpclient/__init__.py it has no-che?k-code (glob)
Skipping mercurial/httpclient/_readers.py it has no-che?k-code (glob)
Skipping mercurial/httpclient/socketutil.py it has no-che?k-code (glob)
+ Skipping mercurial/socketserver.py it has no-che?k-code (glob)
More information about the Mercurial-devel
mailing list