[Python-checkins] [3.10] bpo-19460: Add test for MIMENonMultipart (GH-29817) (GH-29818)

asvetlov webhook-mailer at python.org
Sun Nov 28 05:57:15 EST 2021


https://github.com/python/cpython/commit/2c398a5acf85d1bbc5796f3385972d0759b90e54
commit: 2c398a5acf85d1bbc5796f3385972d0759b90e54
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: asvetlov <andrew.svetlov at gmail.com>
date: 2021-11-28T12:57:10+02:00
summary:

[3.10] bpo-19460: Add test for MIMENonMultipart (GH-29817) (GH-29818)


Co-authored-by: 180909 <wjh180909 at gmail.com>
Co-authored-by: Andrew Svetlov <andrew.svetlov at gmail.com>

files:
A Misc/NEWS.d/next/Tests/2021-11-28-15-25-02.bpo-19460.lr0aWs.rst
M Lib/test/test_email/test_email.py

diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 54ffcdc544e8b..a3ccbbbabfb32 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -2743,6 +2743,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 0000000000000..b082d6de20c07
--- /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 :class:`email.mime.nonmultipart.MIMENonMultipart`.



More information about the Python-checkins mailing list