annotate Lib/test/test_mimetools.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 44019e37ac92
children 6768b2350c57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29230
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
1 import unittest
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
2 from test import test_support
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
3
47640
44019e37ac92 deprecated mimetools
Benjamin Peterson <benjamin@python.org>
parents: 39108
diff changeset
4 import string
44019e37ac92 deprecated mimetools
Benjamin Peterson <benjamin@python.org>
parents: 39108
diff changeset
5 import StringIO
44019e37ac92 deprecated mimetools
Benjamin Peterson <benjamin@python.org>
parents: 39108
diff changeset
6
44019e37ac92 deprecated mimetools
Benjamin Peterson <benjamin@python.org>
parents: 39108
diff changeset
7 mimetools = test_support.import_module("mimetools", deprecated=True)
29230
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
8
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
9 msgtext1 = mimetools.Message(StringIO.StringIO(
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
10 """Content-Type: text/plain; charset=iso-8859-1; format=flowed
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
11 Content-Transfer-Encoding: 8bit
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
12
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
13 Foo!
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
14 """))
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
15
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
16 class MimeToolsTest(unittest.TestCase):
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
17
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
18 def test_decodeencode(self):
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
19 start = string.ascii_letters + "=" + string.digits + "\n"
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
20 for enc in ['7bit','8bit','base64','quoted-printable',
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
21 'uuencode', 'x-uuencode', 'uue', 'x-uue']:
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
22 i = StringIO.StringIO(start)
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
23 o = StringIO.StringIO()
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
24 mimetools.encode(i, o, enc)
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
25 i = StringIO.StringIO(o.getvalue())
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
26 o = StringIO.StringIO()
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
27 mimetools.decode(i, o, enc)
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
28 self.assertEqual(o.getvalue(), start)
14937
fd7f879aff81 Add mimetools testcase.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
29
29230
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
30 def test_boundary(self):
39108
008941521805 Remove usage of sets module (patch #1500609).
Georg Brandl <georg@python.org>
parents: 29488
diff changeset
31 s = set([""])
29230
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
32 for i in xrange(100):
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
33 nb = mimetools.choose_boundary()
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
34 self.assert_(nb not in s)
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
35 s.add(nb)
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
36
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
37 def test_message(self):
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
38 msg = mimetools.Message(StringIO.StringIO(msgtext1))
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
39 self.assertEqual(msg.gettype(), "text/plain")
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
40 self.assertEqual(msg.getmaintype(), "text")
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
41 self.assertEqual(msg.getsubtype(), "plain")
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
42 self.assertEqual(msg.getplist(), ["charset=iso-8859-1", "format=flowed"])
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
43 self.assertEqual(msg.getparamnames(), ["charset", "format"])
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
44 self.assertEqual(msg.getparam("charset"), "iso-8859-1")
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
45 self.assertEqual(msg.getparam("format"), "flowed")
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
46 self.assertEqual(msg.getparam("spam"), None)
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
47 self.assertEqual(msg.getencoding(), "8bit")
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
48
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
49 def test_main():
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
50 test_support.run_unittest(MimeToolsTest)
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
51
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
52 if __name__=="__main__":
bd82161b61e5 Port test_mimetools.py to PyUnit and add various tests.
Walter Dörwald <walter@livinglogic.de>
parents: 24364
diff changeset
53 test_main()