]> git.decadent.org.uk Git - dak.git/blob - dak/test/004/test.py
Stop using silly names, and migrate to a saner directory structure.
[dak.git] / dak / test / 004 / test.py
1 #!/usr/bin/env python
2
3 # Check utils.extract_component_from_section()
4 # Copyright (C) 2000  James Troup <james@nocrew.org>
5 # $Id: test.py,v 1.3 2002-10-16 02:47:32 troup Exp $
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 utils
28
29 ################################################################################
30
31 def fail(message):
32     sys.stderr.write("%s\n" % (message));
33     sys.exit(1);
34
35 ################################################################################
36
37 # prefix: non-US
38 # component: main, contrib, non-free
39 # section: games, admin, libs, [...]
40
41 # [1] Order is as above.
42 # [2] Prefix is optional for the default archive, but mandatory when
43 #     uploads are going anywhere else.
44 # [3] Default component is main and may be omitted.
45 # [4] Section is optional.
46 # [5] Prefix is case insensitive
47 # [6] Everything else is case sensitive.
48
49 def test(input, output):
50     result = utils.extract_component_from_section(input);
51     if result != output:
52         fail ("%s -> %r [should have been %r]" % (input, result, output));
53
54 def main ():
55     # Err, whoops?  should probably be "utils", "main"...
56     input = "main/utils"; output = ("main/utils", "main");
57     test (input, output);
58
59
60     # Validate #3
61     input = "utils"; output = ("utils", "main");
62     test (input, output);
63
64     input = "non-free/libs"; output = ("non-free/libs", "non-free");
65     test (input, output);
66
67     input = "contrib/net"; output = ("contrib/net", "contrib");
68     test (input, output);
69
70
71     # Validate #3 with a prefix
72     input = "non-US"; output = ("non-US", "non-US/main");
73     test (input, output);
74
75
76     # Validate #4
77     input = "main"; output = ("main", "main");
78     test (input, output);
79
80     input = "contrib"; output = ("contrib", "contrib");
81     test (input, output);
82
83     input = "non-free"; output = ("non-free", "non-free");
84     test (input, output);
85
86
87     # Validate #4 with a prefix
88     input = "non-US/main"; output = ("non-US/main", "non-US/main");
89     test (input, output);
90
91     input = "non-US/contrib"; output = ("non-US/contrib", "non-US/contrib");
92     test (input, output);
93
94     input = "non-US/non-free"; output = ("non-US/non-free", "non-US/non-free");
95     test (input, output);
96
97
98     # Validate #5
99     input = "non-us"; output = ("non-us", "non-US/main");
100     test (input, output);
101
102     input = "non-us/contrib"; output = ("non-us/contrib", "non-US/contrib");
103     test (input, output);
104
105
106     # Validate #6 (section)
107     input = "utIls"; output = ("utIls", "main");
108     test (input, output);
109
110     # Others..
111     input = "non-US/libs"; output = ("non-US/libs", "non-US/main");
112     test (input, output);
113     input = "non-US/main/libs"; output = ("non-US/main/libs", "non-US/main");
114     test (input, output);
115     input = "non-US/contrib/libs"; output = ("non-US/contrib/libs", "non-US/contrib");
116     test (input, output);
117     input = "non-US/non-free/libs"; output = ("non-US/non-free/libs", "non-US/non-free");
118     test (input, output);
119
120 ################################################################################
121
122 if __name__ == '__main__':
123     main()