cpython: b07b0b7517da (original) (raw)

--- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -87,6 +87,13 @@ def capture_server(evt, buf, serv): serv.close() evt.set() +def bind_af_aware(sock, addr):

+ class HelperFunctionTests(unittest.TestCase): def test_readwriteexc(self): @@ -467,22 +474,22 @@ class BaseTestHandler(asyncore.dispatche raise -class TCPServer(asyncore.dispatcher): +class BaseServer(asyncore.dispatcher): """A server which listens on an address and dispatches the connection to a handler. """

@property def address(self):

def handle_accepted(self, sock, addr): self.handler(sock) @@ -493,9 +500,9 @@ class TCPServer(asyncore.dispatcher): class BaseClient(BaseTestHandler):

def handle_connect(self): @@ -525,8 +532,8 @@ class BaseTestAPI(unittest.TestCase): def handle_connect(self): self.flag = True

def test_handle_accept(self): @@ -534,18 +541,18 @@ class BaseTestAPI(unittest.TestCase): class TestListener(BaseTestHandler):

def handle_accept(self): self.flag = True

def test_handle_accepted(self): @@ -553,12 +560,12 @@ class BaseTestAPI(unittest.TestCase): class TestListener(BaseTestHandler):

def handle_accept(self): asyncore.dispatcher.handle_accept(self) @@ -567,8 +574,8 @@ class BaseTestAPI(unittest.TestCase): sock.close() self.flag = True

@@ -584,8 +591,8 @@ class BaseTestAPI(unittest.TestCase): BaseTestHandler.init(self, conn) self.send(b'x' * 1024)

def test_handle_write(self): @@ -595,8 +602,8 @@ class BaseTestAPI(unittest.TestCase): def handle_write(self): self.flag = True

def test_handle_close(self): @@ -619,8 +626,8 @@ class BaseTestAPI(unittest.TestCase): BaseTestHandler.init(self, conn) self.close()

@unittest.skipIf(sys.platform.startswith("sunos"), @@ -629,6 +636,8 @@ class BaseTestAPI(unittest.TestCase): # Make sure handle_expt is called on OOB data received. # Note: this might fail on some platforms as OOB data is # tenuously supported and rarely used.

class TestClient(BaseClient): def handle_expt(self): @@ -639,8 +648,8 @@ class BaseTestAPI(unittest.TestCase): BaseTestHandler.init(self, conn) self.socket.send(bytes(chr(244), 'latin-1'), socket.MSG_OOB)

def test_handle_error(self): @@ -657,13 +666,13 @@ class BaseTestAPI(unittest.TestCase): else: raise Exception("exception not raised")

def test_connection_attributes(self):

# we start disconnected self.assertFalse(server.connected) @@ -693,25 +702,29 @@ class BaseTestAPI(unittest.TestCase): def test_create_socket(self): s = asyncore.dispatcher()

def test_bind(self):

s2 = asyncore.dispatcher()

def test_set_reuse_addr(self):

@@ -719,11 +732,11 @@ class BaseTestAPI(unittest.TestCase): else: # if SO_REUSEADDR succeeded for sock we expect asyncore # to do the same

@@ -731,18 +744,44 @@ class BaseTestAPI(unittest.TestCase): sock.close() -class TestAPI_UseSelect(BaseTestAPI): +class TestAPI_UseIPv4Sockets(BaseTestAPI):

+ +@unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 support required') +class TestAPI_UseIPv6Sockets(BaseTestAPI):

+ +@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'Unix sockets required') +class TestAPI_UseUnixSockets(BaseTestAPI):

+

+ +class TestAPI_UseIPv4Select(TestAPI_UseIPv4Sockets): use_poll = False @unittest.skipUnless(hasattr(select, 'poll'), 'select.poll required') -class TestAPI_UsePoll(BaseTestAPI): +class TestAPI_UseIPv4Poll(TestAPI_UseIPv4Sockets): use_poll = True +class TestAPI_UseIPv6Select(TestAPI_UseIPv6Sockets):

+ +@unittest.skipUnless(hasattr(select, 'poll'), 'select.poll required') +class TestAPI_UseIPv6Poll(TestAPI_UseIPv6Sockets):

def test_main(): tests = [HelperFunctionTests, DispatcherTests, DispatcherWithSendTests,

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -1221,6 +1221,8 @@ Extension Modules Tests ----- +- Issue #12656: Add tests for IPv6 and Unix sockets to test_asyncore. +