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