[Python-checkins] r84027 - in python/branches/release31-maint: Lib/test/test_socket.py Misc/NEWS

giampaolo.rodola python-checkins at python.org
Sat Aug 14 19:00:05 CEST 2010


Author: giampaolo.rodola
Date: Sat Aug 14 19:00:05 2010
New Revision: 84027

Log:
Merged revisions 84024 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r84024 | giampaolo.rodola | 2010-08-14 18:45:41 +0200 (sab, 14 ago 2010) | 1 line
  
  fix issue #8857: provide a test case for socket.getaddrinfo
........


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Lib/test/test_socket.py
   python/branches/release31-maint/Misc/NEWS

Modified: python/branches/release31-maint/Lib/test/test_socket.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_socket.py	(original)
+++ python/branches/release31-maint/Lib/test/test_socket.py	Sat Aug 14 19:00:05 2010
@@ -17,8 +17,21 @@
 from weakref import proxy
 import signal
 
+def try_address(host, port=0, family=socket.AF_INET):
+    """Try to bind a socket on the given host:port and return True
+    if that has been possible."""
+    try:
+        sock = socket.socket(family, socket.SOCK_STREAM)
+        sock.bind((host, port))
+    except (socket.error, socket.gaierror):
+        return False
+    else:
+        sock.close()
+        return True
+
 HOST = support.HOST
 MSG = b'Michael Gilfix was here\n'
+SUPPORTS_IPV6 = socket.has_ipv6 and try_address('::1', family=socket.AF_INET6)
 
 class SocketTCPTest(unittest.TestCase):
 
@@ -554,6 +567,44 @@
         self.assertTrue(hasattr(socket, 'RCVALL_ON'))
         self.assertTrue(hasattr(socket, 'RCVALL_OFF'))
 
+    def testGetaddrinfo(self):
+        try:
+            socket.getaddrinfo('localhost', 80)
+        except socket.gaierror as err:
+            if err.errno == socket.EAI_SERVICE:
+                # see http://bugs.python.org/issue1282647
+                self.skipTest("buggy libc version")
+            raise
+        # len of every sequence is supposed to be == 5
+        for info in socket.getaddrinfo(HOST, None):
+            self.assertEqual(len(info), 5)
+        # host can be a domain name, a string representation of an
+        # IPv4/v6 address or None
+        socket.getaddrinfo('localhost', 80)
+        socket.getaddrinfo('127.0.0.1', 80)
+        socket.getaddrinfo(None, 80)
+        if SUPPORTS_IPV6:
+            socket.getaddrinfo('::1', 80)
+        # port can be a string service name such as "http", a numeric
+        # port number or None
+        socket.getaddrinfo(HOST, "http")
+        socket.getaddrinfo(HOST, 80)
+        socket.getaddrinfo(HOST, None)
+        # test family and socktype filters
+        infos = socket.getaddrinfo(HOST, None, socket.AF_INET)
+        for family, _, _, _, _ in infos:
+            self.assertEqual(family, socket.AF_INET)
+        infos = socket.getaddrinfo(HOST, None, 0, socket.SOCK_STREAM)
+        for _, socktype, _, _, _ in infos:
+            self.assertEqual(socktype, socket.SOCK_STREAM)
+        # test proto and flags arguments
+        socket.getaddrinfo(HOST, None, 0, 0, socket.AI_CANONNAME)
+        socket.getaddrinfo(HOST, None, 0, 0, 0, socket.AI_PASSIVE)
+        # a server willing to support both IPv4 and IPv6 will
+        # usually do this
+        socket.getaddrinfo(None, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0,
+                           socket.AI_PASSIVE)
+
 
 class BasicTCPTest(SocketConnectedTest):
 

Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS	(original)
+++ python/branches/release31-maint/Misc/NEWS	Sat Aug 14 19:00:05 2010
@@ -479,6 +479,8 @@
 Tests
 -----
 
+- Issue #8857: Provide a test case for socket.getaddrinfo.
+
 - Issue #8433: Fix test_curses failure with newer versions of ncurses.
 
 - Issue #9496: Provide a test suite for the rlcompleter module.  Patch by


More information about the Python-checkins mailing list