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__"
36 class PackageOptionTestCase(unittest.TestCase):
37 def test_PackageOption(self):
38 """Test PackageOption creation"""
39 opts = SCons.Options.Options()
40 opts.Add(SCons.Options.PackageOption('test', 'test option help', '/default/path'))
43 assert o.key == 'test', o.key
44 assert o.help == 'test option help\n ( yes | no | /path/to/test )', repr(o.help)
45 assert o.default == '/default/path', o.default
46 assert not o.validator is None, o.validator
47 assert not o.converter is None, o.converter
49 def test_converter(self):
50 """Test the PackageOption converter"""
51 opts = SCons.Options.Options()
52 opts.Add(SCons.Options.PackageOption('test', 'test option help', '/default/path'))
72 assert x, "converter returned false for '%s'" % t
74 for f in false_values:
76 assert not x, "converter returned true for '%s'" % f
78 x = o.converter('/explicit/path')
79 assert x == '/explicit/path', x
81 # Make sure the converter returns True if we give it str(True) and
82 # False when we give it str(False). This assures consistent operation
83 # through a cycle of Options.Save(<file>) -> Options(<file>).
84 x = o.converter(str(True))
85 assert x == True, "converter returned a string when given str(True)"
87 x = o.converter(str(False))
88 assert x == False, "converter returned a string when given str(False)"
90 def test_validator(self):
91 """Test the PackageOption validator"""
92 opts = SCons.Options.Options()
93 opts.Add(SCons.Options.PackageOption('test', 'test option help', '/default/path'))
95 test = TestCmd.TestCmd(workdir='')
96 test.write('exists', 'exists\n')
100 env = {'F':False, 'T':True, 'X':'x'}
102 exists = test.workpath('exists')
103 does_not_exist = test.workpath('does_not_exist')
105 o.validator('F', '/path', env)
106 o.validator('T', '/path', env)
107 o.validator('X', exists, env)
111 o.validator('X', does_not_exist, env)
112 except SCons.Errors.UserError:
114 assert caught, "did not catch expected UserError"
117 if __name__ == "__main__":
118 suite = unittest.makeSuite(PackageOptionTestCase, 'test_')
119 if not unittest.TextTestRunner().run(suite).wasSuccessful():