2 # -*- coding: utf-8 -*-
4 # Test utils.fix_maintainer()
5 # Copyright (C) 2004, 2006 James Troup <james@nocrew.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ################################################################################
25 sys.path.append(os.path.abspath('../../'))
29 ################################################################################
32 sys.stderr.write("%s\n" % (message))
35 ################################################################################
37 def check_valid(s, xa, xb, xc, xd):
38 (a, b, c, d) = utils.fix_maintainer(s)
40 fail("rfc822_maint: %s (returned) != %s (expected [From: '%s']" % (a, xa, s))
42 fail("rfc2047_maint: %s (returned) != %s (expected [From: '%s']" % (b, xb, s))
44 fail("name: %s (returned) != %s (expected [From: '%s']" % (c, xc, s))
46 fail("email: %s (returned) != %s (expected [From: '%s']" % (d, xd, s))
50 utils.fix_maintainer(s)
51 fail("%s was parsed successfully but is expected to be invalid." % (s))
52 except utils.ParseMaintError, unused:
56 # Check Valid UTF-8 maintainer field
57 s = "Noèl Köthe <noel@debian.org>"
58 xa = "Noèl Köthe <noel@debian.org>"
59 xb = "=?utf-8?b?Tm/DqGwgS8O2dGhl?= <noel@debian.org>"
61 xd = "noel@debian.org"
62 check_valid(s, xa, xb, xc, xd)
64 # Check valid ISO-8859-1 maintainer field
65 s = "Noèl Köthe <noel@debian.org>"
66 xa = "Noèl Köthe <noel@debian.org>"
67 xb = "=?iso-8859-1?q?No=E8l_K=F6the?= <noel@debian.org>"
69 xd = "noel@debian.org"
70 check_valid(s, xa, xb, xc, xd)
72 # Check valid ASCII maintainer field
73 s = "James Troup <james@nocrew.org>"
74 xa = "James Troup <james@nocrew.org>"
75 xb = "James Troup <james@nocrew.org>"
77 xd = "james@nocrew.org"
78 check_valid(s, xa, xb, xc, xd)
80 # Check "Debian vs RFC822" fixup of names with '.' or ',' in them
81 s = "James J. Troup <james@nocrew.org>"
82 xa = "james@nocrew.org (James J. Troup)"
83 xb = "james@nocrew.org (James J. Troup)"
85 xd = "james@nocrew.org"
86 check_valid(s, xa, xb, xc, xd)
87 s = "James J, Troup <james@nocrew.org>"
88 xa = "james@nocrew.org (James J, Troup)"
89 xb = "james@nocrew.org (James J, Troup)"
91 xd = "james@nocrew.org"
92 check_valid(s, xa, xb, xc, xd)
94 # Check just-email form
95 s = "james@nocrew.org"
96 xa = " <james@nocrew.org>"
97 xb = " <james@nocrew.org>"
99 xd = "james@nocrew.org"
100 check_valid(s, xa, xb, xc, xd)
102 # Check bracketed just-email form
103 s = "<james@nocrew.org>"
104 xa = " <james@nocrew.org>"
105 xb = " <james@nocrew.org>"
107 xd = "james@nocrew.org"
108 check_valid(s, xa, xb, xc, xd)
110 # Check Krazy quoted-string local part email address
111 s = "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>"
112 xa = "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>"
113 xb = "Cris van Pelt <\"Cris van Pelt\"@tribe.eu.org>"
115 xd = "\"Cris van Pelt\"@tribe.eu.org"
116 check_valid(s, xa, xb, xc, xd)
119 s = xa = xb = xc = xd = ""
120 check_valid(s, xa, xb, xc, xd)
122 # Check for missing email address
123 check_invalid("James Troup")
124 # Check for invalid email address
125 check_invalid("James Troup <james@nocrew.org")
127 ################################################################################
129 if __name__ == '__main__':