1 # Copyright (C) 2002-2004 Python Software Foundation
3 # A torture test of the email package. This should not be run as part of the
4 # standard Python test suite since it requires several meg of email messages
5 # collected in the wild. These source messages are not checked into the
6 # Python distro, but are available as part of the standalone email package at
7 # http://sf.net/projects/mimelib
12 from cStringIO import StringIO
13 from types import ListType
15 from email.test.test_email import TestEmailBase
16 from test.test_support import TestSkipped
19 from email import __file__ as testfile
20 from email.iterators import _structure
22 def openfile(filename):
23 from os.path import join, dirname, abspath
24 path = abspath(join(dirname(testfile), os.pardir, 'moredata', filename))
25 return open(path, 'r')
27 # Prevent this test from running in the Python distro
29 openfile('crispin-torture.txt')
35 class TortureBase(TestEmailBase):
36 def _msgobj(self, filename):
37 fp = openfile(filename)
39 msg = email.message_from_file(fp)
46 class TestCrispinTorture(TortureBase):
47 # Mark Crispin's torture test from the SquirrelMail project
48 def test_mondo_message(self):
50 neq = self.ndiffAssertEqual
51 msg = self._msgobj('crispin-torture.txt')
52 payload = msg.get_payload()
53 eq(type(payload), ListType)
55 eq(msg.preamble, None)
56 eq(msg.epilogue, '\n')
57 # Probably the best way to verify the message is parsed correctly is to
58 # dump its structure and compare it against the known structure.
60 _structure(msg, fp=fp)
61 neq(fp.getvalue(), """\
69 application/andrew-inset
83 application/atomicmail
95 application/postscript
103 application/postscript
111 application/atomicmail
118 mod = sys.modules[__name__]
119 return [getattr(mod, name) for name in dir(mod) if name.startswith('Test')]
123 suite = unittest.TestSuite()
124 for testclass in _testclasses():
125 suite.addTest(unittest.makeSuite(testclass))
130 for testclass in _testclasses():
131 test_support.run_unittest(testclass)
135 if __name__ == '__main__':
136 unittest.main(defaultTest='suite')