@@ -158,32 +158,6 @@ def test_debuglevel_2(self):
158158 re .MULTILINE )
159159 self .assertRegex (stderr .getvalue (), expected )
160160
161- def test_host_port_host (self ):
162- mock_socket .reply_with (b"220 Hello world" )
163- # create instance without arguments
164- smtp = smtplib .SMTP (f"{ HOST } :{ self .port } " )
165- # .connect must set ._host since it is used by .starttls
166- self .assertEqual (smtp ._host , HOST )
167- smtp .close ()
168-
169- def test_explicit_connect (self ):
170- mock_socket .reply_with (b"220 Hello world" )
171- # create instance without arguments
172- smtp = smtplib .SMTP ()
173- # .connect must set ._host since it is used by .starttls
174- smtp .connect (HOST , self .port )
175- self .assertEqual (smtp ._host , HOST )
176- smtp .close ()
177-
178- def test_explicit_connect_host_port (self ):
179- mock_socket .reply_with (b"220 Hello world" )
180- # create instance without arguments
181- smtp = smtplib .SMTP ()
182- # .connect must set ._host since it is used by .starttls
183- smtp .connect (f"{ HOST } :{ self .port } " )
184- self .assertEqual (smtp ._host , HOST )
185- smtp .close ()
186-
187161
188162class SMTPGeneralTests (GeneralTests , unittest .TestCase ):
189163
@@ -308,6 +282,34 @@ def testBasic(self):
308282 # connect
309283 smtp = smtplib .SMTP (HOST , self .port , local_hostname = 'localhost' ,
310284 timeout = support .LOOPBACK_TIMEOUT )
285+ # implicit .connect must set ._host since it is used by .starttls
286+ self .assertEqual (smtp ._host , HOST )
287+ smtp .quit ()
288+
289+ def test_host_port_host (self ):
290+ # create instance with host:port notation
291+ smtp = smtplib .SMTP (f"{ HOST } :{ self .port } " , local_hostname = 'localhost' ,
292+ timeout = support .LOOPBACK_TIMEOUT )
293+ # implicit .connect must set ._host since it is used by .starttls
294+ self .assertEqual (smtp ._host , HOST )
295+ smtp .quit ()
296+
297+ def test_explicit_connect (self ):
298+ # create instance without arguments
299+ smtp = smtplib .SMTP (local_hostname = 'localhost' ,
300+ timeout = support .LOOPBACK_TIMEOUT )
301+ # explicit .connect must set ._host since it is used by .starttls
302+ smtp .connect (HOST , self .port )
303+ self .assertEqual (smtp ._host , HOST )
304+ smtp .quit ()
305+
306+ def test_explicit_connect_host_port (self ):
307+ # create instance without arguments
308+ smtp = smtplib .SMTP (local_hostname = 'localhost' ,
309+ timeout = support .LOOPBACK_TIMEOUT )
310+ # explicit .connect with host:port notation must set ._host, too
311+ smtp .connect (f"{ HOST } :{ self .port } " )
312+ self .assertEqual (smtp ._host , HOST )
311313 smtp .quit ()
312314
313315 def testSourceAddress (self ):
0 commit comments