Back to index

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

List of all members.

Public Member Functions

def test_simple
def test_simple_surprise
def test_header_needs_no_decoding
def test_long
def test_multilingual
def test_empty_header_encode
def test_header_ctor_default_args
def test_explicit_maxlinelen
def test_quopri_splittable
def test_base64_splittable
def test_us_ascii_header
def test_string_charset
def ndiffAssertEqual

Detailed Description

Definition at line 3894 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 4081 of file test_email.py.

04081 
04082     def test_base64_splittable(self):
04083         eq = self.ndiffAssertEqual
04084         h = Header(charset='koi8-r', maxlinelen=20)
04085         x = 'xxxx ' * 20
04086         h.append(x)
04087         s = h.encode()
04088         eq(s, """\
04089 =?koi8-r?b?eHh4?=
04090  =?koi8-r?b?eCB4?=
04091  =?koi8-r?b?eHh4?=
04092  =?koi8-r?b?IHh4?=
04093  =?koi8-r?b?eHgg?=
04094  =?koi8-r?b?eHh4?=
04095  =?koi8-r?b?eCB4?=
04096  =?koi8-r?b?eHh4?=
04097  =?koi8-r?b?IHh4?=
04098  =?koi8-r?b?eHgg?=
04099  =?koi8-r?b?eHh4?=
04100  =?koi8-r?b?eCB4?=
04101  =?koi8-r?b?eHh4?=
04102  =?koi8-r?b?IHh4?=
04103  =?koi8-r?b?eHgg?=
04104  =?koi8-r?b?eHh4?=
04105  =?koi8-r?b?eCB4?=
04106  =?koi8-r?b?eHh4?=
04107  =?koi8-r?b?IHh4?=
04108  =?koi8-r?b?eHgg?=
04109  =?koi8-r?b?eHh4?=
04110  =?koi8-r?b?eCB4?=
04111  =?koi8-r?b?eHh4?=
04112  =?koi8-r?b?IHh4?=
04113  =?koi8-r?b?eHgg?=
04114  =?koi8-r?b?eHh4?=
04115  =?koi8-r?b?eCB4?=
04116  =?koi8-r?b?eHh4?=
04117  =?koi8-r?b?IHh4?=
04118  =?koi8-r?b?eHgg?=
04119  =?koi8-r?b?eHh4?=
04120  =?koi8-r?b?eCB4?=
04121  =?koi8-r?b?eHh4?=
04122  =?koi8-r?b?IA==?=""")
04123         eq(x, str(make_header(decode_header(s))))
04124         h = Header(charset='koi8-r', maxlinelen=40)
04125         h.append(x)
04126         s = h.encode()
04127         eq(s, """\
04128 =?koi8-r?b?eHh4eCB4eHh4IHh4eHggeHh4?=
04129  =?koi8-r?b?eCB4eHh4IHh4eHggeHh4eCB4?=
04130  =?koi8-r?b?eHh4IHh4eHggeHh4eCB4eHh4?=
04131  =?koi8-r?b?IHh4eHggeHh4eCB4eHh4IHh4?=
04132  =?koi8-r?b?eHggeHh4eCB4eHh4IHh4eHgg?=
04133  =?koi8-r?b?eHh4eCB4eHh4IA==?=""")
04134         eq(x, str(make_header(decode_header(s))))

Here is the call graph for this function:

Definition at line 3982 of file test_email.py.

03982 
03983     def test_empty_header_encode(self):
03984         h = Header()
03985         self.assertEqual(h.encode(), '')

Here is the call graph for this function:

Definition at line 3993 of file test_email.py.

03993 
03994     def test_explicit_maxlinelen(self):
03995         eq = self.ndiffAssertEqual
03996         hstr = ('A very long line that must get split to something other '
03997                 'than at the 76th character boundary to test the non-default '
03998                 'behavior')
03999         h = Header(hstr)
04000         eq(h.encode(), '''\
04001 A very long line that must get split to something other than at the 76th
04002  character boundary to test the non-default behavior''')
04003         eq(str(h), hstr)
04004         h = Header(hstr, header_name='Subject')
04005         eq(h.encode(), '''\
04006 A very long line that must get split to something other than at the
04007  76th character boundary to test the non-default behavior''')
04008         eq(str(h), hstr)
04009         h = Header(hstr, maxlinelen=1024, header_name='Subject')
04010         eq(h.encode(), hstr)
04011         eq(str(h), hstr)

Here is the call graph for this function:

Definition at line 3986 of file test_email.py.

03986 
03987     def test_header_ctor_default_args(self):
03988         eq = self.ndiffAssertEqual
03989         h = Header()
03990         eq(h, '')
03991         h.append('foo', Charset('iso-8859-1'))
03992         eq(h, 'foo')

Here is the call graph for this function:

Definition at line 3909 of file test_email.py.

03909 
03910     def test_header_needs_no_decoding(self):
03911         h = 'no decoding needed'
03912         self.assertEqual(decode_header(h), [(h, None)])

Here is the call graph for this function:

