]> git.decadent.org.uk Git - dak.git/blob - dak/test/004/test.py
Merge commit 'godog/master' into merge
[dak.git] / dak / test / 004 / test.py
1 #!/usr/bin/env python
2
3 # Check utils.extract_component_from_section()
4 # Copyright (C) 2000, 2006  James Troup <james@nocrew.org>
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 ################################################################################
21
22 import os, sys
23
24 sys.path.append(os.path.abspath('../../'))
25
26 import utils
27
28 ################################################################################
29
30 def fail(message):
31     sys.stderr.write("%s\n" % (message))
32     sys.exit(1)
33
34 ################################################################################
35
36 # prefix: non-US
37 # component: main, contrib, non-free
38 # section: games, admin, libs, [...]
39
40 # [1] Order is as above.
41 # [2] Prefix is optional for the default archive, but mandatory when
42 #     uploads are going anywhere else.
43 # [3] Default component is main and may be omitted.
44 # [4] Section is optional.
45 # [5] Prefix is case insensitive
46 # [6] Everything else is case sensitive.
47
48 def test(input, output):
49     result = utils.extract_component_from_section(input)
50     if result != output:
51         fail ("%s -> %r [should have been %r]" % (input, result, output))
52
53 def main ():
54     # Err, whoops?  should probably be "utils", "main"...
55     input = "main/utils"; output = ("main/utils", "main")
56     test (input, output)
57
58
59     # Validate #3
60     input = "utils"; output = ("utils", "main")
61     test (input, output)
62
63     input = "non-free/libs"; output = ("non-free/libs", "non-free")
64     test (input, output)
65
66     input = "contrib/net"; output = ("contrib/net", "contrib")
67     test (input, output)
68
69
70     # Validate #3 with a prefix
71     input = "non-US"; output = ("non-US", "non-US/main")
72     test (input, output)
73
74
75     # Validate #4
76     input = "main"; output = ("main", "main")
77     test (input, output)
78
79     input = "contrib"; output = ("contrib", "contrib")
80     test (input, output)
81
82     input = "non-free"; output = ("non-free", "non-free")
83     test (input, output)
84
85
86     # Validate #4 with a prefix
87     input = "non-US/main"; output = ("non-US/main", "non-US/main")
88     test (input, output)
89
90     input = "non-US/contrib"; output = ("non-US/contrib", "non-US/contrib")
91     test (input, output)
92
93     input = "non-US/non-free"; output = ("non-US/non-free", "non-US/non-free")
94     test (input, output)
95
96
97     # Validate #5
98     input = "non-us"; output = ("non-us", "non-US/main")
99     test (input, output)
100
101     input = "non-us/contrib"; output = ("non-us/contrib", "non-US/contrib")
102     test (input, output)
103
104
105     # Validate #6 (section)
106     input = "utIls"; output = ("utIls", "main")
107     test (input, output)
108
109     # Others..
110     input = "non-US/libs"; output = ("non-US/libs", "non-US/main")
111     test (input, output)
112     input = "non-US/main/libs"; output = ("non-US/main/libs", "non-US/main")
113     test (input, output)
114     input = "non-US/contrib/libs"; output = ("non-US/contrib/libs", "non-US/contrib")
115     test (input, output)
116     input = "non-US/non-free/libs"; output = ("non-US/non-free/libs", "non-US/non-free")
117     test (input, output)
118
119 ################################################################################
120
121 if __name__ == '__main__':
122     main()