move sections
[python/dscho.git] / Lib / test / test_mimetools.py
blob86a26dc7e5a2911201e23d94736a0a6fc25410a5
1 import unittest
2 from test import test_support
4 import string
5 import StringIO
7 mimetools = test_support.import_module("mimetools", deprecated=True)
9 msgtext1 = mimetools.Message(StringIO.StringIO(
10 """Content-Type: text/plain; charset=iso-8859-1; format=flowed
11 Content-Transfer-Encoding: 8bit
13 Foo!
14 """))
16 class MimeToolsTest(unittest.TestCase):
18 def test_decodeencode(self):
19 start = string.ascii_letters + "=" + string.digits + "\n"
20 for enc in ['7bit','8bit','base64','quoted-printable',
21 'uuencode', 'x-uuencode', 'uue', 'x-uue']:
22 i = StringIO.StringIO(start)
23 o = StringIO.StringIO()
24 mimetools.encode(i, o, enc)
25 i = StringIO.StringIO(o.getvalue())
26 o = StringIO.StringIO()
27 mimetools.decode(i, o, enc)
28 self.assertEqual(o.getvalue(), start)
30 def test_boundary(self):
31 s = set([""])
32 for i in xrange(100):
33 nb = mimetools.choose_boundary()
34 self.assertNotIn(nb, s)
35 s.add(nb)
37 def test_message(self):
38 msg = mimetools.Message(StringIO.StringIO(msgtext1))
39 self.assertEqual(msg.gettype(), "text/plain")
40 self.assertEqual(msg.getmaintype(), "text")
41 self.assertEqual(msg.getsubtype(), "plain")
42 self.assertEqual(msg.getplist(), ["charset=iso-8859-1", "format=flowed"])
43 self.assertEqual(msg.getparamnames(), ["charset", "format"])
44 self.assertEqual(msg.getparam("charset"), "iso-8859-1")
45 self.assertEqual(msg.getparam("format"), "flowed")
46 self.assertEqual(msg.getparam("spam"), None)
47 self.assertEqual(msg.getencoding(), "8bit")
49 def test_main():
50 test_support.run_unittest(MimeToolsTest)
52 if __name__=="__main__":
53 test_main()