+++ /dev/null
-# Copyright (C) 2002-2004 Python Software Foundation\r
-#\r
-# A torture test of the email package. This should not be run as part of the\r
-# standard Python test suite since it requires several meg of email messages\r
-# collected in the wild. These source messages are not checked into the\r
-# Python distro, but are available as part of the standalone email package at\r
-# http://sf.net/projects/mimelib\r
-\r
-import sys\r
-import os\r
-import unittest\r
-from cStringIO import StringIO\r
-from types import ListType\r
-\r
-from email.test.test_email import TestEmailBase\r
-from test.test_support import TestSkipped, run_unittest\r
-\r
-import email\r
-from email import __file__ as testfile\r
-from email.iterators import _structure\r
-\r
-def openfile(filename):\r
- from os.path import join, dirname, abspath\r
- path = abspath(join(dirname(testfile), os.pardir, 'moredata', filename))\r
- return open(path, 'r')\r
-\r
-# Prevent this test from running in the Python distro\r
-try:\r
- openfile('crispin-torture.txt')\r
-except IOError:\r
- raise TestSkipped\r
-\r
-\r
-\f\r
-class TortureBase(TestEmailBase):\r
- def _msgobj(self, filename):\r
- fp = openfile(filename)\r
- try:\r
- msg = email.message_from_file(fp)\r
- finally:\r
- fp.close()\r
- return msg\r
-\r
-\r
-\f\r
-class TestCrispinTorture(TortureBase):\r
- # Mark Crispin's torture test from the SquirrelMail project\r
- def test_mondo_message(self):\r
- eq = self.assertEqual\r
- neq = self.ndiffAssertEqual\r
- msg = self._msgobj('crispin-torture.txt')\r
- payload = msg.get_payload()\r
- eq(type(payload), ListType)\r
- eq(len(payload), 12)\r
- eq(msg.preamble, None)\r
- eq(msg.epilogue, '\n')\r
- # Probably the best way to verify the message is parsed correctly is to\r
- # dump its structure and compare it against the known structure.\r
- fp = StringIO()\r
- _structure(msg, fp=fp)\r
- neq(fp.getvalue(), """\\r
-multipart/mixed\r
- text/plain\r
- message/rfc822\r
- multipart/alternative\r
- text/plain\r
- multipart/mixed\r
- text/richtext\r
- application/andrew-inset\r
- message/rfc822\r
- audio/basic\r
- audio/basic\r
- image/pbm\r
- message/rfc822\r
- multipart/mixed\r
- multipart/mixed\r
- text/plain\r
- audio/x-sun\r
- multipart/mixed\r
- image/gif\r
- image/gif\r
- application/x-be2\r
- application/atomicmail\r
- audio/x-sun\r
- message/rfc822\r
- multipart/mixed\r
- text/plain\r
- image/pgm\r
- text/plain\r
- message/rfc822\r
- multipart/mixed\r
- text/plain\r
- image/pbm\r
- message/rfc822\r
- application/postscript\r
- image/gif\r
- message/rfc822\r
- multipart/mixed\r
- audio/basic\r
- audio/basic\r
- message/rfc822\r
- multipart/mixed\r
- application/postscript\r
- text/plain\r
- message/rfc822\r
- multipart/mixed\r
- text/plain\r
- multipart/parallel\r
- image/gif\r
- audio/basic\r
- application/atomicmail\r
- message/rfc822\r
- audio/x-sun\r
-""")\r
-\r
-\f\r
-def _testclasses():\r
- mod = sys.modules[__name__]\r
- return [getattr(mod, name) for name in dir(mod) if name.startswith('Test')]\r
-\r
-\r
-def suite():\r
- suite = unittest.TestSuite()\r
- for testclass in _testclasses():\r
- suite.addTest(unittest.makeSuite(testclass))\r
- return suite\r
-\r
-\r
-def test_main():\r
- for testclass in _testclasses():\r
- run_unittest(testclass)\r
-\r
-\r
-\f\r
-if __name__ == '__main__':\r
- unittest.main(defaultTest='suite')\r