From 10beb47d1b20bd033974d14a42d6203dd9bbbd20 Mon Sep 17 00:00:00 2001 From: 180909 Date: Sun, 28 Nov 2021 17:24:41 +0800 Subject: [PATCH 1/2] bpo-19460: Add test for MIMENonMultipart (GH-29817) (cherry picked from commit 46c8d915715aa2bd4d697482aa051fe974d440e1) Co-authored-by: 180909 --- Lib/test/test_email/test_email.py | 14 ++++++++++++++ .../Tests/2021-11-28-15-25-02.bpo-19460.lr0aWs.rst | 1 + 2 files changed, 15 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2021-11-28-15-25-02.bpo-19460.lr0aWs.rst diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index bc062b5cb0c591..489cd05be4dd58 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -2742,6 +2742,20 @@ def test_multipart_custom_policy(self): self.assertEqual(str(cm.exception), 'There may be at most 1 To headers in a message') + +# Test the NonMultipart class +class TestNonMultipart(TestEmailBase): + def test_nonmultipart_is_not_multipart(self): + msg = MIMENonMultipart('text', 'plain') + self.assertFalse(msg.is_multipart()) + + def test_attach_raises_exception(self): + msg = Message() + msg['Subject'] = 'subpart 1' + r = MIMENonMultipart('text', 'plain') + self.assertRaises(errors.MultipartConversionError, r.attach, msg) + + # A general test of parser->model->generator idempotency. IOW, read a message # in, parse it into a message object tree, then without touching the tree, # regenerate the plain text. The original text and the transformed text diff --git a/Misc/NEWS.d/next/Tests/2021-11-28-15-25-02.bpo-19460.lr0aWs.rst b/Misc/NEWS.d/next/Tests/2021-11-28-15-25-02.bpo-19460.lr0aWs.rst new file mode 100644 index 00000000000000..e2d3d9526ecab9 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2021-11-28-15-25-02.bpo-19460.lr0aWs.rst @@ -0,0 +1 @@ +Add new Test for ``Lib/email/mime/nonmultipart.py::MIMENonMultipart``. From 0c6f5ceef52aa968b7f93d877bac2ffa57a3ebcb Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sun, 28 Nov 2021 12:58:20 +0200 Subject: [PATCH 2/2] Update 2021-11-28-15-25-02.bpo-19460.lr0aWs.rst --- Misc/NEWS.d/next/Tests/2021-11-28-15-25-02.bpo-19460.lr0aWs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2021-11-28-15-25-02.bpo-19460.lr0aWs.rst b/Misc/NEWS.d/next/Tests/2021-11-28-15-25-02.bpo-19460.lr0aWs.rst index e2d3d9526ecab9..b082d6de20c079 100644 --- a/Misc/NEWS.d/next/Tests/2021-11-28-15-25-02.bpo-19460.lr0aWs.rst +++ b/Misc/NEWS.d/next/Tests/2021-11-28-15-25-02.bpo-19460.lr0aWs.rst @@ -1 +1 @@ -Add new Test for ``Lib/email/mime/nonmultipart.py::MIMENonMultipart``. +Add new Test for :class:`email.mime.nonmultipart.MIMENonMultipart`.