Please note the following important changes since release 0.95:
- The behavior of the env.Append() and env.Prepend() methods has
- changed when appending a string value to a UserList. They now
- behave like normal Python addition of a string to a UserList.
- Given an initialization like:
-
- env = Environment(VARIABLE = UserList(['foo']))
-
- An Append() call like:
-
- env.Append(VARIABLE = 'bar')
-
- Will now yield a $VARIABLE value of ['foo', 'b', 'a', 'r'].
- This is because Python UserList objects treat added strings as
- sequences of letters.
-
- The old behavior of yielding a $VARIABLE value of ['foo', 'bar']
- now requires that the appended variable be a list (when the original
- variable is a UserList object):
-
- env.Append(VARIABLE = ['bar'])
-
- Note that the behavior when appending to normal lists has *not*
- changed.
+ changed when appending a string value to a UserList, or vice versa.
+ They now behave like normal Python addition of a string to
+ a UserList. Given an initialization and an env.Append() call like:
+
+ env = Environment(VAR1=UserList(['foo']), VAR2='foo')
+ env.Append(VAR1='bar', VAR2=UserList(['bar'])
+
+ The resulting values of $VAR1 and $VAR2 will now be ['foo', 'b',
+ 'a', 'r'] and ['f', 'o', 'o', 'bar'], respectively. This is because
+ Python UserList objects treat strings as sequences of letters when
+ adding them to the value of the UserList.
+
+ The old behavior of yielding $VAR1 and $VAR2 values of ['foo',
+ 'bar'] when either variable is a UserList object now requires that
+ the string variables be enclosed in a list:
+
+ env = Environment(VAR1=UserList(['foo']), VAR2=['foo'])
+ env.Append(VAR1='bar', VAR2=UserList(['bar']))
+
+ Note that the SCons behavior when appending to normal lists has
+ *not* changed, and the behavior of all of the default values that
+ SCons uses to initialize all construction variables has *not*
+ changed. This change *only* affects any cases where you explicitly
+ use UserList objects to initialize or append to a variable.
Please note the following important changes since release 0.94:
import sys
import TestCmd
import unittest
+import UserList
from SCons.Environment import *
import SCons.Warnings
+class CLVar(UserList.UserList):
+ def __init__(self, seq):
+ if type(seq) == type(''):
+ seq = string.split(seq)
+ UserList.UserList.__init__(self, seq)
+ def __coerce__(self, other):
+ return (self, CLVar(other))
+
+
+
class EnvironmentTestCase(unittest.TestCase):
def test___init__(self):
cases = [
'a1', 'A1', 'a1A1',
'a2', ['A2'], ['a2', 'A2'],
- 'a3', UL(['A3']), UL(['a3', 'A3']),
+ 'a3', UL(['A3']), UL(['a', '3', 'A3']),
'a4', '', 'a4',
'a5', [], ['a5'],
- 'a6', UL([]), UL(['a6']),
+ 'a6', UL([]), UL(['a', '6']),
'a7', [''], ['a7', ''],
- 'a8', UL(['']), UL(['a8', '']),
+ 'a8', UL(['']), UL(['a', '8', '']),
['e1'], 'E1', ['e1', 'E1'],
['e2'], ['E2'], ['e2', 'E2'],
del cases[:3]
assert failed == 0, "%d Append() cases failed" % failed
+ env['UL'] = UL(['foo'])
+ env.Append(UL = 'bar')
+ result = env['UL']
+ assert isinstance(result, UL), repr(result)
+ assert result == ['foo', 'b', 'a', 'r'], result
+
+ env['CLVar'] = CLVar(['foo'])
+ env.Append(CLVar = 'bar')
+ result = env['CLVar']
+ assert isinstance(result, CLVar), repr(result)
+ assert result == ['foo', 'bar'], result
+
class C:
def __init__(self, name):
self.name = name
x = env2.get('XYZ')
assert x == ['-DABC', 'x -DXYZ y', '-DDEF'], x
+ # Ensure that special properties of a class don't get
+ # lost on copying.
+ env1 = Environment(FLAGS = CLVar('flag1 flag2'))
+ x = env1.get('FLAGS')
+ assert x == ['flag1', 'flag2'], x
+ env2 = env1.Copy()
+ env2.Append(FLAGS = 'flag3 flag4')
+ x = env2.get('FLAGS')
+ assert x == ['flag1', 'flag2', 'flag3', 'flag4'], x
+
def test_Detect(self):
"""Test Detect()ing tools"""
test = TestCmd.TestCmd(workdir = '')
cases = [
'a1', 'A1', 'A1a1',
'a2', ['A2'], ['A2', 'a2'],
- 'a3', UL(['A3']), UL(['A3', 'a3']),
+ 'a3', UL(['A3']), UL(['A3', 'a', '3']),
'a4', '', 'a4',
'a5', [], ['a5'],
- 'a6', UL([]), UL(['a6']),
+ 'a6', UL([]), UL(['a', '6']),
'a7', [''], ['', 'a7'],
- 'a8', UL(['']), UL(['', 'a8']),
+ 'a8', UL(['']), UL(['', 'a', '8']),
['e1'], 'E1', ['E1', 'e1'],
['e2'], ['E2'], ['E2', 'e2'],
(repr(input), repr(prepend), repr(result), repr(expect))
failed = failed + 1
del cases[:3]
- assert failed == 0, "%d subst() cases failed" % failed
+ assert failed == 0, "%d Prepend() cases failed" % failed
+
+ env['UL'] = UL(['foo'])
+ env.Prepend(UL = 'bar')
+ result = env['UL']
+ assert isinstance(result, UL), repr(result)
+ assert result == ['b', 'a', 'r', 'foo'], result
+
+ env['CLVar'] = CLVar(['foo'])
+ env.Prepend(CLVar = 'bar')
+ result = env['CLVar']
+ assert isinstance(result, CLVar), repr(result)
+ assert result == ['bar', 'foo'], result
env3 = Environment(X = {'x1' : 7})
env3.Prepend(X = {'x1' : 8, 'x2' : 9}, Y = {'y1' : 10})