From 4627ad9743964c93f65f508e513c198d6bd2fe91 Mon Sep 17 00:00:00 2001 From: Chason Chaffin Date: Thu, 25 Jan 2018 18:05:43 +0900 Subject: [PATCH 1/3] bpo-32663 Make SMTPUTF8SimTests run The tests for SMTPUTF8SimTests in test_smtplib.py were not actually being run because they were never added to test_main. Additionally, one of the tests needed to be in the non-UTF8 server class because it relied on the server not being UTF-8 compatible. --- Lib/test/test_smtplib.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py index 040ad4e05962ba..a89f7a9181e73b 100644 --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -1072,6 +1072,19 @@ def test_send_unicode_without_SMTPUTF8(self): self.assertRaises(UnicodeEncodeError, smtp.sendmail, 'Alice', 'Böb', '') self.assertRaises(UnicodeEncodeError, smtp.mail, 'Älice') + def test_send_message_error_on_non_ascii_addrs_if_no_smtputf8(self): + # This test is located here and not in the SMTPUTF8SimTests + # class because it needs a "regular" SMTP server to work + msg = EmailMessage() + msg['From'] = "Páolo " + msg['To'] = 'Dinsdale' + msg['Subject'] = 'Nudge nudge, wink, wink \u1F609' + smtp = smtplib.SMTP( + HOST, self.port, local_hostname='localhost', timeout=3) + self.addCleanup(smtp.close) + with self.assertRaises(smtplib.SMTPNotSupportedError): + smtp.send_message(msg) + class SimSMTPUTF8Server(SimSMTPServer): @@ -1201,17 +1214,6 @@ def test_send_message_uses_smtputf8_if_addrs_non_ascii(self): self.assertIn('SMTPUTF8', self.serv.last_mail_options) self.assertEqual(self.serv.last_rcpt_options, []) - def test_send_message_error_on_non_ascii_addrs_if_no_smtputf8(self): - msg = EmailMessage() - msg['From'] = "Páolo " - msg['To'] = 'Dinsdale' - msg['Subject'] = 'Nudge nudge, wink, wink \u1F609' - smtp = smtplib.SMTP( - HOST, self.port, local_hostname='localhost', timeout=3) - self.addCleanup(smtp.close) - self.assertRaises(smtplib.SMTPNotSupportedError, - smtp.send_message(msg)) - EXPECTED_RESPONSE = encode_base64(b'\0psu\0doesnotexist', eol='') @@ -1289,6 +1291,7 @@ def test_main(verbose=None): SMTPAUTHInitialResponseSimTests, SMTPSimTests, TooLongLineTests, + SMTPUTF8SimTests, ) From 5339be20ac8d9b201da8c31c96bd82b6d0ef25d6 Mon Sep 17 00:00:00 2001 From: Chason Chaffin Date: Thu, 25 Jan 2018 18:10:55 +0900 Subject: [PATCH 2/3] bpo-32663 Adding NEWS entry --- Misc/NEWS.d/next/Tests/2018-01-25-18-10-47.bpo-32663.IKDsqu.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2018-01-25-18-10-47.bpo-32663.IKDsqu.rst diff --git a/Misc/NEWS.d/next/Tests/2018-01-25-18-10-47.bpo-32663.IKDsqu.rst b/Misc/NEWS.d/next/Tests/2018-01-25-18-10-47.bpo-32663.IKDsqu.rst new file mode 100644 index 00000000000000..8357284e573488 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2018-01-25-18-10-47.bpo-32663.IKDsqu.rst @@ -0,0 +1,2 @@ +Making sure the `SMTPUTF8SimTests` class of tests gets run in +test_smtplib.py. From 20d6b88786de4c6dc259958f0a7b20b713113313 Mon Sep 17 00:00:00 2001 From: Chason Chaffin Date: Fri, 26 Jan 2018 10:17:25 +0900 Subject: [PATCH 3/3] bpo-32663 Modernize call to unittest Updating __main__ to call unittest.main() as per bitdancer's request --- Lib/test/test_smtplib.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py index a89f7a9181e73b..02aa6e0a39660e 100644 --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -1281,19 +1281,5 @@ def testAUTH_PLAIN_initial_response_auth(self): self.assertEqual(code, 235) -@support.reap_threads -def test_main(verbose=None): - support.run_unittest( - BadHELOServerTests, - DebuggingServerTests, - GeneralTests, - NonConnectingTests, - SMTPAUTHInitialResponseSimTests, - SMTPSimTests, - TooLongLineTests, - SMTPUTF8SimTests, - ) - - if __name__ == '__main__': - test_main() + unittest.main()