PageRenderTime 243ms CodeModel.GetById 90ms app.highlight 7ms RepoModel.GetById 144ms app.codeStats 0ms

/Lib/test/test_mimetools.py

http://unladen-swallow.googlecode.com/
Python | 53 lines | 46 code | 3 blank | 4 comment | 0 complexity | 37ef67acdc1cdfb066a6d25d300d6d79 MD5 | raw file
 1import unittest
 2from test import test_support
 3
 4import string
 5import StringIO
 6
 7mimetools = test_support.import_module("mimetools", deprecated=True)
 8
 9msgtext1 = mimetools.Message(StringIO.StringIO(
10"""Content-Type: text/plain; charset=iso-8859-1; format=flowed
11Content-Transfer-Encoding: 8bit
12
13Foo!
14"""))
15
16class MimeToolsTest(unittest.TestCase):
17
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)
29
30    def test_boundary(self):
31        s = set([""])
32        for i in xrange(100):
33            nb = mimetools.choose_boundary()
34            self.assert_(nb not in s)
35            s.add(nb)
36
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")
48
49def test_main():
50    test_support.run_unittest(MimeToolsTest)
51
52if __name__=="__main__":
53    test_main()