[Zope3-checkins] CVS: Zope3/src/zope/proxy/context/tests - test_wrapper.py:1.2.12.3

Steve Alexander steve@cat-box.net
Mon, 7 Apr 2003 05:46:42 -0400


Update of /cvs-repository/Zope3/src/zope/proxy/context/tests
In directory cvs.zope.org:/tmp/cvs-serv10217/src/zope/proxy/context/tests

Modified Files:
      Tag: stevea-contextaware_in_c-branch
	test_wrapper.py 
Log Message:
Fixed problems with objects pretending to have a __del__ method and also
being involved in cycles.


=== Zope3/src/zope/proxy/context/tests/test_wrapper.py 1.2.12.2 => 1.2.12.3 ===
--- Zope3/src/zope/proxy/context/tests/test_wrapper.py:1.2.12.2	Mon Apr  7 05:31:46 2003
+++ Zope3/src/zope/proxy/context/tests/test_wrapper.py	Mon Apr  7 05:46:41 2003
@@ -133,6 +133,10 @@
                 self.args = None
                 self.retval = retval
             def __getattr__(self, name):
+                if name == '__del__':
+                    # We don't want Python's gc to think that we have a
+                    # __del__, otherwise cycles will not be collected.
+                    raise AttributeError, name
                 self.__dict__['args'] = self, name
                 return self.__dict__['retval']
             def getArgs(self):
@@ -141,15 +145,11 @@
         context = object()
 
         x = X(23)
-        try:
-            p = self.new_proxy(x, context)
-            self.assertEquals(p.foo, 23)
-            # Nothing special happens; we don't rebind the self of __getattr__
-            self.assertEquals(p.getArgs(), (x, 'foo'))
-            self.assert_(p.getArgs()[0] is x)
-        finally:
-            # remove cycles
-            del x.args
+        p = self.new_proxy(x, context)
+        self.assertEquals(p.foo, 23)
+        # Nothing special happens; we don't rebind the self of __getattr__
+        self.assertEquals(p.getArgs(), (x, 'foo'))
+        self.assert_(p.getArgs()[0] is x)
 
     def test_ContextAware_getattr(self):
         class Y(ContextAware):
@@ -157,6 +157,10 @@
                 self.args = None
                 self.retval = retval
             def __getattr__(self, name):
+                if name == '__del__':
+                    # We don't want Python's gc to think that we have a
+                    # __del__, otherwise cycles will not be collected.
+                    raise AttributeError, name
                 self.args = self, name
                 return self.__dict__['retval']
             def getArgs(self):
@@ -166,15 +170,11 @@
                 return getobject(self).__dict__['args']
 
         y = Y(23)
-        try:
-            p = self.new_proxy(y, 23)
-            self.assertEquals(p.foo, 23)
-            # Nothing special happens; we don't rebind the self of __getattr__
-            self.assertEquals(p.getArgs(), (y, 'foo'))
-            self.assert_(p.getArgs()[0] is y)
-        finally:
-            # remove cycles
-            del y.args
+        p = self.new_proxy(y, 23)
+        self.assertEquals(p.foo, 23)
+        # Nothing special happens; we don't rebind the self of __getattr__
+        self.assertEquals(p.getArgs(), (y, 'foo'))
+        self.assert_(p.getArgs()[0] is y)
 
     def test_ContextMethod_getattr(self):
         class Z(object):