[Python-checkins] cpython (merge 3.2 -> default): Merge: Improve message.py test coverage to 100%.

r.david.murray python-checkins at python.org
Sat Apr 16 15:22:38 CEST 2011


http://hg.python.org/cpython/rev/2aea51cb0d1d
changeset:   69393:2aea51cb0d1d
parent:      69391:c49c595e4214
parent:      69392:2596389a993d
user:        R David Murray <rdmurray at bitdance.com>
date:        Sat Apr 16 09:21:49 2011 -0400
summary:
  Merge: Improve message.py test coverage to 100%.

coverage.py reports 99% on branch coverage, but that appears to be
a bug or limitation in coverage.py.

files:
  Lib/test/test_email/test_email.py |  56 +++++++++++++++++++
  1 files changed, 56 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -221,6 +221,10 @@
         msg.set_payload('foo')
         eq(msg.get_payload(decode=True), b'foo')
 
+    def test_get_payload_n_raises_on_non_multipart(self):
+        msg = Message()
+        self.assertRaises(TypeError, msg.get_payload, 1)
+
     def test_decoded_generator(self):
         eq = self.assertEqual
         msg = self._msgobj('msg_07.txt')
@@ -376,6 +380,17 @@
         msg.del_param('filename', 'content-disposition')
         self.assertEqual(msg['content-disposition'], 'attachment')
 
+    def test_del_param_on_nonexistent_header(self):
+        msg = Message()
+        msg.del_param('filename', 'content-disposition')
+
+    def test_del_nonexistent_param(self):
+        msg = Message()
+        msg.add_header('Content-Type', 'text/plain', charset='utf-8')
+        existing_header = msg['Content-Type']
+        msg.del_param('foobar', header='Content-Type')
+        self.assertEqual(msg['Content-Type'], 'text/plain; charset="utf-8"')
+
     def test_set_type(self):
         eq = self.assertEqual
         msg = Message()
@@ -506,6 +521,27 @@
         self.assertEqual(msg.get_payload(decode=True),
                          bytes(x, 'raw-unicode-escape'))
 
+    def test_broken_unicode_payload(self):
+        # This test improves coverage but is not a compliance test.
+        # The behavior in this situation is currently undefined by the API.
+        x = 'this is a br\xf6ken thing to do'
+        msg = Message()
+        msg['content-type'] = 'text/plain'
+        msg['content-transfer-encoding'] = '8bit'
+        msg.set_payload(x)
+        self.assertEqual(msg.get_payload(decode=True),
+                         bytes(x, 'raw-unicode-escape'))
+
+    def test_questionable_bytes_payload(self):
+        # This test improves coverage but is not a compliance test,
+        # since it involves poking inside the black box.
+        x = 'this is a quéstionable thing to do'.encode('utf-8')
+        msg = Message()
+        msg['content-type'] = 'text/plain; charset="utf-8"'
+        msg['content-transfer-encoding'] = '8bit'
+        msg._payload = x
+        self.assertEqual(msg.get_payload(decode=True), x)
+
     # Issue 1078919
     def test_ascii_add_header(self):
         msg = Message()
@@ -546,6 +582,16 @@
             "attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.ppt",
             msg['Content-Disposition'])
 
+    def test_add_header_with_name_only_param(self):
+        msg = Message()
+        msg.add_header('Content-Disposition', 'inline', foo_bar=None)
+        self.assertEqual("inline; foo-bar", msg['Content-Disposition'])
+
+    def test_add_header_with_no_value(self):
+        msg = Message()
+        msg.add_header('X-Status', None)
+        self.assertEqual('', msg['X-Status'])
+
     # Issue 5871: reject an attempt to embed a header inside a header value
     # (header injection attack).
     def test_embeded_header_via_Header_rejected(self):
@@ -4150,6 +4196,16 @@
 -Me
 """)
 
+    def test_set_param_requote(self):
+        msg = Message()
+        msg.set_param('title', 'foo')
+        self.assertEqual(msg['content-type'], 'text/plain; title="foo"')
+        msg.set_param('title', 'bar', requote=False)
+        self.assertEqual(msg['content-type'], 'text/plain; title=bar')
+        # tspecial is still quoted.
+        msg.set_param('title', "(bar)bell", requote=False)
+        self.assertEqual(msg['content-type'], 'text/plain; title="(bar)bell"')
+
     def test_del_param(self):
         eq = self.ndiffAssertEqual
         msg = self._msgobj('msg_01.txt')

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list