Definition at line 3913 of file test_email.py.

03913 
03914     def test_long(self):
03915         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.",
03916                    maxlinelen=76)
03917         for l in h.encode(splitchars=' ').split('\n '):
03918             self.assertTrue(len(l) <= 76)

Here is the call graph for this function:

Definition at line 3919 of file test_email.py.

03919 
03920     def test_multilingual(self):
03921         eq = self.ndiffAssertEqual
03922         g = Charset("iso-8859-1")
03923         cz = Charset("iso-8859-2")
03924         utf8 = Charset("utf-8")
03925         g_head = (b'Die Mieter treten hier ein werden mit einem '
03926                   b'Foerderband komfortabel den Korridor entlang, '
03927                   b'an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, '
03928                   b'gegen die rotierenden Klingen bef\xf6rdert. ')
03929         cz_head = (b'Finan\xe8ni metropole se hroutily pod tlakem jejich '
03930                    b'd\xf9vtipu.. ')
03931         utf8_head = ('\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f'
03932                      '\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00'
03933                      '\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c'
03934                      '\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067'
03935                      '\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das '
03936                      'Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder '
03937                      'die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066'
03938                      '\u3044\u307e\u3059\u3002')
03939         h = Header(g_head, g)
03940         h.append(cz_head, cz)
03941         h.append(utf8_head, utf8)
03942         enc = h.encode(maxlinelen=76)
03943         eq(enc, """\
03944 =?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerderband_kom?=
03945  =?iso-8859-1?q?fortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndischen_Wand?=
03946  =?iso-8859-1?q?gem=E4lden_vorbei=2C_gegen_die_rotierenden_Klingen_bef=F6r?=
03947  =?iso-8859-1?q?dert=2E_?= =?iso-8859-2?q?Finan=E8ni_metropole_se_hroutily?=
03948  =?iso-8859-2?q?_pod_tlakem_jejich_d=F9vtipu=2E=2E_?= =?utf-8?b?5q2j56K6?=
03949  =?utf-8?b?44Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE44G+44Gb44KT44CC?=
03950  =?utf-8?b?5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB44GC44Go44Gv44Gn?=
03951  =?utf-8?b?44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBpc3QgZGFz?=
03952  =?utf-8?b?IE51bnN0dWNrIGdpdCB1bmQgU2xvdGVybWV5ZXI/IEphISBCZWloZXJodW5k?=
03953  =?utf-8?b?IGRhcyBPZGVyIGRpZSBGbGlwcGVyd2FsZHQgZ2Vyc3B1dC7jgI3jgajoqIA=?=
03954  =?utf-8?b?44Gj44Gm44GE44G+44GZ44CC?=""")
03955         decoded = decode_header(enc)
03956         eq(len(decoded), 3)
03957         eq(decoded[0], (g_head, 'iso-8859-1'))
03958         eq(decoded[1], (cz_head, 'iso-8859-2'))
03959         eq(decoded[2], (utf8_head.encode('utf-8'), 'utf-8'))
03960         ustr = str(h)
03961         eq(ustr,
03962            (b'Die Mieter treten hier ein werden mit einem Foerderband '
03963             b'komfortabel den Korridor entlang, an s\xc3\xbcdl\xc3\xbcndischen '
03964             b'Wandgem\xc3\xa4lden vorbei, gegen die rotierenden Klingen '
03965             b'bef\xc3\xb6rdert. Finan\xc4\x8dni metropole se hroutily pod '
03966             b'tlakem jejich d\xc5\xafvtipu.. \xe6\xad\xa3\xe7\xa2\xba\xe3\x81'
03967             b'\xab\xe8\xa8\x80\xe3\x81\x86\xe3\x81\xa8\xe7\xbf\xbb\xe8\xa8\xb3'
03968             b'\xe3\x81\xaf\xe3\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3'
03969             b'\x81\xbe\xe3\x81\x9b\xe3\x82\x93\xe3\x80\x82\xe4\xb8\x80\xe9\x83'
03970             b'\xa8\xe3\x81\xaf\xe3\x83\x89\xe3\x82\xa4\xe3\x83\x84\xe8\xaa\x9e'
03971             b'\xe3\x81\xa7\xe3\x81\x99\xe3\x81\x8c\xe3\x80\x81\xe3\x81\x82\xe3'
03972             b'\x81\xa8\xe3\x81\xaf\xe3\x81\xa7\xe3\x81\x9f\xe3\x82\x89\xe3\x82'
03973             b'\x81\xe3\x81\xa7\xe3\x81\x99\xe3\x80\x82\xe5\xae\x9f\xe9\x9a\x9b'
03974             b'\xe3\x81\xab\xe3\x81\xaf\xe3\x80\x8cWenn ist das Nunstuck git '
03975             b'und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt '
03976             b'gersput.\xe3\x80\x8d\xe3\x81\xa8\xe8\xa8\x80\xe3\x81\xa3\xe3\x81'
03977             b'\xa6\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82'
03978             ).decode('utf-8'))
03979         # Test make_header()
03980         newh = make_header(decode_header(enc))
03981         eq(newh, h)

