From 28c0a793b641e53dc900383db9dca987641069ac Mon Sep 17 00:00:00 2001 From: stevenknight Date: Sat, 8 Oct 2005 14:36:33 +0000 Subject: [PATCH] When deleting a variable from an OverrideEnvironment, do not throw an exception if the underlying Environment does not have a variable we deleted. git-svn-id: http://scons.tigris.org/svn/scons/trunk@1362 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 4 ++++ src/engine/SCons/Environment.py | 12 ++++++++++-- src/engine/SCons/EnvironmentTests.py | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 8fd81cc5..68d1b48a 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -340,6 +340,10 @@ RELEASE 0.97 - XXX - Don't fail when writing signatures if the .sconsign.dblite file is owned by a different user (e.g. root) from a previous run. + - When deleting variables from stacked OverrideEnvironments, don't + throw a KeyError if we were able to delte the variable from any + Environment in the stack. + From Chen Lee: - Handle Visual Studio project and solution files in Unicode. diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 0833f5f1..08e085d6 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -1509,8 +1509,16 @@ class OverrideEnvironment(Base): try: del self.__dict__['overrides'][key] except KeyError: - pass - return self.__dict__['__subject'].__delitem__(key) + deleted = 0 + else: + deleted = 1 + try: + result = self.__dict__['__subject'].__delitem__(key) + except KeyError: + if not deleted: + raise + result = None + return result def get(self, key, default=None): """Emulates the get() method of dictionaries.""" try: diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 55dfb3a8..4b222b87 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -2847,6 +2847,25 @@ class OverrideEnvironmentTestCase(unittest.TestCase): assert env2['YYY'] == 'y', env2['YYY'] assert env3['YYY'] == 'y3', env3['YYY'] + def test___delitem__(self): + """Test deleting variables from an OverrideEnvironment""" + env, env2, env3 = self.envs + + del env3['XXX'] + assert not env.has_key('XXX'), "env has XXX?" + assert not env2.has_key('XXX'), "env2 has XXX?" + assert not env3.has_key('XXX'), "env3 has XXX?" + + del env3['YYY'] + assert not env.has_key('YYY'), "env has YYY?" + assert not env2.has_key('YYY'), "env2 has YYY?" + assert not env3.has_key('YYY'), "env3 has YYY?" + + del env3['ZZZ'] + assert not env.has_key('ZZZ'), "env has ZZZ?" + assert not env2.has_key('ZZZ'), "env2 has ZZZ?" + assert not env3.has_key('ZZZ'), "env3 has ZZZ?" + def test_get(self): """Test the OverrideEnvironment get() method""" env, env2, env3 = self.envs -- 2.26.2