test_rfc822.py :  » Mobile » Python-for-PalmOS » Python-1.5.2+reduced-1.0 » Lib » test » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Mobile » Python for PalmOS 
Python for PalmOS » Python 1.5.2 reduced 1.0 » Lib » test » test_rfc822.py
from test_support import verbose
import rfc822, sys
try:
    from cStringIO import StringIO
except ImportError:
    from StringIO import StringIO

def test(msg, results):
    fp = StringIO()
    fp.write(msg)
    fp.seek(0)
    m = rfc822.Message(fp)
    i = 0
    
    for n, a in m.getaddrlist('to') + m.getaddrlist('cc'):
        if verbose:
            print 'name:', repr(n), 'addr:', repr(a)
        try:
            mn, ma = results[i][0], results[i][1]
        except IndexError:
            print 'extra parsed address:', repr(n), repr(a)
            continue
        i = i + 1
        if mn == n and ma == a:
            if verbose:
                print '    [matched]'
        else:
            if verbose:
                print '    [no match]'
            print 'not found:', repr(n), repr(a)

    out = m.getdate('date')
    if out:
        if verbose:
            print 'Date:', m.getheader('date')
        if out == (1999, 1, 13, 23, 57, 35, 0, 0, 0):
            if verbose:
                print '    [matched]'
        else:
            if verbose:
                print '    [no match]'
            print 'Date conversion failed:', out

# Note: all test cases must have the same date (in various formats),
# or no date!

test('''Date:    Wed, 13 Jan 1999 23:57:35 -0500
From:    Guido van Rossum <guido@CNRI.Reston.VA.US>
To:      "Guido van
   : Rossum" <guido@python.org>
Subject: test2

test2
''', [('Guido van\n   : Rossum', 'guido@python.org')])

test('''From: Barry <bwarsaw@python.org
To: guido@python.org (Guido: the Barbarian)
Subject: nonsense
Date: Wednesday, January 13 1999 23:57:35 -0500

test''', [('Guido: the Barbarian', 'guido@python.org'),
          ])

test('''From: Barry <bwarsaw@python.org
To: guido@python.org (Guido: the Barbarian)
Cc: "Guido: the Madman" <guido@python.org>
Date:  13-Jan-1999 23:57:35 EST

test''', [('Guido: the Barbarian', 'guido@python.org'),
          ('Guido: the Madman', 'guido@python.org')
          ])

test('''To: "The monster with
     the very long name: Guido" <guido@python.org>
Date:    Wed, 13 Jan 1999 23:57:35 -0500

test''', [('The monster with\n     the very long name: Guido',
           'guido@python.org')])

test('''To: "Amit J. Patel" <amitp@Theory.Stanford.EDU>
CC: Mike Fletcher <mfletch@vrtelecom.com>,
        "'string-sig@python.org'" <string-sig@python.org>
Cc: fooz@bat.com, bart@toof.com
Cc: goit@lip.com
Date:    Wed, 13 Jan 1999 23:57:35 -0500

test''', [('Amit J. Patel', 'amitp@Theory.Stanford.EDU'),
          ('Mike Fletcher', 'mfletch@vrtelecom.com'),
          ("'string-sig@python.org'", 'string-sig@python.org'),
          ('', 'fooz@bat.com'),
          ('', 'bart@toof.com'),
          ('', 'goit@lip.com'),
          ])

# This one is just twisted.  I don't know what the proper result should be,
# but it shouldn't be to infloop, which is what used to happen!
test('''To: <[smtp:dd47@mail.xxx.edu]_at_hmhq@hdq-mdm1-imgout.companay.com>
Date:    Wed, 13 Jan 1999 23:57:35 -0500

test''', [('', ''),
          ('', 'dd47@mail.xxx.edu'),
          ('', '_at_hmhq@hdq-mdm1-imgout.companay.com')
          ])

# This exercises the old commas-in-a-full-name bug, which should be doing the
# right thing in recent versions of the module.
test('''To: "last, first" <userid@foo.net>

test''', [('last, first', 'userid@foo.net'),
          ])

test('''To: (Comment stuff) "Quoted name"@somewhere.com

test''', [('Comment stuff', '"Quoted name"@somewhere.com'),
          ])

test('''To: :
Cc: goit@lip.com
Date:    Wed, 13 Jan 1999 23:57:35 -0500

test''', [('', 'goit@lip.com')])

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.