Python email.test() Examples
The following are 30
code examples of email.test().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
email
, or try the search function
.
Example #1
Source File: test_email_renamed.py From BinderFilter with MIT License | 6 votes |
def test_mime_attachments_in_constructor(self): eq = self.assertEqual text1 = MIMEText('') text2 = MIMEText('') msg = MIMEMultipart(_subparts=(text1, text2)) eq(len(msg.get_payload()), 2) eq(msg.get_payload(0), text1) eq(msg.get_payload(1), text2) # 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.
Example #2
Source File: test_email.py From BinderFilter with MIT License | 6 votes |
def test_split_long_continuation(self): eq = self.ndiffAssertEqual msg = email.message_from_string("""\ Subject: bug demonstration \t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 \tmore text test """) sfp = StringIO() g = Generator(sfp) g.flatten(msg) eq(sfp.getvalue(), """\ Subject: bug demonstration 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 more text test """)
Example #3
Source File: test_email.py From oss-ftp with MIT License | 6 votes |
def test_whitespace_continuation_last_header(self): eq = self.assertEqual # Like the previous test, but the subject line is the last # header. msg = email.message_from_string("""\ From: aperson@dom.ain To: bperson@dom.ain Date: Mon, 8 Apr 2002 15:09:19 -0400 Message-ID: spam Subject: the next line has a space on it \x20 Here's the message body """) eq(msg['subject'], 'the next line has a space on it\n ') eq(msg['message-id'], 'spam') eq(msg.get_payload(), "Here's the message body\n")
Example #4
Source File: test_email_renamed.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_whitespace_continuation_last_header(self): eq = self.assertEqual # Like the previous test, but the subject line is the last # header. msg = email.message_from_string("""\ From: aperson@dom.ain To: bperson@dom.ain Date: Mon, 8 Apr 2002 15:09:19 -0400 Message-ID: spam Subject: the next line has a space on it \x20 Here's the message body """) eq(msg['subject'], 'the next line has a space on it\n ') eq(msg['message-id'], 'spam') eq(msg.get_payload(), "Here's the message body\n")
Example #5
Source File: test_email.py From oss-ftp with MIT License | 6 votes |
def test_split_long_continuation(self): eq = self.ndiffAssertEqual msg = email.message_from_string("""\ Subject: bug demonstration \t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 \tmore text test """) sfp = StringIO() g = Generator(sfp) g.flatten(msg) eq(sfp.getvalue(), """\ Subject: bug demonstration 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 more text test """)
Example #6
Source File: test_email_renamed.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_mime_attachments_in_constructor(self): eq = self.assertEqual text1 = MIMEText('') text2 = MIMEText('') msg = MIMEMultipart(_subparts=(text1, text2)) eq(len(msg.get_payload()), 2) eq(msg.get_payload(0), text1) eq(msg.get_payload(1), text2) # 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.
Example #7
Source File: test_email_renamed.py From oss-ftp with MIT License | 6 votes |
def test_split_long_continuation(self): eq = self.ndiffAssertEqual msg = email.message_from_string("""\ Subject: bug demonstration \t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 \tmore text test """) sfp = StringIO() g = Generator(sfp) g.flatten(msg) eq(sfp.getvalue(), """\ Subject: bug demonstration 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 more text test """)
Example #8
Source File: test_email.py From BinderFilter with MIT License | 6 votes |
def test_whitespace_continuation_last_header(self): eq = self.assertEqual # Like the previous test, but the subject line is the last # header. msg = email.message_from_string("""\ From: aperson@dom.ain To: bperson@dom.ain Date: Mon, 8 Apr 2002 15:09:19 -0400 Message-ID: spam Subject: the next line has a space on it \x20 Here's the message body """) eq(msg['subject'], 'the next line has a space on it\n ') eq(msg['message-id'], 'spam') eq(msg.get_payload(), "Here's the message body\n")
Example #9
Source File: test_email_renamed.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_split_long_continuation(self): eq = self.ndiffAssertEqual msg = email.message_from_string("""\ Subject: bug demonstration \t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 \tmore text test """) sfp = StringIO() g = Generator(sfp) g.flatten(msg) eq(sfp.getvalue(), """\ Subject: bug demonstration 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 more text test """)
Example #10
Source File: test_email_renamed.py From oss-ftp with MIT License | 6 votes |
def test_mime_attachments_in_constructor(self): eq = self.assertEqual text1 = MIMEText('') text2 = MIMEText('') msg = MIMEMultipart(_subparts=(text1, text2)) eq(len(msg.get_payload()), 2) eq(msg.get_payload(0), text1) eq(msg.get_payload(1), text2) # 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.
Example #11
Source File: test_email_renamed.py From oss-ftp with MIT License | 6 votes |
def test_whitespace_continuation_last_header(self): eq = self.assertEqual # Like the previous test, but the subject line is the last # header. msg = email.message_from_string("""\ From: aperson@dom.ain To: bperson@dom.ain Date: Mon, 8 Apr 2002 15:09:19 -0400 Message-ID: spam Subject: the next line has a space on it \x20 Here's the message body """) eq(msg['subject'], 'the next line has a space on it\n ') eq(msg['message-id'], 'spam') eq(msg.get_payload(), "Here's the message body\n")
Example #12
Source File: test_email_renamed.py From BinderFilter with MIT License | 6 votes |
def test_split_long_continuation(self): eq = self.ndiffAssertEqual msg = email.message_from_string("""\ Subject: bug demonstration \t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 \tmore text test """) sfp = StringIO() g = Generator(sfp) g.flatten(msg) eq(sfp.getvalue(), """\ Subject: bug demonstration 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 more text test """)
Example #13
Source File: test_email.py From datafari with Apache License 2.0 | 6 votes |
def test_split_long_continuation(self): eq = self.ndiffAssertEqual msg = email.message_from_string("""\ Subject: bug demonstration \t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 \tmore text test """) sfp = StringIO() g = Generator(sfp) g.flatten(msg) eq(sfp.getvalue(), """\ Subject: bug demonstration 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 more text test """)
Example #14
Source File: test_email_renamed.py From BinderFilter with MIT License | 6 votes |
def test_whitespace_continuation_last_header(self): eq = self.assertEqual # Like the previous test, but the subject line is the last # header. msg = email.message_from_string("""\ From: aperson@dom.ain To: bperson@dom.ain Date: Mon, 8 Apr 2002 15:09:19 -0400 Message-ID: spam Subject: the next line has a space on it \x20 Here's the message body """) eq(msg['subject'], 'the next line has a space on it\n ') eq(msg['message-id'], 'spam') eq(msg.get_payload(), "Here's the message body\n")
Example #15
Source File: test_email.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_whitespace_continuation_last_header(self): eq = self.assertEqual # Like the previous test, but the subject line is the last # header. msg = email.message_from_string("""\ From: aperson@dom.ain To: bperson@dom.ain Date: Mon, 8 Apr 2002 15:09:19 -0400 Message-ID: spam Subject: the next line has a space on it \x20 Here's the message body """) eq(msg['subject'], 'the next line has a space on it\n ') eq(msg['message-id'], 'spam') eq(msg.get_payload(), "Here's the message body\n")
Example #16
Source File: test_email.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_split_long_continuation(self): eq = self.ndiffAssertEqual msg = email.message_from_string("""\ Subject: bug demonstration \t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 \tmore text test """) sfp = StringIO() g = Generator(sfp) g.flatten(msg) eq(sfp.getvalue(), """\ Subject: bug demonstration 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789 more text test """)
Example #17
Source File: test_email_renamed.py From BinderFilter with MIT License | 5 votes |
def test_message_from_file(self): fp = openfile('msg_01.txt') try: text = fp.read() fp.seek(0) msg = email.message_from_file(fp) s = StringIO() # Don't wrap/continue long headers since we're trying to test # idempotency. g = Generator(s, maxheaderlen=0) g.flatten(msg) self.assertEqual(text, s.getvalue()) finally: fp.close()
Example #18
Source File: test_email_renamed.py From oss-ftp with MIT License | 5 votes |
def test_set_param(self): eq = self.assertEqual msg = Message() msg.set_param('title', 'This is even more ***fun*** isn\'t it!', charset='us-ascii') eq(msg.get_param('title'), ('us-ascii', '', 'This is even more ***fun*** isn\'t it!')) msg.set_param('title', 'This is even more ***fun*** isn\'t it!', charset='us-ascii', language='en') eq(msg.get_param('title'), ('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!')) msg = self._msgobj('msg_01.txt') msg.set_param('title', 'This is even more ***fun*** isn\'t it!', charset='us-ascii', language='en') self.ndiffAssertEqual(msg.as_string(), """\ Return-Path: <bbb@zzz.org> Delivered-To: bbb@zzz.org Received: by mail.zzz.org (Postfix, from userid 889) id 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: <15090.61304.110929.45684@aaa.zzz.org> From: bbb@ddd.com (John X. Doe) To: bbb@zzz.org Subject: This is a test message Date: Fri, 4 May 2001 14:05:44 -0400 Content-Type: text/plain; charset=us-ascii; title*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21" Hi, Do you like this message? -Me """)
Example #19
Source File: test_email_renamed.py From oss-ftp with MIT License | 5 votes |
def test_idempotent(self): eq = self.assertEqual # Make sure us-ascii = no Unicode conversion c = Charset('us-ascii') s = 'Hello World!' sp = c.to_splittable(s) eq(s, c.from_splittable(sp)) # test 8-bit idempotency with us-ascii s = '\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa' sp = c.to_splittable(s) eq(s, c.from_splittable(sp))
Example #20
Source File: test_email.py From oss-ftp with MIT License | 5 votes |
def test_set_param(self): eq = self.assertEqual msg = Message() msg.set_param('title', 'This is even more ***fun*** isn\'t it!', charset='us-ascii') eq(msg.get_param('title'), ('us-ascii', '', 'This is even more ***fun*** isn\'t it!')) msg.set_param('title', 'This is even more ***fun*** isn\'t it!', charset='us-ascii', language='en') eq(msg.get_param('title'), ('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!')) msg = self._msgobj('msg_01.txt') msg.set_param('title', 'This is even more ***fun*** isn\'t it!', charset='us-ascii', language='en') self.ndiffAssertEqual(msg.as_string(), """\ Return-Path: <bbb@zzz.org> Delivered-To: bbb@zzz.org Received: by mail.zzz.org (Postfix, from userid 889) id 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: <15090.61304.110929.45684@aaa.zzz.org> From: bbb@ddd.com (John X. Doe) To: bbb@zzz.org Subject: This is a test message Date: Fri, 4 May 2001 14:05:44 -0400 Content-Type: text/plain; charset=us-ascii; title*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21" Hi, Do you like this message? -Me """)
Example #21
Source File: test_email.py From oss-ftp with MIT License | 5 votes |
def test_default_multipart_constructor(self): msg = MIMEMultipart() self.assertTrue(msg.is_multipart()) # 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.
Example #22
Source File: test_email.py From oss-ftp with MIT License | 5 votes |
def test_rfc2047_B_bad_padding(self): s = '=?iso-8859-1?B?%s?=' data = [ # only test complete bytes ('dm==', 'v'), ('dm=', 'v'), ('dm', 'v'), ('dmk=', 'vi'), ('dmk', 'vi') ] for q, a in data: dh = decode_header(s % q) self.assertEqual(dh, [(a, 'iso-8859-1')])
Example #23
Source File: test_email.py From oss-ftp with MIT License | 5 votes |
def setUp(self): # Make sure we pick up the audiotest.au that lives in email/test/data. # In Python, there's an audiotest.au living in Lib/test but that isn't # included in some binary distros that don't include the test # package. The trailing empty string on the .join() is significant # since findfile() will do a dirname(). datadir = os.path.join(os.path.dirname(landmark), 'data', '') fp = open(findfile('audiotest.au', datadir), 'rb') try: self._audiodata = fp.read() finally: fp.close() self._au = MIMEAudio(self._audiodata)
Example #24
Source File: test_email.py From oss-ftp with MIT License | 5 votes |
def test_no_semis_header_splitter(self): eq = self.ndiffAssertEqual msg = Message() msg['From'] = 'test@dom.ain' msg['References'] = SPACE.join(['<%d@dom.ain>' % i for i in range(10)]) msg.set_payload('Test') sfp = StringIO() g = Generator(sfp) g.flatten(msg) eq(sfp.getvalue(), """\ From: test@dom.ain References: <0@dom.ain> <1@dom.ain> <2@dom.ain> <3@dom.ain> <4@dom.ain> <5@dom.ain> <6@dom.ain> <7@dom.ain> <8@dom.ain> <9@dom.ain> Test""")
Example #25
Source File: test_email_renamed.py From BinderFilter with MIT License | 5 votes |
def test_idempotent(self): eq = self.assertEqual # Make sure us-ascii = no Unicode conversion c = Charset('us-ascii') s = 'Hello World!' sp = c.to_splittable(s) eq(s, c.from_splittable(sp)) # test 8-bit idempotency with us-ascii s = '\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa' sp = c.to_splittable(s) eq(s, c.from_splittable(sp))
Example #26
Source File: test_email.py From oss-ftp with MIT License | 5 votes |
def test_embeded_header_via_string_rejected(self): msg = Message() msg['Dummy'] = 'dummy\nX-Injected-Header: test' self.assertRaises(Errors.HeaderParseError, msg.as_string) # Test the email.Encoders module
Example #27
Source File: test_email_renamed.py From BinderFilter with MIT License | 5 votes |
def test_explicit_maxlinelen(self): eq = self.ndiffAssertEqual hstr = 'A very long line that must get split to something other than at the 76th character boundary to test the non-default behavior' h = Header(hstr) eq(h.encode(), '''\ A very long line that must get split to something other than at the 76th character boundary to test the non-default behavior''') h = Header(hstr, header_name='Subject') eq(h.encode(), '''\ A very long line that must get split to something other than at the 76th character boundary to test the non-default behavior''') h = Header(hstr, maxlinelen=1024, header_name='Subject') eq(h.encode(), hstr)
Example #28
Source File: test_email.py From oss-ftp with MIT License | 5 votes |
def test_embeded_header_via_Header_rejected(self): msg = Message() msg['Dummy'] = Header('dummy\nX-Injected-Header: test') self.assertRaises(Errors.HeaderParseError, msg.as_string)
Example #29
Source File: test_email_renamed.py From BinderFilter with MIT License | 5 votes |
def test_set_param(self): eq = self.assertEqual msg = Message() msg.set_param('title', 'This is even more ***fun*** isn\'t it!', charset='us-ascii') eq(msg.get_param('title'), ('us-ascii', '', 'This is even more ***fun*** isn\'t it!')) msg.set_param('title', 'This is even more ***fun*** isn\'t it!', charset='us-ascii', language='en') eq(msg.get_param('title'), ('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!')) msg = self._msgobj('msg_01.txt') msg.set_param('title', 'This is even more ***fun*** isn\'t it!', charset='us-ascii', language='en') self.ndiffAssertEqual(msg.as_string(), """\ Return-Path: <bbb@zzz.org> Delivered-To: bbb@zzz.org Received: by mail.zzz.org (Postfix, from userid 889) id 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: <15090.61304.110929.45684@aaa.zzz.org> From: bbb@ddd.com (John X. Doe) To: bbb@zzz.org Subject: This is a test message Date: Fri, 4 May 2001 14:05:44 -0400 Content-Type: text/plain; charset=us-ascii; title*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21" Hi, Do you like this message? -Me """)
Example #30
Source File: test_email.py From oss-ftp with MIT License | 5 votes |
def openfile(filename, mode='r'): path = os.path.join(os.path.dirname(landmark), 'data', filename) return open(path, mode) # Base test class