Fix env.Copy() stack trace.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 21 Aug 2004 14:32:17 +0000 (14:32 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 21 Aug 2004 14:32:17 +0000 (14:32 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1046 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Options/ListOption.py
src/engine/SCons/Options/ListOptionTests.py
src/engine/SCons/Util.py
test/Copy-Option.py [new file with mode: 0644]

index 20b7e99f7ecd1fd5c5118b17a17ae8929916ce94..eade37429e5ebb52fff04e4a6ff4ece95d528fdf 100644 (file)
@@ -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):
index 2175720233417c70703bedbb36c454389312477a..0c7cc8eb50790dcd50694ed15d3009c16d87462e 100644 (file)
@@ -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_')
index ea5d7f65c3ffad03c5a5e93c8c4a14804867dd38..5636a90d6d894ac08aa8fe9677667b45d439522a 100644 (file)
@@ -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 (file)
index 0000000..505d69b
--- /dev/null
@@ -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()