PyXR

c:\python24\lib \ test \ test_mimetools.py



0001 import unittest
0002 from test import test_support
0003 
0004 import string, StringIO, mimetools, sets
0005 
0006 msgtext1 = mimetools.Message(StringIO.StringIO(
0007 """Content-Type: text/plain; charset=iso-8859-1; format=flowed
0008 Content-Transfer-Encoding: 8bit
0009 
0010 Foo!
0011 """))
0012 
0013 class MimeToolsTest(unittest.TestCase):
0014 
0015     def test_decodeencode(self):
0016         start = string.ascii_letters + "=" + string.digits + "\n"
0017         for enc in ['7bit','8bit','base64','quoted-printable',
0018                     'uuencode', 'x-uuencode', 'uue', 'x-uue']:
0019             i = StringIO.StringIO(start)
0020             o = StringIO.StringIO()
0021             mimetools.encode(i, o, enc)
0022             i = StringIO.StringIO(o.getvalue())
0023             o = StringIO.StringIO()
0024             mimetools.decode(i, o, enc)
0025             self.assertEqual(o.getvalue(), start)
0026 
0027     def test_boundary(self):
0028         s = sets.Set([""])
0029         for i in xrange(100):
0030             nb = mimetools.choose_boundary()
0031             self.assert_(nb not in s)
0032             s.add(nb)
0033 
0034     def test_message(self):
0035         msg = mimetools.Message(StringIO.StringIO(msgtext1))
0036         self.assertEqual(msg.gettype(), "text/plain")
0037         self.assertEqual(msg.getmaintype(), "text")
0038         self.assertEqual(msg.getsubtype(), "plain")
0039         self.assertEqual(msg.getplist(), ["charset=iso-8859-1", "format=flowed"])
0040         self.assertEqual(msg.getparamnames(), ["charset", "format"])
0041         self.assertEqual(msg.getparam("charset"), "iso-8859-1")
0042         self.assertEqual(msg.getparam("format"), "flowed")
0043         self.assertEqual(msg.getparam("spam"), None)
0044         self.assertEqual(msg.getencoding(), "8bit")
0045 
0046 def test_main():
0047     test_support.run_unittest(MimeToolsTest)
0048 
0049 if __name__=="__main__":
0050     test_main()
0051 

Generated by PyXR 0.9.4
SourceForge.net Logo