Skip to content

Commit cecbe0a

Browse files
miss-islingtonchason
authored andcommitted
bpo-32663 Make SMTPUTF8SimTests run (GH-5314) (#8470)
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 cfadd1c commit cecbe0a

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
@@ -1068,6 +1068,19 @@ def test_send_unicode_without_SMTPUTF8(self):
10681068
self.assertRaises(UnicodeEncodeError, smtp.sendmail, 'Alice', 'Böb', '')
10691069
self.assertRaises(UnicodeEncodeError, smtp.mail, 'Älice')
10701070

1071+
def test_send_message_error_on_non_ascii_addrs_if_no_smtputf8(self):
1072+
# This test is located here and not in the SMTPUTF8SimTests
1073+
# class because it needs a "regular" SMTP server to work
1074+
msg = EmailMessage()
1075+
msg['From'] = "Páolo <fő[email protected]>"
1076+
msg['To'] = 'Dinsdale'
1077+
msg['Subject'] = 'Nudge nudge, wink, wink \u1F609'
1078+
smtp = smtplib.SMTP(
1079+
HOST, self.port, local_hostname='localhost', timeout=3)
1080+
self.addCleanup(smtp.close)
1081+
with self.assertRaises(smtplib.SMTPNotSupportedError):
1082+
smtp.send_message(msg)
1083+
10711084
def test_name_field_not_included_in_envelop_addresses(self):
10721085
smtp = smtplib.SMTP(
10731086
HOST, self.port, local_hostname='localhost', timeout=3
@@ -1213,17 +1226,6 @@ def test_send_message_uses_smtputf8_if_addrs_non_ascii(self):
12131226
self.assertIn('SMTPUTF8', self.serv.last_mail_options)
12141227
self.assertEqual(self.serv.last_rcpt_options, [])
12151228

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

12281230
EXPECTED_RESPONSE = encode_base64(b'\0psu\0doesnotexist', eol='')
12291231

@@ -1292,18 +1294,5 @@ def testAUTH_PLAIN_initial_response_auth(self):
12921294
self.assertEqual(code, 235)
12931295

12941296

1295-
@support.reap_threads
1296-
def test_main(verbose=None):
1297-
support.run_unittest(
1298-
BadHELOServerTests,
1299-
DebuggingServerTests,
1300-
GeneralTests,
1301-
NonConnectingTests,
1302-
SMTPAUTHInitialResponseSimTests,
1303-
SMTPSimTests,
1304-
TooLongLineTests,
1305-
)
1306-
1307-
13081297
if __name__ == '__main__':
1309-
test_main()
1298+
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)