Back to index

python3.2  3.2.2
Public Member Functions
email.test.test_email.TestMiscellaneous Class Reference
Inheritance diagram for email.test.test_email.TestMiscellaneous:
Inheritance graph
[legend]
Collaboration diagram for email.test.test_email.TestMiscellaneous:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_message_from_string
def test_message_from_file
def test_message_from_string_with_class
def test_message_from_file_with_class
def test__all__
def test_formatdate
def test_formatdate_localtime
def test_formatdate_usegmt
def test_parsedate_none
def test_parsedate_compact
def test_parsedate_no_dayofweek
def test_parsedate_compact_no_dayofweek
def test_parsedate_no_space_before_positive_offset
def test_parsedate_no_space_before_negative_offset
def test_parsedate_acceptable_to_time_functions
def test_parsedate_y2k
def test_parseaddr_empty
def test_noquote_dump
def test_escape_dump
def test_escape_backslashes
def test_name_with_dot
def test_parseaddr_preserves_quoted_pairs_in_addresses
def test_parseaddr_preserves_spaces_in_local_part
def test_multiline_from_comment
def test_quote_dump
def test_charset_richcomparisons
def test_getaddresses
def test_getaddresses_nasty
def test_getaddresses_embedded_comment
def test_utils_quote_unquote
def test_get_body_encoding_with_bogus_charset
def test_get_body_encoding_with_uppercase_charset
def test_charsets_case_insensitive
def test_partial_falls_inside_message_delivery_status
def test_make_msgid_domain
def ndiffAssertEqual

Detailed Description

Definition at line 2446 of file test_email.py.


Member Function Documentation

def email.test.test_email.TestEmailBase.ndiffAssertEqual (   self,
  first,
  second 
) [inherited]
Like assertEqual except use ndiff for readable output.

Definition at line 57 of file test_email.py.

00057 
00058     def ndiffAssertEqual(self, first, second):
00059         """Like assertEqual except use ndiff for readable output."""
00060         if first != second:
00061             sfirst = str(first)
00062             ssecond = str(second)
00063             rfirst = [repr(line) for line in sfirst.splitlines()]
00064             rsecond = [repr(line) for line in ssecond.splitlines()]
00065             diff = difflib.ndiff(rfirst, rsecond)
00066             raise self.failureException(NL + NL.join(diff))

Here is the call graph for this function:

Definition at line 2503 of file test_email.py.

02503 
02504     def test__all__(self):
02505         module = __import__('email')
02506         # Can't use sorted() here due to Python 2.3 compatibility
02507         all = module.__all__[:]
02508         all.sort()
02509         self.assertEqual(all, [
02510             'base64mime', 'charset', 'encoders', 'errors', 'generator',
02511             'header', 'iterators', 'message', 'message_from_binary_file',
02512             'message_from_bytes', 'message_from_file',
02513             'message_from_string', 'mime', 'parser',
02514             'quoprimime', 'utils',
02515             ])

Here is the call graph for this function:

Definition at line 2669 of file test_email.py.

02669 
02670     def test_charset_richcomparisons(self):
02671         eq = self.assertEqual
02672         ne = self.assertNotEqual
02673         cset1 = Charset()
02674         cset2 = Charset()
02675         eq(cset1, 'us-ascii')
02676         eq(cset1, 'US-ASCII')
02677         eq(cset1, 'Us-AsCiI')
02678         eq('us-ascii', cset1)
02679         eq('US-ASCII', cset1)
02680         eq('Us-AsCiI', cset1)
02681         ne(cset1, 'usascii')
02682         ne(cset1, 'USASCII')
02683         ne(cset1, 'UsAsCiI')
02684         ne('usascii', cset1)
02685         ne('USASCII', cset1)
02686         ne('UsAsCiI', cset1)
02687         eq(cset1, cset2)
02688         eq(cset2, cset1)

Here is the call graph for this function:

Definition at line 2749 of file test_email.py.

02749 
02750     def test_charsets_case_insensitive(self):
02751         lc = Charset('us-ascii')
02752         uc = Charset('US-ASCII')
02753         self.assertEqual(lc.get_body_encoding(), uc.get_body_encoding())

Here is the call graph for this function:

Definition at line 2605 of file test_email.py.

