# Copyright (C) 2002-2004 Python Software Foundation
# A torture test of the email package. This should not be run as part of the
# standard Python test suite since it requires several meg of email messages
# collected in the wild. These source messages are not checked into the
# Python distro, but are available as part of the standalone email package at
# http://sf.net/projects/mimelib
from cStringIO
import StringIO
from types
import ListType
from email
.test
.test_email
import TestEmailBase
from test
.test_support
import TestSkipped
from email
import __file__
as testfile
from email
.Iterators
import _structure
from os
.path
import join
, dirname
, abspath
path
= abspath(join(dirname(testfile
), os
.pardir
, 'moredata', filename
))
# Prevent this test from running in the Python distro
openfile('crispin-torture.txt')
class TortureBase(TestEmailBase
):
def _msgobj(self
, filename
):
msg
= email
.message_from_file(fp
)
class TestCrispinTorture(TortureBase
):
# Mark Crispin's torture test from the SquirrelMail project
def test_mondo_message(self
):
neq
= self
.ndiffAssertEqual
msg
= self
._msgobj
('crispin-torture.txt')
payload
= msg
.get_payload()
eq(type(payload
), ListType
)
# Probably the best way to verify the message is parsed correctly is to
# dump its structure and compare it against the known structure.
mod
= sys
.modules
[__name__
]
return [getattr(mod
, name
) for name
in dir(mod
) if name
.startswith('Test')]
suite
= unittest
.TestSuite()
for testclass
in _testclasses():
suite
.addTest(unittest
.makeSuite(testclass
))
for testclass
in _testclasses():
test_support
.run_unittest(testclass
)
if __name__
== '__main__':
unittest
.main(defaultTest
='suite')