Skip to content

Commit 89352b0

Browse files
miss-islingtonchason
authored andcommitted
bpo-32663 Make SMTPUTF8SimTests run (GH-5314) (#8471)
Enable and fix SMTPUTF8SimTests in test_smtplib. The tests for SMTPUTF8SimTests in test_smtplib.py were not actually being run because test_smtplib was still using the 'test_main' pattern, and the class was never added to test_main. Additionally, one of the tests needed to be moved to the non-UTF8 server class because it relies on the server not being UTF-8 compatible (and it had a bug in in). (cherry picked from commit 48ed88a) Co-authored-by: chason <[email protected]>
1 parent 9736493 commit 89352b0

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

Lib/test/test_smtplib.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,19 @@ def test_send_unicode_without_SMTPUTF8(self):
10741074
self.assertRaises(UnicodeEncodeError, smtp.sendmail, 'Alice', 'Böb', '')
10751075
self.assertRaises(UnicodeEncodeError, smtp.mail, 'Älice')
10761076

1077+
def test_send_message_error_on_non_ascii_addrs_if_no_smtputf8(self):
1078+
# This test is located here and not in the SMTPUTF8SimTests
1079+
# class because it needs a "regular" SMTP server to work
1080+
msg = EmailMessage()
1081+
msg['From'] = "Páolo <fő[email protected]>"
1082+
msg['To'] = 'Dinsdale'
1083+
msg['Subject'] = 'Nudge nudge, wink, wink \u1F609'
1084+
smtp = smtplib.SMTP(
1085+
HOST, self.port, local_hostname='localhost', timeout=3)
1086+
self.addCleanup(smtp.close)
1087+
with self.assertRaises(smtplib.SMTPNotSupportedError):
1088+
smtp.send_message(msg)
1089+
10771090
def test_name_field_not_included_in_envelop_addresses(self):
10781091
smtp = smtplib.SMTP(
10791092
HOST, self.port, local_hostname='localhost', timeout=3
@@ -1218,17 +1231,6 @@ def test_send_message_uses_smtputf8_if_addrs_non_ascii(self):
12181231
self.assertIn('SMTPUTF8', self.serv.last_mail_options)
12191232
self.assertEqual(self.serv.last_rcpt_options, [])
12201233

1221-
def test_send_message_error_on_non_ascii_addrs_if_no_smtputf8(self):
1222-
msg = EmailMessage()
1223-
msg['From'] = "Páolo <fő[email protected]>"
1224-
msg['To'] = 'Dinsdale'
1225-
msg['Subject'] = 'Nudge nudge, wink, wink \u1F609'
1226-
smtp = smtplib.SMTP(
1227-
HOST, self.port, local_hostname='localhost', timeout=3)
1228-
self.addCleanup(smtp.close)
1229-
self.assertRaises(smtplib.SMTPNotSupportedError,
1230-
smtp.send_message(msg))
1231-
12321234

12331235
EXPECTED_RESPONSE = encode_base64(b'\0psu\0doesnotexist', eol='')
12341236

@@ -1296,18 +1298,5 @@ def testAUTH_PLAIN_initial_response_auth(self):
12961298
self.assertEqual(code, 235)
12971299

12981300

1299-
@support.reap_threads
1300-
def test_main(verbose=None):
1301-
support.run_unittest(
1302-
BadHELOServerTests,
1303-
DebuggingServerTests,
1304-
GeneralTests,
1305-
NonConnectingTests,
1306-
SMTPAUTHInitialResponseSimTests,
1307-
SMTPSimTests,
1308-
TooLongLineTests,
1309-
)
1310-
1311-
13121301
if __name__ == '__main__':
1313-
test_main()
1302+
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Making sure the `SMTPUTF8SimTests` class of tests gets run in
2+
test_smtplib.py.

0 commit comments

Comments
 (0)