02605 
02606     def test_escape_backslashes(self):
02607         self.assertEqual(
02608             utils.formataddr(('Arthur \Backslash\ Foobar', 'person@dom.ain')),
02609             r'"Arthur \\Backslash\\ Foobar" <person@dom.ain>')
02610         a = r'Arthur \Backslash\ Foobar'
02611         b = 'person@dom.ain'
02612         self.assertEqual(utils.parseaddr(utils.formataddr((a, b))), (a, b))

Here is the call graph for this function:

Definition at line 2597 of file test_email.py.

02597 
02598     def test_escape_dump(self):
02599         self.assertEqual(
02600             utils.formataddr(('A (Very) Silly Person', 'person@dom.ain')),
02601             r'"A \(Very\) Silly Person" <person@dom.ain>')
02602         a = r'A \(Special\) Person'
02603         b = 'person@dom.ain'
02604         self.assertEqual(utils.parseaddr(utils.formataddr((a, b))), (a, b))

Here is the call graph for this function:

Definition at line 2516 of file test_email.py.

02516 
02517     def test_formatdate(self):
02518         now = time.time()
02519         self.assertEqual(utils.parsedate(utils.formatdate(now))[:6],
02520                          time.gmtime(now)[:6])

Here is the call graph for this function:

Definition at line 2521 of file test_email.py.

02521 
02522     def test_formatdate_localtime(self):
02523         now = time.time()
02524         self.assertEqual(
02525             utils.parsedate(utils.formatdate(now, localtime=True))[:6],
02526             time.localtime(now)[:6])

Here is the call graph for this function:

Definition at line 2527 of file test_email.py.

02527 
02528     def test_formatdate_usegmt(self):
02529         now = time.time()
02530         self.assertEqual(
02531             utils.formatdate(now, localtime=False),
02532             time.strftime('%a, %d %b %Y %H:%M:%S -0000', time.gmtime(now)))
02533         self.assertEqual(
02534             utils.formatdate(now, localtime=False, usegmt=True),
02535             time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime(now)))

Here is the call graph for this function:

Definition at line 2719 of file test_email.py.

02719 
02720     def test_get_body_encoding_with_bogus_charset(self):
02721         charset = Charset('not a charset')
02722         self.assertEqual(charset.get_body_encoding(), 'base64')

Here is the call graph for this function:

Definition at line 2723 of file test_email.py.

02723 
02724     def test_get_body_encoding_with_uppercase_charset(self):
02725         eq = self.assertEqual
02726         msg = Message()
02727         msg['Content-Type'] = 'text/plain; charset=UTF-8'
02728         eq(msg['content-type'], 'text/plain; charset=UTF-8')
02729         charsets = msg.get_charsets()
02730         eq(len(charsets), 1)
02731         eq(charsets[0], 'utf-8')
02732         charset = Charset(charsets[0])
02733         eq(charset.get_body_encoding(), 'base64')
02734         msg.set_payload(b'hello world', charset=charset)
02735         eq(msg.get_payload(), 'aGVsbG8gd29ybGQ=\n')
02736         eq(msg.get_payload(decode=True), b'hello world')
02737         eq(msg['content-transfer-encoding'], 'base64')
02738         # Try another one
02739         msg = Message()
02740         msg['Content-Type'] = 'text/plain; charset="US-ASCII"'
02741         charsets = msg.get_charsets()
02742         eq(len(charsets), 1)
02743         eq(charsets[0], 'us-ascii')
02744         charset = Charset(charsets[0])
02745         eq(charset.get_body_encoding(), encoders.encode_7or8bit)
02746         msg.set_payload('hello world', charset=charset)
02747         eq(msg.get_payload(), 'hello world')
02748         eq(msg['content-transfer-encoding'], '7bit')

Here is the call graph for this function:

Definition at line 2689 of file test_email.py.

02689 
02690     def test_getaddresses(self):
02691         eq = self.assertEqual
02692         eq(utils.getaddresses(['aperson@dom.ain (Al Person)',
02693                                'Bud Person <bperson@dom.ain>']),
02694            [('Al Person', 'aperson@dom.ain'),
02695             ('Bud Person', 'bperson@dom.ain')])

Here is the call graph for this function:

Test proper handling of a nested comment

Definition at line 2706 of file test_email.py.

02706 
02707     def test_getaddresses_embedded_comment(self):
02708         """Test proper handling of a nested comment"""
02709         eq = self.assertEqual
02710         addrs = utils.getaddresses(['User ((nested comment)) <foo@bar.com>'])
02711         eq(addrs[0][1], 'foo@bar.com')

Here is the call graph for this function:

Definition at line 2696 of file test_email.py.

02696 
02697     def test_getaddresses_nasty(self):
02698         eq = self.assertEqual
02699         eq(utils.getaddresses(['foo: ;']), [('', '')])
02700         eq(utils.getaddresses(
02701            ['[]*-- =~$']),
02702            [('', ''), ('', ''), ('', '*--')])
02703         eq(utils.getaddresses(
02704            ['foo: ;', '"Jason R. Mastaler" <jason@dom.ain>']),
02705            [('', ''), ('Jason R. Mastaler', 'jason@dom.ain')])

Here is the call graph for this function:

Definition at line 2796 of file test_email.py.

02796 
02797     def test_make_msgid_domain(self):
02798         self.assertEqual(
02799             email.utils.make_msgid(domain='testdomain-string')[-19:],
02800             '@testdomain-string>')
02801 
02802 
# Test the iterator/generators

Here is the call graph for this function:

Definition at line 2458 of file test_email.py.

02458 
02459     def test_message_from_file(self):
02460         with openfile('msg_01.txt') as fp:
02461             text = fp.read()
02462             fp.seek(0)
02463             msg = email.message_from_file(fp)
02464             s = StringIO()
02465             # Don't wrap/continue long headers since we're trying to test
02466             # idempotency.
02467             g = Generator(s, maxheaderlen=0)
02468             g.flatten(msg)
02469             self.assertEqual(text, s.getvalue())

Here is the call graph for this function:

Definition at line 2488 of file test_email.py.

02488 
02489     def test_message_from_file_with_class(self):
02490         unless = self.assertTrue
02491         # Create a subclass
02492         class MyMessage(Message):
02493             pass
02494 
02495         with openfile('msg_01.txt') as fp:
02496             msg = email.message_from_file(fp, MyMessage)
02497         unless(isinstance(msg, MyMessage))
02498         # Try something more complicated
02499         with openfile('msg_02.txt') as fp:
02500             msg = email.message_from_file(fp, MyMessage)
02501         for subpart in msg.walk():
02502             unless(isinstance(subpart, MyMessage))

Here is the call graph for this function:

Definition at line 2447 of file test_email.py.

02447 
02448     def test_message_from_string(self):
02449         with openfile('msg_01.txt') as fp:
02450             text = fp.read()
02451         msg = email.message_from_string(text)
02452         s = StringIO()
02453         # Don't wrap/continue long headers since we're trying to test
02454         # idempotency.
02455         g = Generator(s, maxheaderlen=0)
02456         g.flatten(msg)
02457         self.assertEqual(text, s.getvalue())

Here is the call graph for this function:

Definition at line 2470 of file test_email.py.

02470 
02471     def test_message_from_string_with_class(self):
02472         unless = self.assertTrue
02473         with openfile('msg_01.txt') as fp:
02474             text = fp.read()
02475 
02476         # Create a subclass
02477         class MyMessage(Message):
02478             pass
02479 
02480         msg = email.message_from_string(text, MyMessage)
02481         unless(isinstance(msg, MyMessage))
02482         # Try something more complicated
02483         with openfile('msg_02.txt') as fp:
02484             text = fp.read()
02485         msg = email.message_from_string(text, MyMessage)
02486         for subpart in msg.walk():
02487             unless(isinstance(subpart, MyMessage))

Here is the call graph for this function:

Definition at line 2658 of file test_email.py.

02658 
02659     def test_multiline_from_comment(self):
02660         x = """\
02661 Foo
02662 \tBar <foo@example.com>"""
02663         self.assertEqual(utils.parseaddr(x), ('Foo Bar', 'foo@example.com'))

Here is the call graph for this function:

Definition at line 2613 of file test_email.py.

02613 
02614     def test_name_with_dot(self):
02615         x = 'John X. Doe <jxd@example.com>'
02616         y = '"John X. Doe" <jxd@example.com>'
02617         a, b = ('John X. Doe', 'jxd@example.com')
02618         self.assertEqual(utils.parseaddr(x), (a, b))
02619         self.assertEqual(utils.parseaddr(y), (a, b))
02620         # formataddr() quotes the name if there's a dot in it
02621         self.assertEqual(utils.formataddr((a, b)), y)

Here is the call graph for this function:

Definition at line 2592 of file test_email.py.

