diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py index bea3592b744..3219f725223 100644 --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -158,32 +158,6 @@ def test_debuglevel_2(self): re.MULTILINE) self.assertRegex(stderr.getvalue(), expected) - def test_host_port_host(self): - mock_socket.reply_with(b"220 Hello world") - # create instance without arguments - smtp = smtplib.SMTP(f"{HOST}:{self.port}") - # .connect must set ._host since it is used by .starttls - self.assertEqual(smtp._host, HOST) - smtp.close() - - def test_explicit_connect(self): - mock_socket.reply_with(b"220 Hello world") - # create instance without arguments - smtp = smtplib.SMTP() - # .connect must set ._host since it is used by .starttls - smtp.connect(HOST, self.port) - self.assertEqual(smtp._host, HOST) - smtp.close() - - def test_explicit_connect_host_port(self): - mock_socket.reply_with(b"220 Hello world") - # create instance without arguments - smtp = smtplib.SMTP() - # .connect must set ._host since it is used by .starttls - smtp.connect(f"{HOST}:{self.port}") - self.assertEqual(smtp._host, HOST) - smtp.close() - class SMTPGeneralTests(GeneralTests, unittest.TestCase): @@ -308,6 +282,34 @@ def testBasic(self): # connect smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=support.LOOPBACK_TIMEOUT) + # implicit .connect must set ._host since it is used by .starttls + self.assertEqual(smtp._host, HOST) + smtp.quit() + + def test_host_port_host(self): + # create instance with host:port notation + smtp = smtplib.SMTP(f"{HOST}:{self.port}", local_hostname='localhost', + timeout=support.LOOPBACK_TIMEOUT) + # implicit .connect must set ._host since it is used by .starttls + self.assertEqual(smtp._host, HOST) + smtp.quit() + + def test_explicit_connect(self): + # create instance without arguments + smtp = smtplib.SMTP(local_hostname='localhost', + timeout=support.LOOPBACK_TIMEOUT) + # explicit .connect must set ._host since it is used by .starttls + smtp.connect(HOST, self.port) + self.assertEqual(smtp._host, HOST) + smtp.quit() + + def test_explicit_connect_host_port(self): + # create instance without arguments + smtp = smtplib.SMTP(local_hostname='localhost', + timeout=support.LOOPBACK_TIMEOUT) + # explicit .connect with host:port notation must set ._host, too + smtp.connect(f"{HOST}:{self.port}") + self.assertEqual(smtp._host, HOST) smtp.quit() def testSourceAddress(self): diff --git a/Lib/test/test_smtpnet.py b/Lib/test/test_smtpnet.py index e29385f4f60..86c19fa38c7 100644 --- a/Lib/test/test_smtpnet.py +++ b/Lib/test/test_smtpnet.py @@ -42,7 +42,7 @@ def test_connect_starttls(self): server.ehlo() server.quit() - def test_connect2_starttls(self): + def test_connect_host_port_starttls(self): support.get_attribute(smtplib, 'SMTP_SSL') context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) context.check_hostname = False @@ -59,7 +59,7 @@ def test_connect2_starttls(self): server.ehlo() server.quit() - def test_connect3_starttls(self): + def test_explicit_connect_starttls(self): support.get_attribute(smtplib, 'SMTP_SSL') context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) context.check_hostname = False @@ -77,7 +77,7 @@ def test_connect3_starttls(self): server.ehlo() server.quit() - def test_connect4_starttls(self): + def test_explicit_connect_host_port_starttls(self): support.get_attribute(smtplib, 'SMTP_SSL') context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) context.check_hostname = False