Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e75888e

Browse files
committed
Test the rfc822.py module. Contains just a few simple cases, and some
troublesome ones encountered on the c.l.py list.
1 parent 8a57843 commit e75888e

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lib/test/output/test_rfc822

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test_rfc822

Lib/test/test_rfc822.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
from test_support import verbose
2+
import rfc822, sys
3+
try:
4+
from cStringIO import StringIO
5+
except ImportError:
6+
from StringIO import StringIO
7+
8+
def test(msg, results):
9+
fp = StringIO()
10+
fp.write(msg)
11+
fp.seek(0)
12+
m = rfc822.Message(fp)
13+
i = 0
14+
for n, a in m.getaddrlist('to') + m.getaddrlist('cc'):
15+
if verbose:
16+
print 'name:', repr(n), 'addr:', repr(a)
17+
try:
18+
mn, ma = results[i][0], results[i][1]
19+
except IndexError:
20+
print 'extra parsed address:', repr(n), repr(a)
21+
continue
22+
i = i + 1
23+
if mn == n and ma == a:
24+
if verbose:
25+
print ' [matched]'
26+
else:
27+
if verbose:
28+
print ' [no match]'
29+
print 'not found:', repr(n), repr(a)
30+
31+
test('''Date: Wed, 13 Jan 1999 23:57:35 -0500
32+
From: Guido van Rossum <[email protected]>
33+
To: "Guido van
34+
: Rossum" <[email protected]>
35+
Subject: test2
36+
37+
test2
38+
''', [('Guido van\n : Rossum', '[email protected]')])
39+
40+
test('''From: Barry <[email protected]
41+
To: [email protected] (Guido: the Barbarian)
42+
Subject: nonsense
43+
44+
test''', [('Guido: the Barbarian', '[email protected]'),
45+
])
46+
47+
test('''From: Barry <[email protected]
48+
To: [email protected] (Guido: the Barbarian)
49+
Cc: "Guido: the Madman" <[email protected]>
50+
51+
test''', [('Guido: the Barbarian', '[email protected]'),
52+
('Guido: the Madman', '[email protected]')
53+
])
54+
55+
test('''To: "The monster with
56+
the very long name: Guido" <[email protected]>
57+
58+
test''', [('The monster with\n the very long name: Guido',
59+
60+
61+
test('''To: "Amit J. Patel" <[email protected]>
62+
CC: Mike Fletcher <[email protected]>,
63+
64+
65+
66+
67+
test''', [('Amit J. Patel', '[email protected]'),
68+
('Mike Fletcher', '[email protected]'),
69+
70+
71+
72+
73+
])
74+
75+
# This one is just twisted. I don't know what the proper result should be,
76+
# but it shouldn't be to infloop, which is what used to happen!
77+
78+
79+
test''', [('', ''),
80+
81+
82+
])

0 commit comments

Comments
 (0)