2 # -*- coding: utf-8 -*-
4 # Test utils.fix_maintainer()
5 # Copyright (C) 2004 James Troup <james@nocrew.org>
6 # $Id: test.py,v 1.2 2004-06-23 23:11:51 troup Exp $
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 ################################################################################
26 sys.path.append(os.path.abspath('../../'))
30 ################################################################################
33 sys.stderr.write("%s\n" % (message))
36 ################################################################################
38 def check_valid(s, xa, xb, xc, xd):
39 (a, b, c, d) = utils.fix_maintainer(s)
41 fail("rfc822_maint: %s (returned) != %s (expected [From: '%s']" % (a, xa, s))
43 fail("rfc2047_maint: %s (returned) != %s (expected [From: '%s']" % (b, xb, s))
45 fail("name: %s (returned) != %s (expected [From: '%s']" % (c, xc, s))
47 fail("email: %s (returned) != %s (expected [From: '%s']" % (d, xd, s))
51 utils.fix_maintainer(s)
52 fail("%s was parsed successfully but is expected to be invalid." % (s))
53 except utils.ParseMaintError, unused:
57 # Check Valid UTF-8 maintainer field
58 s = "Noèl Köthe <noel@debian.org>"
59 xa = "Noèl Köthe <noel@debian.org>"
60 xb = "=?utf-8?b?Tm/DqGwgS8O2dGhl?= <noel@debian.org>"
62 xd = "noel@debian.org"
63 check_valid(s, xa, xb, xc, xd)
65 # Check valid ISO-8859-1 maintainer field
66 s = "Noèl Köthe <noel@debian.org>"
67 xa = "Noèl Köthe <noel@debian.org>"
68 xb = "=?iso-8859-1?q?No=E8l_K=F6the?= <noel@debian.org>"
70 xd = "noel@debian.org"
71 check_valid(s, xa, xb, xc, xd)
73 # Check valid ASCII maintainer field
74 s = "James Troup <james@nocrew.org>"
75 xa = "James Troup <james@nocrew.org>"
76 xb = "James Troup <james@nocrew.org>"
78 xd = "james@nocrew.org"
79 check_valid(s, xa, xb, xc, xd)
81 # Check "Debian vs RFC822" fixup of names with '.' or ',' in them
82 s = "James J. Troup <james@nocrew.org>"
83 xa = "james@nocrew.org (James J. Troup)"
84 xb = "james@nocrew.org (James J. Troup)"
86 xd = "james@nocrew.org"
87 check_valid(s, xa, xb, xc, xd)
88 s = "James J, Troup <james@nocrew.org>"
89 xa = "james@nocrew.org (James J, Troup)"
90 xb = "james@nocrew.org (James J, Troup)"
92 xd = "james@nocrew.org"
93 check_valid(s, xa, xb, xc, xd)
95 # Check just-email form
96 s = "james@nocrew.org"
97 xa = " <james@nocrew.org>"
98 xb = " <james@nocrew.org>"
100 xd = "james@nocrew.org"
101 check_valid(s, xa, xb, xc, xd)
103 # Check bracketed just-email form
104 s = "<james@nocrew.org>"
105 xa = " <james@nocrew.org>"
106 xb = " <james@nocrew.org>"
108 xd = "james@nocrew.org"
109 check_valid(s, xa, xb, xc, xd)
111 # Check Krazy quoted-string local part email address
112 s = "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>"
113 xa = "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>"
114 xb = "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>"
116 xd = "\"Cris van Pelt\"@tribe.eu.org"
117 check_valid(s, xa, xb, xc, xd)
120 s = xa = xb = xc = xd = ""
121 check_valid(s, xa, xb, xc, xd)
123 # Check for missing email address
124 check_invalid("James Troup")
125 # Check for invalid email address
126 check_invalid("James Troup <james@nocrew.org")
128 ################################################################################
130 if __name__ == '__main__':