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

Skip to content

Commit 3ed1be9

Browse files
committed
Regression test for date format code, by Mike Meyer.
(I tweaked it slightly so examples are allowed to have no date too.)
1 parent 4f13669 commit 3ed1be9

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lib/test/test_rfc822.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def test(msg, results):
1111
fp.seek(0)
1212
m = rfc822.Message(fp)
1313
i = 0
14+
1415
for n, a in m.getaddrlist('to') + m.getaddrlist('cc'):
1516
if verbose:
1617
print 'name:', repr(n), 'addr:', repr(a)
@@ -28,6 +29,21 @@ def test(msg, results):
2829
print ' [no match]'
2930
print 'not found:', repr(n), repr(a)
3031

32+
out = m.getdate('date')
33+
if out:
34+
if verbose:
35+
print 'Date:', m.getheader('date')
36+
if out == (1999, 1, 13, 23, 57, 35, 0, 0, 0):
37+
if verbose:
38+
print ' [matched]'
39+
else:
40+
if verbose:
41+
print ' [no match]'
42+
print 'Date conversion failed:', out
43+
44+
# Note: all test cases must have the same date (in various formats),
45+
# or no date!
46+
3147
test('''Date: Wed, 13 Jan 1999 23:57:35 -0500
3248
From: Guido van Rossum <[email protected]>
3349
To: "Guido van
@@ -40,20 +56,23 @@ def test(msg, results):
4056
test('''From: Barry <[email protected]
4157
To: [email protected] (Guido: the Barbarian)
4258
Subject: nonsense
59+
Date: Wednesday, January 13 1999 23:57:35 -0500
4360
4461
test''', [('Guido: the Barbarian', '[email protected]'),
4562
])
4663

4764
test('''From: Barry <[email protected]
4865
To: [email protected] (Guido: the Barbarian)
4966
Cc: "Guido: the Madman" <[email protected]>
67+
Date: 13-Jan-1999 23:57:35 EST
5068
5169
test''', [('Guido: the Barbarian', '[email protected]'),
5270
('Guido: the Madman', '[email protected]')
5371
])
5472

5573
test('''To: "The monster with
5674
the very long name: Guido" <[email protected]>
75+
Date: Wed, 13 Jan 1999 23:57:35 -0500
5776
5877
test''', [('The monster with\n the very long name: Guido',
5978
@@ -63,6 +82,7 @@ def test(msg, results):
6382
6483
6584
85+
Date: Wed, 13 Jan 1999 23:57:35 -0500
6686
6787
test''', [('Amit J. Patel', '[email protected]'),
6888
('Mike Fletcher', '[email protected]'),
@@ -75,6 +95,7 @@ def test(msg, results):
7595
# This one is just twisted. I don't know what the proper result should be,
7696
# but it shouldn't be to infloop, which is what used to happen!
7797
98+
Date: Wed, 13 Jan 1999 23:57:35 -0500
7899
79100
test''', [('', ''),
80101

0 commit comments

Comments
 (0)