]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-19460: Add test for MIMENonMultipart (GH-29817)
author180909 <wjh180909@gmail.com>
Sun, 28 Nov 2021 09:24:41 +0000 (17:24 +0800)
committerGitHub <noreply@github.com>
Sun, 28 Nov 2021 09:24:41 +0000 (11:24 +0200)
Lib/test/test_email/test_email.py
Misc/NEWS.d/next/Tests/2021-11-28-15-25-02.bpo-19460.lr0aWs.rst [new file with mode: 0644]

index 54ffcdc544e8bbfcd6d7dd7d41f9676b02cd8ef8..a3ccbbbabfb328f25870df6b8d7750f044ee92f3 100644 (file)
@@ -2743,6 +2743,20 @@ message 2
         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 (file)
index 0000000..e2d3d95
--- /dev/null
@@ -0,0 +1 @@
+Add new Test for ``Lib/email/mime/nonmultipart.py::MIMENonMultipart``.