@@ -142,26 +142,6 @@ def test_port_parameter_types(self):
142142 (INET , STREAM , TCP , '' , ('1.2.3.4' , 1 )),
143143 base_events ._ipaddr_info ('1.2.3.4' , b'1' , INET , STREAM , TCP ))
144144
145- def test_getaddrinfo_servname (self ):
146- INET = socket .AF_INET
147- STREAM = socket .SOCK_STREAM
148- TCP = socket .IPPROTO_TCP
149-
150- self .assertEqual (
151- (INET , STREAM , TCP , '' , ('1.2.3.4' , 80 )),
152- base_events ._ipaddr_info ('1.2.3.4' , 'http' , INET , STREAM , TCP ))
153-
154- self .assertEqual (
155- (INET , STREAM , TCP , '' , ('1.2.3.4' , 80 )),
156- base_events ._ipaddr_info ('1.2.3.4' , b'http' , INET , STREAM , TCP ))
157-
158- # Raises "service/proto not found".
159- with self .assertRaises (OSError ):
160- base_events ._ipaddr_info ('1.2.3.4' , 'nonsense' , INET , STREAM , TCP )
161-
162- with self .assertRaises (OSError ):
163- base_events ._ipaddr_info ('1.2.3.4' , 'nonsense' , INET , STREAM , TCP )
164-
165145 @patch_socket
166146 def test_ipaddr_info_no_inet_pton (self , m_socket ):
167147 del m_socket .inet_pton
@@ -1209,6 +1189,37 @@ def test_create_connection_ip_addr(self, m_socket):
12091189 def test_create_connection_no_inet_pton (self , m_socket ):
12101190 self ._test_create_connection_ip_addr (m_socket , False )
12111191
1192+ @patch_socket
1193+ def test_create_connection_service_name (self , m_socket ):
1194+ m_socket .getaddrinfo = socket .getaddrinfo
1195+ sock = m_socket .socket .return_value
1196+
1197+ self .loop .add_reader = mock .Mock ()
1198+ self .loop .add_reader ._is_coroutine = False
1199+ self .loop .add_writer = mock .Mock ()
1200+ self .loop .add_writer ._is_coroutine = False
1201+
1202+ for service , port in ('http' , 80 ), (b'http' , 80 ):
1203+ coro = self .loop .create_connection (asyncio .Protocol ,
1204+ '127.0.0.1' , service )
1205+
1206+ t , p = self .loop .run_until_complete (coro )
1207+ try :
1208+ sock .connect .assert_called_with (('127.0.0.1' , port ))
1209+ _ , kwargs = m_socket .socket .call_args
1210+ self .assertEqual (kwargs ['family' ], m_socket .AF_INET )
1211+ self .assertEqual (kwargs ['type' ], m_socket .SOCK_STREAM )
1212+ finally :
1213+ t .close ()
1214+ test_utils .run_briefly (self .loop ) # allow transport to close
1215+
1216+ for service in 'nonsense' , b'nonsense' :
1217+ coro = self .loop .create_connection (asyncio .Protocol ,
1218+ '127.0.0.1' , service )
1219+
1220+ with self .assertRaises (OSError ):
1221+ self .loop .run_until_complete (coro )
1222+
12121223 def test_create_connection_no_local_addr (self ):
12131224 @asyncio .coroutine
12141225 def getaddrinfo (host , * args , ** kw ):
0 commit comments