2 from test
import test_support
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
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
):
33 nb
= mimetools
.choose_boundary()
34 self
.assertNotIn(nb
, s
)
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")
50 test_support
.run_unittest(MimeToolsTest
)
52 if __name__
=="__main__":