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__"
34 class PackageOptionTestCase(unittest.TestCase):
35 def test_PackageOption(self):
36 """Test PackageOption creation"""
37 opts = SCons.Options.Options()
38 opts.Add(SCons.Options.PackageOption('test', 'test option help', '/default/path'))
41 assert o.key == 'test', o.key
42 assert o.help == 'test option help\n ( yes | no | /path/to/test )', repr(o.help)
43 assert o.default == '/default/path', o.default
44 assert not o.validator is None, o.validator
45 assert not o.converter is None, o.converter
47 def test_converter(self):
48 """Test the PackageOption converter"""
49 opts = SCons.Options.Options()
50 opts.Add(SCons.Options.PackageOption('test', 'test option help', '/default/path'))
70 assert x, "converter returned false for '%s'" % t
72 for f in false_values:
74 assert not x, "converter returned true for '%s'" % f
76 x = o.converter('/explicit/path')
77 assert x == '/explicit/path', x
79 def test_validator(self):
80 """Test the PackageOption validator"""
81 opts = SCons.Options.Options()
82 opts.Add(SCons.Options.PackageOption('test', 'test option help', '/default/path'))
84 test = TestCmd.TestCmd(workdir='')
85 test.write('exists', 'exists\n')
89 env = {'F':0, 'T':1, 'X':'x'}
91 exists = test.workpath('exists')
92 does_not_exist = test.workpath('does_not_exist')
94 o.validator('F', '/path', env)
95 o.validator('T', '/path', env)
96 o.validator('X', exists, env)
100 o.validator('X', does_not_exist, env)
101 except SCons.Errors.UserError:
103 assert caught, "did not catch expected UserError"
106 if __name__ == "__main__":
107 suite = unittest.makeSuite(PackageOptionTestCase, 'test_')
108 if not unittest.TextTestRunner().run(suite).wasSuccessful():