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 BoolVariableTestCase(unittest.TestCase):
33 def test_BoolVariable(self):
34 """Test BoolVariable creation"""
35 opts = SCons.Variables.Variables()
36 opts.Add(SCons.Variables.BoolVariable('test', 'test option help', 0))
39 assert o.key == 'test', o.key
40 assert o.help == 'test option help (yes|no)', o.help
41 assert o.default == 0, o.default
42 assert not o.validator is None, o.validator
43 assert not o.converter is None, o.converter
45 def test_converter(self):
46 """Test the BoolVariable converter"""
47 opts = SCons.Variables.Variables()
48 opts.Add(SCons.Variables.BoolVariable('test', 'test option help', 0))
73 assert x, "converter returned false for '%s'" % t
75 for f in false_values:
77 assert not x, "converter returned true for '%s'" % f
84 assert caught, "did not catch expected ValueError"
86 def test_validator(self):
87 """Test the BoolVariable validator"""
88 opts = SCons.Variables.Variables()
89 opts.Add(SCons.Variables.BoolVariable('test', 'test option help', 0))
99 o.validator('T', 0, env)
101 o.validator('F', 0, env)
105 o.validator('N', 0, env)
106 except SCons.Errors.UserError:
108 assert caught, "did not catch expected UserError for N"
112 o.validator('NOSUCHKEY', 0, env)
115 assert caught, "did not catch expected KeyError for NOSUCHKEY"
118 if __name__ == "__main__":
119 suite = unittest.makeSuite(BoolVariableTestCase, 'test_')
120 if not unittest.TextTestRunner().run(suite).wasSuccessful():