[Python-checkins] python/dist/src/Lib/email/test test_email.py,1.29,1.30
bwarsaw@users.sourceforge.net
bwarsaw@users.sourceforge.net
Wed, 05 Mar 2003 21:40:48 -0800
Update of /cvsroot/python/python/dist/src/Lib/email/test
In directory sc8-pr-cvs1:/tmp/cvs-serv5915
Modified Files:
test_email.py
Log Message:
Merge of the folding-reimpl-branch. Specific changes,
Update tests for email 2.5.
Index: test_email.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/test/test_email.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** test_email.py 2 Jan 2003 22:48:36 -0000 1.29
--- test_email.py 6 Mar 2003 05:40:45 -0000 1.30
***************
*** 2,14 ****
# email package unit tests
- import sys
import os
import time
- import unittest
import base64
import difflib
from cStringIO import StringIO
from types import StringType, ListType
- import warnings
import email
--- 2,14 ----
# email package unit tests
import os
+ import sys
import time
import base64
import difflib
+ import unittest
+ import warnings
from cStringIO import StringIO
from types import StringType, ListType
import email
***************
*** 567,571 ****
cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. "
utf8_head = u"\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8")
! h = Header(g_head, g)
h.append(cz_head, cz)
h.append(utf8_head, utf8)
--- 567,571 ----
cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. "
utf8_head = u"\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8")
! h = Header(g_head, g, header_name='Subject')
h.append(cz_head, cz)
h.append(utf8_head, utf8)
***************
*** 575,612 ****
g = Generator(sfp)
g.flatten(msg)
! eq(sfp.getvalue(), '''\
! Subject: =?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_eine?=
! =?iso-8859-1?q?m_Foerderband_komfortabel_den_Korridor_ent?=
! =?iso-8859-1?q?lang=2C_an_s=FCdl=FCndischen_Wandgem=E4lden_vorbei?=
! =?iso-8859-1?q?=2C_gegen_die_rotierenden_Klingen_bef=F6rdert=2E_?=
! =?iso-8859-2?q?Finan=E8ni_metropole_se_hroutil?=
! =?iso-8859-2?q?y_pod_tlakem_jejich_d=F9vtipu=2E=2E_?=
! =?utf-8?b?5q2j56K644Gr6KiA44GG44Go57+76Kiz44Gv?=
! =?utf-8?b?44GV44KM44Gm44GE44G+44Gb44KT44CC5LiA?=
! =?utf-8?b?6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM?=
! =?utf-8?b?44CB44GC44Go44Gv44Gn44Gf44KJ44KB44Gn?=
! =?utf-8?b?44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBpc3QgZGE=?=
! =?utf-8?q?s_Nunstuck_git_und?=
! =?utf-8?q?_Slotermeyer=3F_Ja!_Beiherhund_das_Ode?=
! =?utf-8?q?r_die_Flipperwaldt?=
! =?utf-8?b?IGdlcnNwdXQu44CN44Go6KiA44Gj44Gm44GE44G+44GZ44CC?=
! ''')
! eq(h.encode(), '''\
! =?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_eine?=
! =?iso-8859-1?q?m_Foerderband_komfortabel_den_Korridor_ent?=
! =?iso-8859-1?q?lang=2C_an_s=FCdl=FCndischen_Wandgem=E4lden_vorbei?=
! =?iso-8859-1?q?=2C_gegen_die_rotierenden_Klingen_bef=F6rdert=2E_?=
! =?iso-8859-2?q?Finan=E8ni_metropole_se_hroutil?=
! =?iso-8859-2?q?y_pod_tlakem_jejich_d=F9vtipu=2E=2E_?=
! =?utf-8?b?5q2j56K644Gr6KiA44GG44Go57+76Kiz44Gv?=
! =?utf-8?b?44GV44KM44Gm44GE44G+44Gb44KT44CC5LiA?=
! =?utf-8?b?6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM?=
! =?utf-8?b?44CB44GC44Go44Gv44Gn44Gf44KJ44KB44Gn?=
! =?utf-8?b?44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBpc3QgZGE=?=
! =?utf-8?q?s_Nunstuck_git_und?=
! =?utf-8?q?_Slotermeyer=3F_Ja!_Beiherhund_das_Ode?=
! =?utf-8?q?r_die_Flipperwaldt?=
! =?utf-8?b?IGdlcnNwdXQu44CN44Go6KiA44Gj44Gm44GE44G+44GZ44CC?=''')
def test_long_header_encode(self):
--- 575,604 ----
g = Generator(sfp)
g.flatten(msg)
! eq(sfp.getvalue(), """\
! Subject: =?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerd?=
! =?iso-8859-1?q?erband_komfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndi?=
! =?iso-8859-1?q?schen_Wandgem=E4lden_vorbei=2C_gegen_die_rotierenden_Kling?=
! =?iso-8859-1?q?en_bef=F6rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_met?=
! =?iso-8859-2?q?ropole_se_hroutily_pod_tlakem_jejich_d=F9vtipu=2E=2E_?=
! =?utf-8?b?5q2j56K644Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE?=
! =?utf-8?b?44G+44Gb44KT44CC5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB?=
! =?utf-8?b?44GC44Go44Gv44Gn44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CM?=
! =?utf-8?q?Wenn_ist_das_Nunstuck_git_und_Slotermeyer=3F_Ja!_Beiherhund_das?=
! =?utf-8?b?IE9kZXIgZGllIEZsaXBwZXJ3YWxkdCBnZXJzcHV0LuOAjeOBqOiogOOBow==?=
! =?utf-8?b?44Gm44GE44G+44GZ44CC?=
! """)
! eq(h.encode(), """\
! =?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerd?=
! =?iso-8859-1?q?erband_komfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndi?=
! =?iso-8859-1?q?schen_Wandgem=E4lden_vorbei=2C_gegen_die_rotierenden_Kling?=
! =?iso-8859-1?q?en_bef=F6rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_met?=
! =?iso-8859-2?q?ropole_se_hroutily_pod_tlakem_jejich_d=F9vtipu=2E=2E_?=
! =?utf-8?b?5q2j56K644Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE?=
! =?utf-8?b?44G+44Gb44KT44CC5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB?=
! =?utf-8?b?44GC44Go44Gv44Gn44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CM?=
! =?utf-8?q?Wenn_ist_das_Nunstuck_git_und_Slotermeyer=3F_Ja!_Beiherhund_das?=
! =?utf-8?b?IE9kZXIgZGllIEZsaXBwZXJ3YWxkdCBnZXJzcHV0LuOAjeOBqOiogOOBow==?=
! =?utf-8?b?44Gm44GE44G+44GZ44CC?=""")
def test_long_header_encode(self):
***************
*** 713,722 ****
eq = self.ndiffAssertEqual
msg = Message()
! h = Header('Britische Regierung gibt', 'iso-8859-1')
h.append('gr\xfcnes Licht f\xfcr Offshore-Windkraftprojekte')
msg['Subject'] = h
eq(msg.as_string(), """\
! Subject: =?iso-8859-1?q?Britische_Regierung_gibt?=
! =?iso-8859-1?q?gr=FCnes_Licht_f=FCr_Offshore-Windkraftprojekte?=
""")
--- 705,715 ----
eq = self.ndiffAssertEqual
msg = Message()
! h = Header('Britische Regierung gibt', 'iso-8859-1',
! header_name='Subject')
h.append('gr\xfcnes Licht f\xfcr Offshore-Windkraftprojekte')
msg['Subject'] = h
eq(msg.as_string(), """\
! Subject: =?iso-8859-1?q?Britische_Regierung_gibt?= =?iso-8859-1?q?gr=FCnes?=
! =?iso-8859-1?q?_Licht_f=FCr_Offshore-Windkraftprojekte?=
""")
***************
*** 731,734 ****
--- 724,769 ----
""")
+ def test_long_to_header(self):
+ eq = self.ndiffAssertEqual
+ to = '"Someone Test #A" <someone@eecs.umich.edu>,<someone@eecs.umich.edu>,"Someone Test #B" <someone@umich.edu>, "Someone Test #C" <someone@eecs.umich.edu>, "Someone Test #D" <someone@eecs.umich.edu>'
+ msg = Message()
+ msg['To'] = to
+ eq(msg.as_string(0), '''\
+ To: "Someone Test #A" <someone@eecs.umich.edu>, <someone@eecs.umich.edu>,
+ \t"Someone Test #B" <someone@umich.edu>,
+ \t"Someone Test #C" <someone@eecs.umich.edu>,
+ \t"Someone Test #D" <someone@eecs.umich.edu>
+
+ ''')
+
+ def test_long_line_after_append(self):
+ eq = self.ndiffAssertEqual
+ s = 'This is an example of string which has almost the limit of header length.'
+ h = Header(s)
+ h.append('Add another line.')
+ eq(h.encode(), """\
+ This is an example of string which has almost the limit of header length.
+ Add another line.""")
+
+ def test_shorter_line_with_append(self):
+ eq = self.ndiffAssertEqual
+ s = 'This is a shorter line.'
+ h = Header(s)
+ h.append('Add another sentence. (Surprise?)')
+ eq(h.encode(),
+ 'This is a shorter line. Add another sentence. (Surprise?)')
+
+ def test_long_field_name(self):
+ eq = self.ndiffAssertEqual
+ fn = 'X-Very-Very-Very-Long-Header-Name'
+ gs = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. "
+ h = Header(gs, 'iso-8859-1', header_name=fn)
+ # BAW: this seems broken because the first line is too long
+ eq(h.encode(), """\
+ =?iso-8859-1?q?Die_Mieter_treten_hier_?=
+ =?iso-8859-1?q?ein_werden_mit_einem_Foerderband_komfortabel_den_Korridor_?=
+ =?iso-8859-1?q?entlang=2C_an_s=FCdl=FCndischen_Wandgem=E4lden_vorbei=2C_g?=
+ =?iso-8859-1?q?egen_die_rotierenden_Klingen_bef=F6rdert=2E_?=""")
+
***************
*** 1310,1313 ****
--- 1345,1385 ----
self.assertEqual(sfp.getvalue(), text)
+ def test_no_nl_preamble(self):
+ eq = self.ndiffAssertEqual
+ msg = Message()
+ msg['From'] = 'aperson@dom.ain'
+ msg['To'] = 'bperson@dom.ain'
+ msg['Subject'] = 'Test'
+ msg.preamble = 'MIME message'
+ msg.epilogue = ''
+ msg1 = MIMEText('One')
+ msg2 = MIMEText('Two')
+ msg.add_header('Content-Type', 'multipart/mixed', boundary='BOUNDARY')
+ msg.attach(msg1)
+ msg.attach(msg2)
+ eq(msg.as_string(), """\
+ From: aperson@dom.ain
+ To: bperson@dom.ain
+ Subject: Test
+ Content-Type: multipart/mixed; boundary="BOUNDARY"
+
+ MIME message
+ --BOUNDARY
+ Content-Type: text/plain; charset="us-ascii"
+ MIME-Version: 1.0
+ Content-Transfer-Encoding: 7bit
+
+ One
+
+ --BOUNDARY
+ Content-Type: text/plain; charset="us-ascii"
+ MIME-Version: 1.0
+ Content-Transfer-Encoding: 7bit
+
+ Two
+
+ --BOUNDARY--
+ """)
+
def test_default_type(self):
eq = self.assertEqual
***************
*** 2182,2186 ****
eq(h.encode(), 'Hello World!')
h.append(' Goodbye World!')
! eq(h.encode(), 'Hello World! Goodbye World!')
def test_simple_surprise(self):
--- 2254,2258 ----
eq(h.encode(), 'Hello World!')
h.append(' Goodbye World!')
! eq(h.encode(), 'Hello World! Goodbye World!')
def test_simple_surprise(self):
***************
*** 2189,2193 ****
eq(h.encode(), 'Hello World!')
h.append('Goodbye World!')
! eq(h.encode(), 'Hello World!Goodbye World!')
def test_header_needs_no_decoding(self):
--- 2261,2265 ----
eq(h.encode(), 'Hello World!')
h.append('Goodbye World!')
! eq(h.encode(), 'Hello World! Goodbye World!')
def test_header_needs_no_decoding(self):
***************
*** 2198,2202 ****
h = Header("I am the very model of a modern Major-General; I've information vegetable, animal, and mineral; I know the kings of England, and I quote the fights historical from Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical; I understand equations, both the simple and quadratical; about binomial theorem I'm teeming with a lot o' news, with many cheerful facts about the square of the hypotenuse.",
maxlinelen=76)
! for l in h.encode().split('\n '):
self.failUnless(len(l) <= 76)
--- 2270,2274 ----
h = Header("I am the very model of a modern Major-General; I've information vegetable, animal, and mineral; I know the kings of England, and I quote the fights historical from Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical; I understand equations, both the simple and quadratical; about binomial theorem I'm teeming with a lot o' news, with many cheerful facts about the square of the hypotenuse.",
maxlinelen=76)
! for l in h.encode(splitchars=' ').split('\n '):
self.failUnless(len(l) <= 76)
***************
*** 2213,2231 ****
h.append(utf8_head, utf8)
enc = h.encode()
! eq(enc, """=?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_eine?=
! =?iso-8859-1?q?m_Foerderband_komfortabel_den_Korridor_ent?=
! =?iso-8859-1?q?lang=2C_an_s=FCdl=FCndischen_Wandgem=E4lden_vorbei?=
! =?iso-8859-1?q?=2C_gegen_die_rotierenden_Klingen_bef=F6rdert=2E_?=
! =?iso-8859-2?q?Finan=E8ni_metropole_se_hroutil?=
! =?iso-8859-2?q?y_pod_tlakem_jejich_d=F9vtipu=2E=2E_?=
! =?utf-8?b?5q2j56K644Gr6KiA44GG44Go57+76Kiz44Gv?=
! =?utf-8?b?44GV44KM44Gm44GE44G+44Gb44KT44CC5LiA?=
! =?utf-8?b?6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM?=
! =?utf-8?b?44CB44GC44Go44Gv44Gn44Gf44KJ44KB44Gn?=
! =?utf-8?b?44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBpc3QgZGE=?=
! =?utf-8?q?s_Nunstuck_git_und?=
! =?utf-8?q?_Slotermeyer=3F_Ja!_Beiherhund_das_Ode?=
! =?utf-8?q?r_die_Flipperwaldt?=
! =?utf-8?b?IGdlcnNwdXQu44CN44Go6KiA44Gj44Gm44GE44G+44GZ44CC?=""")
eq(decode_header(enc),
[(g_head, "iso-8859-1"), (cz_head, "iso-8859-2"),
--- 2285,2300 ----
h.append(utf8_head, utf8)
enc = h.encode()
! eq(enc, """\
! =?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerderband_ko?=
! =?iso-8859-1?q?mfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndischen_Wan?=
! =?iso-8859-1?q?dgem=E4lden_vorbei=2C_gegen_die_rotierenden_Klingen_bef=F6?=
! =?iso-8859-1?q?rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_metropole_se_hroutily?=
! =?iso-8859-2?q?_pod_tlakem_jejich_d=F9vtipu=2E=2E_?= =?utf-8?b?5q2j56K6?=
! =?utf-8?b?44Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE44G+44Gb44KT44CC?=
! =?utf-8?b?5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB44GC44Go44Gv44Gn?=
! =?utf-8?b?44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBpc3QgZGFz?=
! =?utf-8?q?_Nunstuck_git_und_Slotermeyer=3F_Ja!_Beiherhund_das_Oder_die_Fl?=
! =?utf-8?b?aXBwZXJ3YWxkdCBnZXJzcHV0LuOAjeOBqOiogOOBo+OBpuOBhOOBvuOBmQ==?=
! =?utf-8?b?44CC?=""")
eq(decode_header(enc),
[(g_head, "iso-8859-1"), (cz_head, "iso-8859-2"),
***************
*** 2318,2321 ****
--- 2387,2414 ----
h.append(x, errors='replace')
eq(str(h), x)
+
+ def test_encoded_adjacent_nonencoded(self):
+ eq = self.assertEqual
+ h = Header()
+ h.append('hello', 'iso-8859-1')
+ h.append('world')
+ s = h.encode()
+ eq(s, '=?iso-8859-1?q?hello?= world')
+ h = make_header(decode_header(s))
+ eq(h.encode(), s)
+
+ def test_whitespace_eater(self):
+ eq = self.assertEqual
+ s = 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.'
+ parts = decode_header(s)
+ eq(parts, [('Subject:', None), ('\xf0\xd2\xcf\xd7\xc5\xd2\xcb\xc1 \xce\xc1 \xc6\xc9\xce\xc1\xcc\xd8\xce\xd9\xca', 'koi8-r'), ('zz.', None)])
+ hdr = make_header(parts)
+ eq(hdr.encode(),
+ 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.')
+
+ def test_broken_base64_header(self):
+ raises = self.assertRaises
+ s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3IQ?='
+ raises(Errors.HeaderParseError, decode_header, s)