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

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


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

Modified Files:
      Tag: stevea-contextaware_in_c-branch
	test_wrapper.py 
Log Message:
Made the making of different context-aware (or otherwise) classes more
elegant.


=== Zope3/src/zope/proxy/context/tests/test_wrapper.py 1.2.12.3 => 1.2.12.4 ===
--- Zope3/src/zope/proxy/context/tests/test_wrapper.py:1.2.12.3	Mon Apr  7 05:46:41 2003
+++ Zope3/src/zope/proxy/context/tests/test_wrapper.py	Mon Apr  7 05:51:00 2003
@@ -86,44 +86,24 @@
     def make_proxies(self, slot, fixed_retval=_marker):
         context = object()
 
-        #
-        # XXX: redo it using type as a constructor and setting just the
-        # appropriate slot
-        #
+        def doit(self, *args):
+            self.retval = getcontext(self), args
+            if fixed_retval is _marker:
+                return self.retval
+            else:
+                return fixed_retval
 
         # context-unaware object
-        class ContextUnawareObj(object):
-            def doit(self, *args):
-                self.retval = getcontext(self), args
-                if fixed_retval is _marker:
-                    return self.retval
-                else:
-                    return fixed_retval
-        setattr(ContextUnawareObj, slot, ContextUnawareObj.doit)
-        proxy1 = self.new_proxy(ContextUnawareObj(), context)
+        t1 = type('ContextUnawareObj', (), {slot: doit})
+        proxy1 = self.new_proxy(t1(), context)
 
         # context-aware object
-        class ContextAwareObj(ContextAware):
-            def doit(self, *args):
-                self.retval = getcontext(self), args
-                if fixed_retval is _marker:
-                    return self.retval
-                else:
-                    return fixed_retval
-        setattr(ContextAwareObj, slot, ContextAwareObj.doit)
-        proxy2 = self.new_proxy(ContextAwareObj(), context)
+        t2 = type('ContextAwareObj', (ContextAware,), {slot: doit})
+        proxy2 = self.new_proxy(t2(), context)
 
         # object with context method
-        class ContextMethodObj(object):
-            def doit(self, *args):
-                self.retval = getcontext(self), args
-                if fixed_retval is _marker:
-                    return self.retval
-                else:
-                    return fixed_retval
-            doit = ContextMethod(doit)
-        setattr(ContextMethodObj, slot, ContextMethodObj.doit)
-        proxy3 = self.new_proxy(ContextMethodObj(), context)
+        t3 = type('ContextMethodObj', (), {slot: ContextMethod(doit)})
+        proxy3 = self.new_proxy(t3(), context)
 
         return proxy1, proxy2, proxy3, context