]> git.decadent.org.uk Git - dak.git/blob - dak/test/006/test.py
Stop using silly names, and migrate to a saner directory structure.
[dak.git] / dak / test / 006 / test.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
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 $
7
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.
12
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.
17
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
21
22 ################################################################################
23
24 import os, sys
25
26 sys.path.append(os.path.abspath('../../'));
27
28 import utils
29
30 ################################################################################
31
32 def fail(message):
33     sys.stderr.write("%s\n" % (message));
34     sys.exit(1);
35
36 ################################################################################
37
38 def check_valid(s, xa, xb, xc, xd):
39     (a, b, c, d) = utils.fix_maintainer(s)
40     if a != xa:
41         fail("rfc822_maint: %s (returned) != %s (expected [From: '%s']" % (a, xa, s));
42     if b != xb:
43         fail("rfc2047_maint: %s (returned) != %s (expected [From: '%s']" % (b, xb, s));
44     if c != xc:
45         fail("name: %s (returned) != %s (expected [From: '%s']" % (c, xc, s));
46     if d != xd:
47         fail("email: %s (returned) != %s (expected [From: '%s']" % (d, xd, s));
48
49 def check_invalid(s):
50     try:
51         utils.fix_maintainer(s);
52         fail("%s was parsed successfully but is expected to be invalid." % (s));
53     except utils.ParseMaintError, unused:
54         pass;
55
56 def main ():
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>"
61     xc = "Noèl Köthe"
62     xd = "noel@debian.org"
63     check_valid(s, xa, xb, xc, xd);
64
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>"
69     xc = "Noèl Köthe"
70     xd = "noel@debian.org"
71     check_valid(s, xa, xb, xc, xd);
72
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>"
77     xc = "James Troup"
78     xd = "james@nocrew.org"
79     check_valid(s, xa, xb, xc, xd);
80
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)"
85     xc = "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)"
91     xc = "James J, Troup"
92     xd = "james@nocrew.org"
93     check_valid(s, xa, xb, xc, xd);
94
95     # Check just-email form
96     s = "james@nocrew.org"
97     xa = " <james@nocrew.org>"
98     xb = " <james@nocrew.org>"
99     xc = ""
100     xd = "james@nocrew.org"
101     check_valid(s, xa, xb, xc, xd);
102
103     # Check bracketed just-email form
104     s = "<james@nocrew.org>"
105     xa = " <james@nocrew.org>"
106     xb = " <james@nocrew.org>"
107     xc = ""
108     xd = "james@nocrew.org"
109     check_valid(s, xa, xb, xc, xd);
110
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>"
115     xc = "Cris van Pelt"
116     xd = "\"Cris van Pelt\"@tribe.eu.org"
117     check_valid(s, xa, xb, xc, xd);
118
119     # Check empty string
120     s = xa = xb = xc = xd = "";
121     check_valid(s, xa, xb, xc, xd);
122
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");
127
128 ################################################################################
129
130 if __name__ == '__main__':
131     main()