Issue 2176: BuilderWrapper __getattr__ should not raise KeyError
authorpankrat <pankrat@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 5 Sep 2008 16:28:48 +0000 (16:28 +0000)
committerpankrat <pankrat@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 5 Sep 2008 16:28:48 +0000 (16:28 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@3341 fdb21ef1-2011-0410-befe-b5e4ea1792b1

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

index 67881eb3d9afcabbe63b9006ebacae16258ecaba..1a4f5f567526341a848c7b09843a9a214c9cec3e 100644 (file)
@@ -230,7 +230,7 @@ class BuilderWrapper(MethodWrapper):
         elif name == 'builder':
             return self.method
         else:
-            return self.__dict__[name]
+            raise AttributeError, name
 
     def __setattr__(self, name, value):
         if name == 'env':
index 7e6d4ca165606362f7b168fc182420449df8b909..01e7e0696765ce1f38726fa44102f6ac8299a0d7 100644 (file)
@@ -916,7 +916,28 @@ class BaseTestCase(unittest.TestCase,TestEnvironmentFixture):
         assert called_it['target'] == None, called_it
         assert called_it['source'] == None, called_it
 
+    def test_BuilderWrapper_attributes(self):
+        """Test getting and setting of BuilderWrapper attributes
+        """
+        b1 = Builder()
+        b2 = Builder()
+        e1 = Environment()
+        e2 = Environment()
+
+        e1.Replace(BUILDERS = {'b' : b1})
+        bw = e1.b
+
+        assert bw.env is e1
+        bw.env = e2
+        assert bw.env is e2
+
+        assert bw.builder is b1
+        bw.builder = b2
+        assert bw.builder is b2
 
+        self.assertRaises(AttributeError, getattr, bw, 'foobar')
+        bw.foobar = 42
+        assert bw.foobar is 42
 
     # This unit test is currently disabled because we don't think the
     # underlying method it tests (Environment.BuilderWrapper.execute())