From: stevenknight Date: Sat, 21 Aug 2004 14:32:17 +0000 (+0000) Subject: Fix env.Copy() stack trace. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f4da410cf55e0e6bde6afb274ea8d90617c2a450;p=scons.git Fix env.Copy() stack trace. git-svn-id: http://scons.tigris.org/svn/scons/trunk@1046 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Options/ListOption.py b/src/engine/SCons/Options/ListOption.py index 20b7e99f..eade3742 100644 --- a/src/engine/SCons/Options/ListOption.py +++ b/src/engine/SCons/Options/ListOption.py @@ -59,7 +59,7 @@ import UserList class _ListOption(UserList.UserList): - def __init__(self, allowedElems, initlist): + def __init__(self, initlist=[], allowedElems=[]): UserList.UserList.__init__(self, filter(None, initlist)) self.allowedElems = allowedElems[:] self.allowedElems.sort() @@ -103,7 +103,7 @@ def _converter(val, allowedElems): if notAllowed: raise ValueError("Invalid value(s) for option: %s" % string.join(notAllowed, ',')) - return _ListOption(allowedElems, val) + return _ListOption(val, allowedElems) ## def _validator(key, val, env): diff --git a/src/engine/SCons/Options/ListOptionTests.py b/src/engine/SCons/Options/ListOptionTests.py index 21757202..0c7cc8eb 100644 --- a/src/engine/SCons/Options/ListOptionTests.py +++ b/src/engine/SCons/Options/ListOptionTests.py @@ -23,6 +23,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import copy import sys import unittest @@ -94,6 +95,16 @@ class ListOptionTestCase(unittest.TestCase): caught = 1 assert caught, "did not catch expected ValueError" + def test_copy(self): + """Test copying a ListOption like an Environment would""" + opts = SCons.Options.Options() + opts.Add(SCons.Options.ListOption('test', 'test option help', 'all', + ['one', 'two', 'three'])) + + o = opts.options[0] + + l = o.converter('all') + n = l.__class__(copy.copy(l)) if __name__ == "__main__": suite = unittest.makeSuite(ListOptionTestCase, 'test_') diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index ea5d7f65..5636a90d 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -231,9 +231,6 @@ class SpecialAttrWrapper: class CallableComposite(UserList.UserList): """A simple composite callable class that, when called, will invoke all of its contained callables with the same arguments.""" - def __init__(self, seq = []): - UserList.UserList.__init__(self, seq) - def __call__(self, *args, **kwargs): retvals = map(lambda x, args=args, kwargs=kwargs: apply(x, args, @@ -253,9 +250,6 @@ class NodeList(UserList.UserList): >>> someList.strip() [ 'foo', 'bar' ] """ - def __init__(self, seq = []): - UserList.UserList.__init__(self, seq) - def __nonzero__(self): return len(self.data) != 0 diff --git a/test/Copy-Option.py b/test/Copy-Option.py new file mode 100644 index 00000000..505d69b3 --- /dev/null +++ b/test/Copy-Option.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test that setting Options in an Environment doesn't prevent the +Environment from being copied. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +gpib_options = ['NI_GPIB', 'NI_ENET'] +gpib_include = '/' + +#0.96 broke copying ListOptions ??? +opts = Options('config.py', ARGUMENTS) +opts.AddOptions( + BoolOption('gpib', 'enable gpib support', 1), + ListOption('gpib_options', + 'whether and what kind of gpib support shall be enabled', + 'all', + gpib_options), + ) +env = Environment(options = opts, CPPPATH = ['#/']) +new_env=env.Copy() +""") + +test.run(arguments = '.') + +test.pass_test()