Here is the call graph for this function:

Definition at line 4012 of file test_email.py.

04012 
04013     def test_quopri_splittable(self):
04014         eq = self.ndiffAssertEqual
04015         h = Header(charset='iso-8859-1', maxlinelen=20)
04016         x = 'xxxx ' * 20
04017         h.append(x)
04018         s = h.encode()
04019         eq(s, """\
04020 =?iso-8859-1?q?xxx?=
04021  =?iso-8859-1?q?x_?=
04022  =?iso-8859-1?q?xx?=
04023  =?iso-8859-1?q?xx?=
04024  =?iso-8859-1?q?_x?=
04025  =?iso-8859-1?q?xx?=
04026  =?iso-8859-1?q?x_?=
04027  =?iso-8859-1?q?xx?=
04028  =?iso-8859-1?q?xx?=
04029  =?iso-8859-1?q?_x?=
04030  =?iso-8859-1?q?xx?=
04031  =?iso-8859-1?q?x_?=
04032  =?iso-8859-1?q?xx?=
04033  =?iso-8859-1?q?xx?=
04034  =?iso-8859-1?q?_x?=
04035  =?iso-8859-1?q?xx?=
04036  =?iso-8859-1?q?x_?=
04037  =?iso-8859-1?q?xx?=
04038  =?iso-8859-1?q?xx?=
04039  =?iso-8859-1?q?_x?=
04040  =?iso-8859-1?q?xx?=
04041  =?iso-8859-1?q?x_?=
04042  =?iso-8859-1?q?xx?=
04043  =?iso-8859-1?q?xx?=
04044  =?iso-8859-1?q?_x?=
04045  =?iso-8859-1?q?xx?=
04046  =?iso-8859-1?q?x_?=
04047  =?iso-8859-1?q?xx?=
04048  =?iso-8859-1?q?xx?=
04049  =?iso-8859-1?q?_x?=
04050  =?iso-8859-1?q?xx?=
04051  =?iso-8859-1?q?x_?=
04052  =?iso-8859-1?q?xx?=
04053  =?iso-8859-1?q?xx?=
04054  =?iso-8859-1?q?_x?=
04055  =?iso-8859-1?q?xx?=
04056  =?iso-8859-1?q?x_?=
04057  =?iso-8859-1?q?xx?=
04058  =?iso-8859-1?q?xx?=
04059  =?iso-8859-1?q?_x?=
04060  =?iso-8859-1?q?xx?=
04061  =?iso-8859-1?q?x_?=
04062  =?iso-8859-1?q?xx?=
04063  =?iso-8859-1?q?xx?=
04064  =?iso-8859-1?q?_x?=
04065  =?iso-8859-1?q?xx?=
04066  =?iso-8859-1?q?x_?=
04067  =?iso-8859-1?q?xx?=
04068  =?iso-8859-1?q?xx?=
04069  =?iso-8859-1?q?_?=""")
04070         eq(x, str(make_header(decode_header(s))))
04071         h = Header(charset='iso-8859-1', maxlinelen=40)
04072         h.append('xxxx ' * 20)
04073         s = h.encode()
04074         eq(s, """\
04075 =?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xxx?=
04076  =?iso-8859-1?q?x_xxxx_xxxx_xxxx_xxxx_?=
04077  =?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xx?=
04078  =?iso-8859-1?q?xx_xxxx_xxxx_xxxx_xxxx?=
04079  =?iso-8859-1?q?_xxxx_xxxx_?=""")
04080         eq(x, str(make_header(decode_header(s))))

Here is the call graph for this function:

Definition at line 3895 of file test_email.py.

03895 
03896     def test_simple(self):
03897         eq = self.ndiffAssertEqual
03898         h = Header('Hello World!')
03899         eq(h.encode(), 'Hello World!')
03900         h.append(' Goodbye World!')
03901         eq(h.encode(), 'Hello World!  Goodbye World!')

Here is the call graph for this function:

Definition at line 3902 of file test_email.py.

03902 
03903     def test_simple_surprise(self):
03904         eq = self.ndiffAssertEqual
03905         h = Header('Hello World!')
03906         eq(h.encode(), 'Hello World!')
03907         h.append('Goodbye World!')
03908         eq(h.encode(), 'Hello World! Goodbye World!')

Here is the call graph for this function:

Definition at line 4143 of file test_email.py.

04143 
04144     def test_string_charset(self):
04145         eq = self.assertEqual
04146         h = Header()
04147         h.append('hello', 'iso-8859-1')
04148         eq(h, 'hello')

Here is the call graph for this function:

Definition at line 4135 of file test_email.py.

04135 
04136     def test_us_ascii_header(self):
04137         eq = self.assertEqual
04138         s = 'hello'
04139         x = decode_header(s)
04140         eq(x, [('hello', None)])
04141         h = make_header(x)
04142         eq(s, h.encode())

Here is the call graph for this function:


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