02592 
02593     def test_noquote_dump(self):
02594         self.assertEqual(
02595             utils.formataddr(('A Silly Person', 'person@dom.ain')),
02596             'A Silly Person <person@dom.ain>')

Here is the call graph for this function:

Definition at line 2588 of file test_email.py.

02588 
02589     def test_parseaddr_empty(self):
02590         self.assertEqual(utils.parseaddr('<>'), ('', ''))
02591         self.assertEqual(utils.formataddr(utils.parseaddr('<>')), '')

Here is the call graph for this function:

Definition at line 2622 of file test_email.py.

02622 
02623     def test_parseaddr_preserves_quoted_pairs_in_addresses(self):
02624         # issue 10005.  Note that in the third test the second pair of
02625         # backslashes is not actually a quoted pair because it is not inside a
02626         # comment or quoted string: the address being parsed has a quoted
02627         # string containing a quoted backslash, followed by 'example' and two
02628         # backslashes, followed by another quoted string containing a space and
02629         # the word 'example'.  parseaddr copies those two backslashes
02630         # literally.  Per rfc5322 this is not technically correct since a \ may
02631         # not appear in an address outside of a quoted string.  It is probably
02632         # a sensible Postel interpretation, though.
02633         eq = self.assertEqual
02634         eq(utils.parseaddr('""example" example"@example.com'),
02635           ('', '""example" example"@example.com'))
02636         eq(utils.parseaddr('"\\"example\\" example"@example.com'),
02637           ('', '"\\"example\\" example"@example.com'))
02638         eq(utils.parseaddr('"\\\\"example\\\\" example"@example.com'),
02639           ('', '"\\\\"example\\\\" example"@example.com'))

Here is the call graph for this function:

Definition at line 2640 of file test_email.py.

02640 
02641     def test_parseaddr_preserves_spaces_in_local_part(self):
02642         # issue 9286.  A normal RFC5322 local part should not contain any
02643         # folding white space, but legacy local parts can (they are a sequence
02644         # of atoms, not dotatoms).  On the other hand we strip whitespace from
02645         # before the @ and around dots, on the assumption that the whitespace
02646         # around the punctuation is a mistake in what would otherwise be
02647         # an RFC5322 local part.  Leading whitespace is, usual, stripped as well.
02648         self.assertEqual(('', "merwok wok@xample.com"),
02649             utils.parseaddr("merwok wok@xample.com"))
02650         self.assertEqual(('', "merwok  wok@xample.com"),
02651             utils.parseaddr("merwok  wok@xample.com"))
02652         self.assertEqual(('', "merwok  wok@xample.com"),
02653             utils.parseaddr(" merwok  wok  @xample.com"))
02654         self.assertEqual(('', 'merwok"wok"  wok@xample.com'),
02655             utils.parseaddr('merwok"wok"  wok@xample.com'))
02656         self.assertEqual(('', 'merwok.wok.wok@xample.com'),
02657             utils.parseaddr('merwok. wok .  wok@xample.com'))

Here is the call graph for this function:

Definition at line 2564 of file test_email.py.

02564 
02565     def test_parsedate_acceptable_to_time_functions(self):
02566         eq = self.assertEqual
02567         timetup = utils.parsedate('5 Feb 2003 13:47:26 -0800')
02568         t = int(time.mktime(timetup))
02569         eq(time.localtime(t)[:6], timetup[:6])
02570         eq(int(time.strftime('%Y', timetup)), 2003)
02571         timetup = utils.parsedate_tz('5 Feb 2003 13:47:26 -0800')
02572         t = int(time.mktime(timetup[:9]))
02573         eq(time.localtime(t)[:6], timetup[:6])
02574         eq(int(time.strftime('%Y', timetup[:9])), 2003)

Here is the call graph for this function:

Definition at line 2539 of file test_email.py.

02539 
02540     def test_parsedate_compact(self):
02541         # The FWS after the comma is optional
02542         self.assertEqual(utils.parsedate('Wed,3 Apr 2002 14:58:26 +0800'),
02543                          utils.parsedate('Wed, 3 Apr 2002 14:58:26 +0800'))

Here is the call graph for this function:

Definition at line 2549 of file test_email.py.

02549 
02550     def test_parsedate_compact_no_dayofweek(self):
02551         eq = self.assertEqual
02552         eq(utils.parsedate_tz('5 Feb 2003 13:47:26 -0800'),
02553            (2003, 2, 5, 13, 47, 26, 0, 1, -1, -28800))

