Follow-on to Append() functionality: generalize the type tests.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 6 May 2002 21:58:02 +0000 (21:58 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 6 May 2002 21:58:02 +0000 (21:58 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@365 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Environment.py
src/engine/SCons/EnvironmentTests.py

index 432c394ecbbf43f14c192fce994584770b896fa6..c5f34070ed8d9bcaf57aeb92e265ec596ba20afe 100644 (file)
@@ -201,16 +201,14 @@ class Environment:
         for key in kw.keys():
             if not self._dict.has_key(key):
                 self._dict[key] = kw[key]
-            elif type(self._dict[key]) is type(kw[key]):
-                self._dict[key] = self._dict[key] + kw[key]
+            elif SCons.Util.is_List(self._dict[key]) and not \
+                 SCons.Util.is_List(kw[key]):
+                self._dict[key] = self._dict[key] + [ kw[key] ]
+            elif SCons.Util.is_List(kw[key]) and not \
+                 SCons.Util.is_List(self._dict[key]):
+                self._dict[key] = [ self._dict[key] ] + kw[key]
             else:
-                l1 = self._dict[key]
-                if not SCons.Util.is_List(l1):
-                    l1 = [l1]
-                l2 = kw[key]
-                if not SCons.Util.is_List(l2):
-                    l2 = [l2]
-                self._dict[key] = l1 + l2
+                self._dict[key] = self._dict[key] + kw[key]
 
     def        Depends(self, target, dependency):
        """Explicity specify that 'target's depend on 'dependency'."""
index d1c5aa8b818ac32345d565bc71ac485d0313514b..f16632da9bd86ac0e8856fd0ab591d42313c0735 100644 (file)
@@ -253,14 +253,30 @@ class EnvironmentTestCase(unittest.TestCase):
     def test_Append(self):
         """Test appending to construction variables in an Environment
         """
-        env1 = Environment(AAA = 'a', BBB = 'b', CCC = 'c',
-                           DDD = ['d'], EEE = ['e'], FFF = ['f'])
-        env1.Append(BBB = 'B', CCC = ['C'], EEE = 'E', FFF = ['F'],
-                    GGG = 'g', HHH = ['h'])
-        env2 = Environment(AAA = 'a', BBB = 'bB', CCC = ['c', 'C'],
-                           DDD = ['d'], EEE = ['e', 'E'], FFF = ['f', 'F'],
-                           GGG = 'g', HHH = ['h'])
-        assert env1 == env2
+        import UserList
+        UL = UserList.UserList
+        env1 = Environment(AAA = 'a', BBB = 'b', CCC = 'c', DDD = 'd',
+                           EEE = ['e'], FFF = ['f'], GGG = ['g'], HHH = ['h'],
+                           III = UL(['i']), JJJ = UL(['j']),
+                           KKK = UL(['k']), LLL = UL(['l']))
+        env1.Append(BBB = 'B', CCC = ['C'], DDD = UL(['D']),
+                    FFF = 'F', GGG = ['G'], HHH = UL(['H']),
+                    JJJ = 'J', KKK = ['K'], LLL = UL(['L']))
+        env2 = Environment(AAA = 'a', BBB = 'bB',
+                           CCC = ['c', 'C'], DDD = UL(['d', 'D']),
+                           EEE = ['e'], FFF = ['f', 'F'],
+                           GGG = ['g', 'G'], HHH = UL(['h', 'H']),
+                           III = UL(['i']), JJJ = UL(['j', 'J']),
+                           KKK = UL(['k', 'K']), LLL = UL(['l', 'L']))
+        assert env1 == env2, env1._dict
+
+        env3 = Environment(X = {'x' : 7})
+        try:
+            env3.Append(X = {'x' : 8})
+        except TypeError:
+            pass
+        except:
+            raise
 
     def test_Depends(self):
        """Test the explicit Depends method."""