4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
30 import SCons.Variables
32 class EnumVariableTestCase(unittest.TestCase):
33 def test_EnumVariable(self):
34 """Test EnumVariable creation"""
35 opts = SCons.Variables.Variables()
36 opts.Add(SCons.Variables.EnumVariable('test', 'test option help', 0,
37 ['one', 'two', 'three'],
41 assert o.key == 'test', o.key
42 assert o.help == 'test option help (one|two|three)', o.help
43 assert o.default == 0, o.default
44 assert o.validator is not None, o.validator
45 assert o.converter is not None, o.converter
47 def test_converter(self):
48 """Test the EnumVariable converter"""
49 opts = SCons.Variables.Variables()
50 opts.Add(SCons.Variables.EnumVariable('test', 'test option help', 0,
51 ['one', 'two', 'three']))
55 for a in ['one', 'two', 'three', 'no_match']:
59 opts = SCons.Variables.Variables()
60 opts.Add(SCons.Variables.EnumVariable('test', 'test option help', 0,
61 ['one', 'two', 'three'],
68 x = o.converter('one')
73 x = o.converter('two')
78 x = o.converter('three')
79 assert x == 'three', x
81 assert x == 'three', x
83 opts = SCons.Variables.Variables()
84 opts.Add(SCons.Variables.EnumVariable('test0', 'test option help', 0,
85 ['one', 'two', 'three'],
90 opts.Add(SCons.Variables.EnumVariable('test1', 'test option help', 0,
91 ['one', 'two', 'three'],
96 opts.Add(SCons.Variables.EnumVariable('test2', 'test option help', 0,
97 ['one', 'two', 'three'],
108 'one' : ['one', 'one', 'one'],
109 'One' : ['One', 'One', 'one'],
110 'ONE' : ['ONE', 'ONE', 'one'],
111 'two' : ['two', 'two', 'two'],
112 'twO' : ['twO', 'twO', 'two'],
113 'TWO' : ['TWO', 'TWO', 'two'],
114 'three' : ['three', 'three', 'three'],
115 'thRee' : ['thRee', 'thRee', 'three'],
116 'THREE' : ['THREE', 'THREE', 'three'],
117 'a' : ['one', 'one', 'one'],
118 'A' : ['A', 'one', 'one'],
119 'b' : ['two', 'two', 'two'],
120 'B' : ['B', 'two', 'two'],
121 'c' : ['three', 'three', 'three'],
122 'C' : ['C', 'three', 'three'],
125 for k, l in table.items():
127 assert x == l[0], "o0 got %s, expected %s" % (x, l[0])
129 assert x == l[1], "o1 got %s, expected %s" % (x, l[1])
131 assert x == l[2], "o2 got %s, expected %s" % (x, l[2])
133 def test_validator(self):
134 """Test the EnumVariable validator"""
135 opts = SCons.Variables.Variables()
136 opts.Add(SCons.Variables.EnumVariable('test0', 'test option help', 0,
137 ['one', 'two', 'three'],
142 opts.Add(SCons.Variables.EnumVariable('test1', 'test option help', 0,
143 ['one', 'two', 'three'],
148 opts.Add(SCons.Variables.EnumVariable('test2', 'test option help', 0,
149 ['one', 'two', 'three'],
160 o.validator('X', v, {})
165 o.validator('X', v, {})
166 except SCons.Errors.UserError:
168 assert caught, "did not catch expected UserError for o = %s, v = %s" % (o.key, v)
171 'one' : [ valid, valid, valid],
172 'One' : [invalid, valid, valid],
173 'ONE' : [invalid, valid, valid],
174 'two' : [ valid, valid, valid],
175 'twO' : [invalid, valid, valid],
176 'TWO' : [invalid, valid, valid],
177 'three' : [ valid, valid, valid],
178 'thRee' : [invalid, valid, valid],
179 'THREE' : [invalid, valid, valid],
180 'a' : [invalid, invalid, invalid],
181 'A' : [invalid, invalid, invalid],
182 'b' : [invalid, invalid, invalid],
183 'B' : [invalid, invalid, invalid],
184 'c' : [invalid, invalid, invalid],
185 'C' : [invalid, invalid, invalid],
186 'no_v' : [invalid, invalid, invalid],
189 for v, l in table.items():
195 if __name__ == "__main__":
196 suite = unittest.makeSuite(EnumVariableTestCase, 'test_')
197 if not unittest.TextTestRunner().run(suite).wasSuccessful():
202 # indent-tabs-mode:nil
204 # vim: set expandtab tabstop=4 shiftwidth=4: