Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move and rename tests
  • Loading branch information
nmartensen committed Feb 19, 2024
commit 5ea81fce9ee1095b25311eef460848688afce5fc
54 changes: 28 additions & 26 deletions Lib/test/test_smtplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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)
Comment thread
bitdancer marked this conversation as resolved.
Outdated
smtp.quit()

def testSourceAddress(self):
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_smtpnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading