def test_transportInterfaces(self): """ The transport wrapper passed to the wrapped protocol's C{makeConnection} provides the same interfaces as are provided by the original transport. """ class IStubTransport(Interface): pass @implementer(IStubTransport) class StubTransport: pass # Looking up what ProtocolWrapper implements also mutates the class. # It adds __implemented__ and __providedBy__ attributes to it. These # prevent __getattr__ from causing the IStubTransport.providedBy call # below from returning True. If, by accident, nothing else causes # these attributes to be added to ProtocolWrapper, the test will pass, # but the interface will only be provided until something does trigger # their addition. So we just trigger it right now to be sure. implementedBy(policies.ProtocolWrapper) proto = protocol.Protocol() wrapper = policies.ProtocolWrapper(policies.WrappingFactory(None), proto) wrapper.makeConnection(StubTransport()) self.assertTrue(IStubTransport.providedBy(proto.transport))
def _getWrapper(self): """ Return L{policies.ProtocolWrapper} that has been connected to a L{StringTransport}. """ wrapper = policies.ProtocolWrapper(policies.WrappingFactory(Server()), protocol.Protocol()) transport = StringTransport() wrapper.makeConnection(transport) return wrapper
def test_breakReferenceCycle(self): """ L{policies.ProtocolWrapper.connectionLost} sets C{wrappedProtocol} to C{None} in order to break reference cycle between wrapper and wrapped protocols. :return: """ wrapper = policies.ProtocolWrapper(policies.WrappingFactory(Server()), protocol.Protocol()) transport = StringTransportWithDisconnection() transport.protocol = wrapper wrapper.makeConnection(transport) self.assertIsNotNone(wrapper.wrappedProtocol) transport.loseConnection() self.assertIsNone(wrapper.wrappedProtocol)