Ejemplo n.º 1
0
 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)")
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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)")
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
 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'))
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
0
 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'))
Ejemplo n.º 14
0
 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)
Ejemplo n.º 15
0
 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)
Ejemplo n.º 16
0
 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)
Ejemplo n.º 17
0
 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)
Ejemplo n.º 18
0
    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'))
Ejemplo n.º 19
0
    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'))
Ejemplo n.º 20
0
 class YayableWrapper(proxyForInterface(IProxiedInterface)):
     """
Ejemplo n.º 21
0
 def test_implements(self):
     """
     The resulting proxy implements the interface that it proxies.
     """
     proxy = proxyForInterface(IProxiedInterface)
     self.assertTrue(IProxiedInterface.implementedBy(proxy))
Ejemplo n.º 22
0
 def test_implements(self):
     """
     The resulting proxy implements the interface that it proxies.
     """
     proxy = proxyForInterface(IProxiedInterface)
     self.assertTrue(IProxiedInterface.implementedBy(proxy))