Here is the call graph for this function:

Definition at line 2544 of file test_email.py.

02544 
02545     def test_parsedate_no_dayofweek(self):
02546         eq = self.assertEqual
02547         eq(utils.parsedate_tz('25 Feb 2003 13:47:26 -0800'),
02548            (2003, 2, 25, 13, 47, 26, 0, 1, -1, -28800))

Here is the call graph for this function:

Definition at line 2558 of file test_email.py.

02558 
02559     def test_parsedate_no_space_before_negative_offset(self):
02560         # Issue 1155362: we already handled '+' for this case.
02561         self.assertEqual(utils.parsedate_tz('Wed, 3 Apr 2002 14:58:26-0800'),
02562            (2002, 4, 3, 14, 58, 26, 0, 1, -1, -28800))
02563 

Here is the call graph for this function:

Definition at line 2554 of file test_email.py.

02554 
02555     def test_parsedate_no_space_before_positive_offset(self):
02556         self.assertEqual(utils.parsedate_tz('Wed, 3 Apr 2002 14:58:26+0800'),
02557            (2002, 4, 3, 14, 58, 26, 0, 1, -1, 28800))

Here is the call graph for this function:

Definition at line 2536 of file test_email.py.

02536 
02537     def test_parsedate_none(self):
02538         self.assertEqual(utils.parsedate(''), None)

Here is the call graph for this function:

Test for parsing a date with a two-digit year.

Parsing a date with a two-digit year should return the correct
four-digit year. RFC822 allows two-digit years, but RFC2822 (which
obsoletes RFC822) requires four-digit years.

Definition at line 2575 of file test_email.py.

02575 
02576     def test_parsedate_y2k(self):
02577         """Test for parsing a date with a two-digit year.
02578 
02579         Parsing a date with a two-digit year should return the correct
02580         four-digit year. RFC822 allows two-digit years, but RFC2822 (which
02581         obsoletes RFC822) requires four-digit years.
02582 
02583         """
02584         self.assertEqual(utils.parsedate_tz('25 Feb 03 13:47:26 -0800'),
02585                          utils.parsedate_tz('25 Feb 2003 13:47:26 -0800'))
02586         self.assertEqual(utils.parsedate_tz('25 Feb 71 13:47:26 -0800'),
02587                          utils.parsedate_tz('25 Feb 1971 13:47:26 -0800'))

Here is the call graph for this function:

Definition at line 2754 of file test_email.py.

02754 
02755     def test_partial_falls_inside_message_delivery_status(self):
02756         eq = self.ndiffAssertEqual
02757         # The Parser interface provides chunks of data to FeedParser in 8192
02758         # byte gulps.  SF bug #1076485 found one of those chunks inside
02759         # message/delivery-status header block, which triggered an
02760         # unreadline() of NeedMoreData.
02761         msg = self._msgobj('msg_43.txt')
02762         sfp = StringIO()
02763         iterators._structure(msg, sfp)
02764         eq(sfp.getvalue(), """\
02765 multipart/report
02766     text/plain
02767     message/delivery-status
02768         text/plain
02769         text/plain
02770         text/plain
02771         text/plain
02772         text/plain
02773         text/plain
02774         text/plain
02775         text/plain
02776         text/plain
02777         text/plain
02778         text/plain
02779         text/plain
02780         text/plain
02781         text/plain
02782         text/plain
02783         text/plain
02784         text/plain
02785         text/plain
02786         text/plain
02787         text/plain
02788         text/plain
02789         text/plain
02790         text/plain
02791         text/plain
02792         text/plain
02793         text/plain
02794     text/rfc822-headers
02795 """)

Here is the call graph for this function:

Definition at line 2664 of file test_email.py.

02664 
02665     def test_quote_dump(self):
02666         self.assertEqual(
02667             utils.formataddr(('A Silly; Person', 'person@dom.ain')),
02668             r'"A Silly; Person" <person@dom.ain>')

Here is the call graph for this function:

Definition at line 2712 of file test_email.py.

02712 
02713     def test_utils_quote_unquote(self):
02714         eq = self.assertEqual
02715         msg = Message()
02716         msg.add_header('content-disposition', 'attachment',
02717                        filename='foo\\wacky"name')
02718         eq(msg.get_filename(), 'foo\\wacky"name')

Here is the call graph for this function:


The documentation for this class was generated from the following file: