Esempio 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)")
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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
Esempio 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)")
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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'))
Esempio 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)
Esempio 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)
Esempio 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'))
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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'))
Esempio 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'))
Esempio n. 20
0
 class YayableWrapper(proxyForInterface(IProxiedInterface)):
     """
Esempio n. 21
0
 def test_implements(self):
     """
     The resulting proxy implements the interface that it proxies.
     """
     proxy = proxyForInterface(IProxiedInterface)
     self.assertTrue(IProxiedInterface.implementedBy(proxy))
Esempio n. 22
0
 def test_implements(self):
     """
     The resulting proxy implements the interface that it proxies.
     """
     proxy = proxyForInterface(IProxiedInterface)
     self.assertTrue(IProxiedInterface.implementedBy(proxy))