[Zope3-checkins] CVS: Zope3/src/zope/proxy/context/tests - test_wrapper.py:1.4
Steve Alexander
steve@cat-box.net
Wed, 9 Apr 2003 08:54:38 -0400
Update of /cvs-repository/Zope3/src/zope/proxy/context/tests
In directory cvs.zope.org:/tmp/cvs-serv29115/src/zope/proxy/context/tests
Modified Files:
test_wrapper.py
Log Message:
Rather than make new types each test run, we make the types once
and cache them in case the same unit test is run multiple times.
=== Zope3/src/zope/proxy/context/tests/test_wrapper.py 1.3 => 1.4 ===
--- Zope3/src/zope/proxy/context/tests/test_wrapper.py:1.3 Tue Apr 8 08:21:39 2003
+++ Zope3/src/zope/proxy/context/tests/test_wrapper.py Wed Apr 9 08:54:38 2003
@@ -21,6 +21,11 @@
_marker = object()
+# We need to make a load of new types. If tests are run multiple times,
+# only make each required new type once, and cache it here.
+# Otherwise, it looks like we have a refcount leak.
+class_lookup = {}
+
class WrapperTestCase(ProxyTestCase):
def new_proxy(self, o, c=None):
return wrapper.Wrapper(o, c)
@@ -93,19 +98,28 @@
else:
return fixed_retval
- # context-unaware object
- t1 = type('ContextUnawareObj', (), {slot: doit})
- proxy1 = self.new_proxy(t1(), context)
-
- # context-aware object
- t2 = type('ContextAwareObj', (ContextAware,), {slot: doit})
- proxy2 = self.new_proxy(t2(), context)
-
- # object with context method
- t3 = type('ContextMethodObj', (), {slot: ContextMethod(doit)})
- proxy3 = self.new_proxy(t3(), context)
+ if slot in class_lookup:
+ # The unit test for this slot has been run before.
+ # Return the types we previously made.
+ return class_lookup[slot]
+ else:
+ # This is the first time the unit-test for this slot has been
+ # run. Make some new types, and cache them.
+
+ # context-unaware object
+ t1 = type('ContextUnawareObj', (), {slot: doit})
+ proxy1 = self.new_proxy(t1(), context)
+
+ # context-aware object
+ t2 = type('ContextAwareObj', (ContextAware,), {slot: doit})
+ proxy2 = self.new_proxy(t2(), context)
+
+ # object with context method
+ t3 = type('ContextMethodObj', (), {slot: ContextMethod(doit)})
+ proxy3 = self.new_proxy(t3(), context)
- return proxy1, proxy2, proxy3, context
+ class_lookup[slot] = retval = proxy1, proxy2, proxy3, context
+ return retval
def test_normal_getattr(self):
class X(object):