[Zope3-checkins] CVS: Zope3/src/zope/proxy/tests - test_proxy.py:1.7

Steve Alexander steve@cat-box.net
Fri, 9 May 2003 10:02:57 -0400


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

Modified Files:
	test_proxy.py 
Log Message:
More development of decorators.
Found a memory leak in Python 2.2.2 and the 2.2 maintenance branch.
This leak is demonstrated in zope.proxy.tests.test_proxy test_leak.
The leak is not apparrent in Python 2.3 from CVS.


=== Zope3/src/zope/proxy/tests/test_proxy.py 1.6 => 1.7 ===
--- Zope3/src/zope/proxy/tests/test_proxy.py:1.6	Thu May  8 05:40:11 2003
+++ Zope3/src/zope/proxy/tests/test_proxy.py	Fri May  9 10:02:56 2003
@@ -73,7 +73,36 @@
         self.assertRaises(TypeError, self.proxy_class, o, key='value')
         self.assertRaises(TypeError, self.proxy_class, key='value')
 
+    def test_leak(self):
+        # XXX Leaky. This is the same leak as in test_subclass_constructor,
+        #     but isolated to depend only on code in Python 2.2.2.
+        #     It still leaks on the release22-maint branch, but not with
+        #     Python 2.3 from CVS HEAD.
+        class SomeClass(object):
+            def somemethod():
+                # XXX The next line produces the following leak:
+                #
+                # totalrefcount=233207   change=32
+                # <type 'tuple'>                3       12
+                # <type 'type'>                 1        7
+                # <type 'dict'>                 1        5
+                # <type 'staticmethod'>         1        4
+                # <type 'function'>             1        4
+                # <type 'getset_descriptor'>    1        4
+                # <type 'member_descriptor'>    1        4
+                # <type 'cell'>                 1        4
+                # <type 'weakref'>              1        4
+                # <type 'str'>                  0       10
+                # <type 'class'>                0        1
+                # <type 'code'>                 0        1
+
+                super(SomeClass, None)
+            somemethod = staticmethod(somemethod)
+        SomeClass.somemethod()
+
     def test_subclass_constructor(self):
+        # NB This leaks due to a bug in Python 2.2.2.
+        #    See test_leak, above.
         class MyProxy(self.proxy_class):
             def __new__(cls, *args, **kwds):
                 return super(MyProxy, cls).__new__(cls, *args, **kwds)
@@ -82,6 +111,7 @@
         o1 = object()
         o2 = object()
         o = MyProxy((o1, o2))
+
         self.assertEquals(o1, o[0])
         self.assertEquals(o2, o[1])