@@ -358,6 +358,28 @@ def test_getnameinfo(self):
358358 self .assertRaises (TypeError , _socket .getnameinfo , ("127.0.0.1" , 80 , 0 , 0 , 0 ), 8 )
359359 self .assertRaises (_socket .gaierror , _socket .getnameinfo , ('no such host will ever exist' , 80 ), 8 )
360360
361+ # try some IPv6 cases
362+ host , service = _socket .getnameinfo (("::1" , 80 ), 0 )
363+ self .assertEqual (service , "http" )
364+
365+ ports = {
366+ 80 : "http" ,
367+ 443 : "https" ,
368+ }
369+
370+ addresses = ["::1" , "::" , "::0" ]
371+ address_num = {"::0" : "::" }
372+
373+ cases = []
374+
375+ for address in addresses :
376+ for port , port_name in ports .items ():
377+ cases .append ((((address , port ), 0 ), (host , port_name )))
378+ cases .append ((((address , port ), _socket .NI_NUMERICHOST | _socket .NI_NUMERICSERV ), (address_num .get (address , address ), str (port ))))
379+
380+ for args , result in cases :
381+ self .assertEqual (_socket .getnameinfo (* args ), result )
382+
361383 def test_gethostbyaddr (self ):
362384 '''Tests _socket.gethostbyaddr'''
363385 _socket .gethostbyaddr ("localhost" )
0 commit comments