def test_proxyName(self):
     """
     The name of a proxy class indicates which interface it proxies.
     """
     proxy = proxyForInterface(IProxiedInterface)
     self.assertEquals(
         proxy.__name__, "(Proxy for "
         "twisted.python.test.test_components.IProxiedInterface)")
 def test_original(self):
     """
     Proxy objects should have an C{original} attribute which refers to the
     original object passed to the constructor.
     """
     original = object()
     proxy = proxyForInterface(IProxiedInterface)(original)
     self.assertIdentical(proxy.original, original)
 def test_original(self):
     """
     Proxy objects should have an C{original} attribute which refers to the
     original object passed to the constructor.
     """
     original = object()
     proxy = proxyForInterface(IProxiedInterface)(original)
     self.assertIdentical(proxy.original, original)
 def test_multipleMethods(self):
     """
     [Regression test] The proxy should send its method calls to the correct
     method, not the incorrect one.
     """
     multi = MultipleMethodImplementor()
     proxy = proxyForInterface(IMultipleMethods)(multi)
     self.assertEquals(proxy.methodOne(), 1)
     self.assertEquals(proxy.methodTwo(), 2)
 class SpecializedProxy(proxyForInterface(IProxiedInterface)):
     """
     A specialized proxy which can decrement the number of yays.
     """
     def boo(self):
         """
         Decrement the number of yays.
         """
         self.original.yays -= 1
 def test_proxyName(self):
     """
     The name of a proxy class indicates which interface it proxies.
     """
     proxy = proxyForInterface(IProxiedInterface)
     self.assertEquals(
         proxy.__name__,
         "(Proxy for "
         "twisted.python.test.test_components.IProxiedInterface)")
 def test_multipleMethods(self):
     """
     [Regression test] The proxy should send its method calls to the correct
     method, not the incorrect one.
     """
     multi = MultipleMethodImplementor()
     proxy = proxyForInterface(IMultipleMethods)(multi)
     self.assertEquals(proxy.methodOne(), 1)
     self.assertEquals(proxy.methodTwo(), 2)
 def test_proxySetAttribute(self):
     """
     The attributes that proxy objects proxy should be assignable and affect
     the original object.
     """
     yayable = Yayable()
     proxy = proxyForInterface(IProxiedInterface)(yayable)
     thingy = object()
     proxy.ifaceAttribute = thingy
     self.assertIdentical(yayable.ifaceAttribute, thingy)
 def test_proxyAttribute(self):
     """
     Proxy objects should proxy declared attributes, but not other
     attributes.
     """
     yayable = Yayable()
     yayable.ifaceAttribute = object()
     proxy = proxyForInterface(IProxiedInterface)(yayable)
     self.assertIdentical(proxy.ifaceAttribute, yayable.ifaceAttribute)
     self.assertRaises(AttributeError, lambda: proxy.yays)
 def test_proxyDeleteAttribute(self):
     """
     The attributes that proxy objects proxy should be deletable and affect
     the original object.
     """
     yayable = Yayable()
     yayable.ifaceAttribute = None
     proxy = proxyForInterface(IProxiedInterface)(yayable)
     del proxy.ifaceAttribute
     self.assertFalse(hasattr(yayable, 'ifaceAttribute'))
 def test_proxySetAttribute(self):
     """
     The attributes that proxy objects proxy should be assignable and affect
     the original object.
     """
     yayable = Yayable()
     proxy = proxyForInterface(IProxiedInterface)(yayable)
     thingy = object()
     proxy.ifaceAttribute = thingy
     self.assertIdentical(yayable.ifaceAttribute, thingy)
 def test_proxyAttribute(self):
     """
     Proxy objects should proxy declared attributes, but not other
     attributes.
     """
     yayable = Yayable()
     yayable.ifaceAttribute = object()
     proxy = proxyForInterface(IProxiedInterface)(yayable)
     self.assertIdentical(proxy.ifaceAttribute, yayable.ifaceAttribute)
     self.assertRaises(AttributeError, lambda: proxy.yays)
 def test_proxyDeleteAttribute(self):
     """
     The attributes that proxy objects proxy should be deletable and affect
     the original object.
     """
     yayable = Yayable()
     yayable.ifaceAttribute = None
     proxy = proxyForInterface(IProxiedInterface)(yayable)
     del proxy.ifaceAttribute
     self.assertFalse(hasattr(yayable, 'ifaceAttribute'))
 def test_proxyMethod(self):
     """
     The class created from L{proxyForInterface} passes methods on an
     interface to the object which is passed to its constructor.
     """
     klass = proxyForInterface(IProxiedInterface)
     yayable = Yayable()
     proxy = klass(yayable)
     proxy.yay()
     self.assertEquals(proxy.yay(), 2)
     self.assertEquals(yayable.yays, 2)
 def test_proxyMethod(self):
     """
     The class created from L{proxyForInterface} passes methods on an
     interface to the object which is passed to its constructor.
     """
     klass = proxyForInterface(IProxiedInterface)
     yayable = Yayable()
     proxy = klass(yayable)
     proxy.yay()
     self.assertEquals(proxy.yay(), 2)
     self.assertEquals(yayable.yays, 2)
 def test_interfaceInheritance(self):
     """
     Proxies of subinterfaces generated with proxyForInterface should allow
     access to attributes of both the child and the base interfaces.
     """
     proxyClass = proxyForInterface(IProxiedSubInterface)
     booable = Booable()
     proxy = proxyClass(booable)
     proxy.yay()
     proxy.boo()
     self.failUnless(booable.yayed)
     self.failUnless(booable.booed)
 def test_interfaceInheritance(self):
     """
     Proxies of subinterfaces generated with proxyForInterface should allow
     access to attributes of both the child and the base interfaces.
     """
     proxyClass = proxyForInterface(IProxiedSubInterface)
     booable = Booable()
     proxy = proxyClass(booable)
     proxy.yay()
     proxy.boo()
     self.failUnless(booable.yayed)
     self.failUnless(booable.booed)
    def test_attributeCustomization(self):
        """
        The original attribute name can be customized via the
        C{originalAttribute} argument of L{proxyForInterface}: the attribute
        should change, but the methods of the original object should still be
        callable, and the attributes still accessible.
        """
        yayable = Yayable()
        yayable.ifaceAttribute = object()
        proxy = proxyForInterface(IProxiedInterface,
                                  originalAttribute='foo')(yayable)
        self.assertIdentical(proxy.foo, yayable)

        # Check the behavior
        self.assertEquals(proxy.yay(), 1)
        self.assertIdentical(proxy.ifaceAttribute, yayable.ifaceAttribute)
        thingy = object()
        proxy.ifaceAttribute = thingy
        self.assertIdentical(yayable.ifaceAttribute, thingy)
        del proxy.ifaceAttribute
        self.assertFalse(hasattr(yayable, 'ifaceAttribute'))
    def test_attributeCustomization(self):
        """
        The original attribute name can be customized via the
        C{originalAttribute} argument of L{proxyForInterface}: the attribute
        should change, but the methods of the original object should still be
        callable, and the attributes still accessible.
        """
        yayable = Yayable()
        yayable.ifaceAttribute = object()
        proxy = proxyForInterface(
            IProxiedInterface, originalAttribute='foo')(yayable)
        self.assertIdentical(proxy.foo, yayable)

        # Check the behavior
        self.assertEquals(proxy.yay(), 1)
        self.assertIdentical(proxy.ifaceAttribute, yayable.ifaceAttribute)
        thingy = object()
        proxy.ifaceAttribute = thingy
        self.assertIdentical(yayable.ifaceAttribute, thingy)
        del proxy.ifaceAttribute
        self.assertFalse(hasattr(yayable, 'ifaceAttribute'))
 class YayableWrapper(proxyForInterface(IProxiedInterface)):
     """
 def test_implements(self):
     """
     The resulting proxy implements the interface that it proxies.
     """
     proxy = proxyForInterface(IProxiedInterface)
     self.assertTrue(IProxiedInterface.implementedBy(proxy))
 def test_implements(self):
     """
     The resulting proxy implements the interface that it proxies.
     """
     proxy = proxyForInterface(IProxiedInterface)
     self.assertTrue(IProxiedInterface.implementedBy(proxy))