[Zope3-checkins] CVS: Zope3/src/zope/app/component/tests - test_wrapper_hooks.py:1.1.2.7

Steve Alexander steve@cat-box.net
Fri, 16 May 2003 12:19:10 -0400


Update of /cvs-repository/Zope3/src/zope/app/component/tests
In directory cvs.zope.org:/tmp/cvs-serv2621/src/zope/app/component/tests

Modified Files:
      Tag: stevea-decorators-branch
	test_wrapper_hooks.py 
Log Message:
All unit tests now pass.
Added an ensureContextWrapped function to zope.proxy.context.

In code that uses context wrapping, we have two situations:

  * Code such as traversal code wants to ensure that there is a context-
    wrapper, and set the parent and items in the context dict.
    If there is no context wrapper, it should create one, but if there
    is one already, it should be preserved.

  * Code that is the primary source of some information, and wants to
    wrap it and add minimal information (name, usually) before allowing
    the world to see the information. The zopecontainerdecorator is an
    example of this.

To resolve these situations, the former code should use
ensureContextWrapped, which keeps an existing context wrapper if possible,
and updates the context and adds/overwrites items in the context dict.
The latter code can continue to use ContextWrapper.



=== Zope3/src/zope/app/component/tests/test_wrapper_hooks.py 1.1.2.6 => 1.1.2.7 ===
--- Zope3/src/zope/app/component/tests/test_wrapper_hooks.py:1.1.2.6	Fri May 16 09:52:18 2003
+++ Zope3/src/zope/app/component/tests/test_wrapper_hooks.py	Fri May 16 12:18:39 2003
@@ -84,6 +84,12 @@
         self.decoratedTearDown()
         unittest.TestCase.tearDown(self)
 
+    def test_decoratingDecorators(self):
+        from zope.app.component.hooks import decorate
+        d = Decorator(1, 2)
+        spec = DecoratorSpecStub(True, Mixin, None, (), {}, {})
+        self.assertRaises(TypeError, decorate, spec, d, None)
+
     def test_decorate(self):
         from zope.app.component.hooks import decorate
 
@@ -176,8 +182,8 @@
                      SomeOtherObject.__Security_checker__)
         self.assert_(d.__Security_checker__ is not None)
 
-        # a decorated proxy should be another decorated proxy, with a
-        # combined checker
+        # A decorated proxy should be another decorated proxy, with a
+        # combined checker.
         d = decorate(spec, proxied_ob, parent, kw)
         self.assert_(type(d) is Proxy)
         self.checkingTestImpl(self.originalChecker, getChecker(d))