[Python-checkins] python/dist/src/Lib/email/test test_email.py,1.18,1.19
bwarsaw@users.sourceforge.net
bwarsaw@users.sourceforge.net
Thu, 10 Oct 2002 08:14:25 -0700
Update of /cvsroot/python/python/dist/src/Lib/email/test
In directory usw-pr-cvs1:/tmp/cvs-serv23990
Modified Files:
test_email.py
Log Message:
New tests to verify that charsets are case insensitive, and that by
default get_body_encoding() cannot be SHORTEST.
Index: test_email.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/test/test_email.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** test_email.py 7 Oct 2002 17:27:55 -0000 1.18
--- test_email.py 10 Oct 2002 15:14:22 -0000 1.19
***************
*** 1690,1693 ****
--- 1690,1727 ----
eq(msg.get_filename(), 'foo\\wacky"name')
+ def test_get_body_encoding_with_bogus_charset(self):
+ charset = Charset('not a charset')
+ self.assertEqual(charset.get_body_encoding(), 'base64')
+
+ def test_get_body_encoding_with_uppercase_charset(self):
+ eq = self.assertEqual
+ msg = Message()
+ msg['Content-Type'] = 'text/plain; charset=UTF-8'
+ eq(msg['content-type'], 'text/plain; charset=UTF-8')
+ charsets = msg.get_charsets()
+ eq(len(charsets), 1)
+ eq(charsets[0], 'utf-8')
+ charset = Charset(charsets[0])
+ eq(charset.get_body_encoding(), 'base64')
+ msg.set_payload('hello world', charset=charset)
+ eq(msg.get_payload(), 'hello world')
+ eq(msg['content-transfer-encoding'], 'base64')
+ # Try another one
+ msg = Message()
+ msg['Content-Type'] = 'text/plain; charset="US-ASCII"'
+ charsets = msg.get_charsets()
+ eq(len(charsets), 1)
+ eq(charsets[0], 'us-ascii')
+ charset = Charset(charsets[0])
+ eq(charset.get_body_encoding(), Encoders.encode_7or8bit)
+ msg.set_payload('hello world', charset=charset)
+ eq(msg.get_payload(), 'hello world')
+ eq(msg['content-transfer-encoding'], '7bit')
+
+ def test_charsets_case_insensitive(self):
+ lc = Charset('us-ascii')
+ uc = Charset('US-ASCII')
+ self.assertEqual(lc.get_body_encoding(), uc.get_body_encoding())
+