Commit dd0652b6 authored by Barry Warsaw's avatar Barry Warsaw

test_header_splitter(), test_body_line_iterator(): Move the test data

into tests/data/msg_*.txt files.
parent fe46afc5
...@@ -28,14 +28,14 @@ NL = '\n' ...@@ -28,14 +28,14 @@ NL = '\n'
EMPTYSTRING = '' EMPTYSTRING = ''
def openfile(filename): def openfile(filename):
path = os.path.join(os.path.dirname(test.regrtest.__file__), path = os.path.join(os.path.dirname(test.regrtest.__file__),
'data', filename) 'data', filename)
return open(path) return open(path)
# Base test class # Base test class
class TestEmailBase(unittest.TestCase): class TestEmailBase(unittest.TestCase):
def _msgobj(self, filename): def _msgobj(self, filename):
...@@ -47,7 +47,7 @@ class TestEmailBase(unittest.TestCase): ...@@ -47,7 +47,7 @@ class TestEmailBase(unittest.TestCase):
return msg return msg
# Test various aspects of the Message class's API # Test various aspects of the Message class's API
class TestMessageAPI(TestEmailBase): class TestMessageAPI(TestEmailBase):
def test_get_charsets(self): def test_get_charsets(self):
...@@ -217,7 +217,7 @@ class TestMessageAPI(TestEmailBase): ...@@ -217,7 +217,7 @@ class TestMessageAPI(TestEmailBase):
self.failIf(msg.has_key('headeri')) self.failIf(msg.has_key('headeri'))
# Test the email.Encoders module # Test the email.Encoders module
class TestEncoders(unittest.TestCase): class TestEncoders(unittest.TestCase):
def test_encode_noop(self): def test_encode_noop(self):
...@@ -254,7 +254,8 @@ class TestEncoders(unittest.TestCase): ...@@ -254,7 +254,8 @@ class TestEncoders(unittest.TestCase):
eq(msg['content-transfer-encoding'], 'quoted-printable') eq(msg['content-transfer-encoding'], 'quoted-printable')
# Test long header wrapping
class TestLongHeaders(unittest.TestCase): class TestLongHeaders(unittest.TestCase):
def test_header_splitter(self): def test_header_splitter(self):
msg = MIMEText('') msg = MIMEText('')
...@@ -266,17 +267,11 @@ class TestLongHeaders(unittest.TestCase): ...@@ -266,17 +267,11 @@ class TestLongHeaders(unittest.TestCase):
sfp = StringIO() sfp = StringIO()
g = Generator(sfp) g = Generator(sfp)
g(msg) g(msg)
self.assertEqual(sfp.getvalue(), '''\ self.assertEqual(sfp.getvalue(), openfile('msg_18.txt').read())
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals";
\tspooge="yummy"; hippos="gargantuan"; marshmallows="gooey"
''')
# Test mangling of "From " lines in the body of a message
class TestFromMangling(unittest.TestCase): class TestFromMangling(unittest.TestCase):
def setUp(self): def setUp(self):
self.msg = Message() self.msg = Message()
...@@ -309,7 +304,7 @@ Blah blah blah ...@@ -309,7 +304,7 @@ Blah blah blah
""") """)
# Test the basic MIMEImage class # Test the basic MIMEImage class
class TestMIMEImage(unittest.TestCase): class TestMIMEImage(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -362,7 +357,7 @@ class TestMIMEImage(unittest.TestCase): ...@@ -362,7 +357,7 @@ class TestMIMEImage(unittest.TestCase):
header='foobar') is missing) header='foobar') is missing)
# Test the basic MIMEText class # Test the basic MIMEText class
class TestMIMEText(unittest.TestCase): class TestMIMEText(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -383,7 +378,8 @@ class TestMIMEText(unittest.TestCase): ...@@ -383,7 +378,8 @@ class TestMIMEText(unittest.TestCase):
self.failUnless(not self._msg.is_multipart()) self.failUnless(not self._msg.is_multipart())
# Test a more complicated multipart/mixed type message
class TestMultipartMixed(unittest.TestCase): class TestMultipartMixed(unittest.TestCase):
def setUp(self): def setUp(self):
fp = openfile('PyBanner048.gif') fp = openfile('PyBanner048.gif')
...@@ -445,7 +441,8 @@ This is the dingus fish. ...@@ -445,7 +441,8 @@ This is the dingus fish.
unless(not m1.is_multipart()) unless(not m1.is_multipart())
# Test some badly formatted messages
class TestNonConformant(TestEmailBase): class TestNonConformant(TestEmailBase):
def test_parse_missing_minor_type(self): def test_parse_missing_minor_type(self):
eq = self.assertEqual eq = self.assertEqual
...@@ -466,7 +463,8 @@ class TestNonConformant(TestEmailBase): ...@@ -466,7 +463,8 @@ class TestNonConformant(TestEmailBase):
self.assertRaises(Errors.BoundaryError, p.parsestr, data) self.assertRaises(Errors.BoundaryError, p.parsestr, data)
# Test RFC 2047 header encoding and decoding
class TestRFC2047(unittest.TestCase): class TestRFC2047(unittest.TestCase):
def test_iso_8859_1(self): def test_iso_8859_1(self):
eq = self.assertEqual eq = self.assertEqual
...@@ -497,7 +495,8 @@ class TestRFC2047(unittest.TestCase): ...@@ -497,7 +495,8 @@ class TestRFC2047(unittest.TestCase):
'=?iso-8859-2?b?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=') '=?iso-8859-2?b?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=')
# Test the MIMEMessage class
class TestMIMEMessage(TestEmailBase): class TestMIMEMessage(TestEmailBase):
def setUp(self): def setUp(self):
fp = openfile('msg_11.txt') fp = openfile('msg_11.txt')
...@@ -603,7 +602,12 @@ Your message cannot be delivered to the following recipients: ...@@ -603,7 +602,12 @@ Your message cannot be delivered to the following recipients:
'<002001c144a6$8752e060$56104586@oxy.edu>') '<002001c144a6$8752e060$56104586@oxy.edu>')
# A general test of parser->model->generator idempotency. IOW, read a message
# in, parse it into a message object tree, then without touching the tree,
# regenerate the plain text. The original text and the transformed text
# should be identical. Note: that we ignore the Unix-From since that may
# contain a changed date.
class TestIdempotent(unittest.TestCase): class TestIdempotent(unittest.TestCase):
def _msgobj(self, filename): def _msgobj(self, filename):
fp = openfile(filename) fp = openfile(filename)
...@@ -703,7 +707,8 @@ class TestIdempotent(unittest.TestCase): ...@@ -703,7 +707,8 @@ class TestIdempotent(unittest.TestCase):
eq(msg1.get_payload(), '\n') eq(msg1.get_payload(), '\n')
# Test various other bits of the package's functionality
class TestMiscellaneous(unittest.TestCase): class TestMiscellaneous(unittest.TestCase):
def test_message_from_string(self): def test_message_from_string(self):
fp = openfile('msg_01.txt') fp = openfile('msg_01.txt')
...@@ -780,7 +785,8 @@ class TestMiscellaneous(unittest.TestCase): ...@@ -780,7 +785,8 @@ class TestMiscellaneous(unittest.TestCase):
unless(isinstance(subpart, MyMessage)) unless(isinstance(subpart, MyMessage))
# Test the iterator/generators
class TestIterators(TestEmailBase): class TestIterators(TestEmailBase):
def test_body_line_iterator(self): def test_body_line_iterator(self):
eq = self.assertEqual eq = self.assertEqual
...@@ -799,51 +805,7 @@ class TestIterators(TestEmailBase): ...@@ -799,51 +805,7 @@ class TestIterators(TestEmailBase):
for line in it: for line in it:
lines.append(line) lines.append(line)
eq(len(lines), 43) eq(len(lines), 43)
eq(EMPTYSTRING.join(lines), """\ eq(EMPTYSTRING.join(lines), openfile('msg_19.txt').read())
Send Ppp mailing list submissions to
\tppp@zzz.org
To subscribe or unsubscribe via the World Wide Web, visit
\thttp://www.zzz.org/mailman/listinfo/ppp
or, via email, send a message with subject or body 'help' to
\tppp-request@zzz.org
You can reach the person managing the list at
\tppp-admin@zzz.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Ppp digest..."
Today's Topics:
1. testing #1 (Barry A. Warsaw)
2. testing #2 (Barry A. Warsaw)
3. testing #3 (Barry A. Warsaw)
4. testing #4 (Barry A. Warsaw)
5. testing #5 (Barry A. Warsaw)
hello
hello
hello
hello
hello
_______________________________________________
Ppp mailing list
Ppp@zzz.org
http://www.zzz.org/mailman/listinfo/ppp
""")
def test_typed_subpart_iterator(self): def test_typed_subpart_iterator(self):
eq = self.assertEqual eq = self.assertEqual
...@@ -863,7 +825,7 @@ to reflect upon our own ...@@ -863,7 +825,7 @@ to reflect upon our own
""") """)
def suite(): def suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestMessageAPI)) suite.addTest(unittest.makeSuite(TestMessageAPI))
...@@ -882,7 +844,7 @@ def suite(): ...@@ -882,7 +844,7 @@ def suite():
return suite return suite
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(defaultTest='suite') unittest.main(defaultTest='suite')
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment