本文整理汇总了Python中twisted.test.proto_helpers.MemoryReactor方法的典型用法代码示例。如果您正苦于以下问题:Python proto_helpers.MemoryReactor方法的具体用法?Python proto_helpers.MemoryReactor怎么用?Python proto_helpers.MemoryReactor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.test.proto_helpers
的用法示例。
在下文中一共展示了proto_helpers.MemoryReactor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getChild
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def test_getChild(self):
"""
The L{ReverseProxyResource.getChild} method should return a resource
instance with the same class as the originating resource, forward
port, host, and reactor values, and update the path value with the
value passed.
"""
reactor = MemoryReactor()
resource = ReverseProxyResource(u"127.0.0.1", 1234, b"/path", reactor)
child = resource.getChild(b'foo', None)
# The child should keep the same class
self.assertIsInstance(child, ReverseProxyResource)
self.assertEqual(child.path, b"/path/foo")
self.assertEqual(child.port, 1234)
self.assertEqual(child.host, u"127.0.0.1")
self.assertIdentical(child.reactor, resource.reactor)
示例2: test_process
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def test_process(self):
"""
L{ReverseProxyRequest.process} should create a connection to its
factory host/port, using a L{ProxyClientFactory} instantiated with the
correct parameters, and particularly set the B{host} header to the
factory host.
"""
transport = StringTransportWithDisconnection()
channel = DummyChannel(transport)
reactor = MemoryReactor()
request = ReverseProxyRequest(channel, False, reactor)
request.factory = DummyFactory(u"example.com", 1234)
request.gotLength(0)
request.requestReceived(b'GET', b'/foo/bar', b'HTTP/1.0')
# Check that one connection has been created, to the good host/port
self.assertEqual(len(reactor.tcpClients), 1)
self.assertEqual(reactor.tcpClients[0][0], u"example.com")
self.assertEqual(reactor.tcpClients[0][1], 1234)
# Check the factory passed to the connect, and its headers
factory = reactor.tcpClients[0][2]
self.assertIsInstance(factory, ProxyClientFactory)
self.assertEqual(factory.headers, {b'host': b'example.com'})
示例3: patchInstallReactor
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def patchInstallReactor(self):
"""
Patch C{_options.installReactor} so we can capture usage and prevent
actual installs.
"""
self.installedReactors = {}
def installReactor(name):
if name != "fusion":
raise NoSuchReactor()
reactor = MemoryReactor()
self.installedReactors[name] = reactor
return reactor
self.patch(_options, "installReactor", installReactor)
示例4: onePrefix
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def onePrefix(self, description, expectedClass):
"""
Test the C{haproxy} enpdoint prefix against one sub-endpoint type.
@param description: A string endpoint description beginning with
C{haproxy}.
@type description: native L{str}
@param expectedClass: the expected sub-endpoint class given the
description.
@type expectedClass: L{type}
@return: the parsed endpoint
@rtype: L{IStreamServerEndpoint}
@raise twisted.trial.unittest.Failtest: if the parsed endpoint doesn't
match expectations.
"""
reactor = MemoryReactor()
endpoint = serverFromString(reactor, description)
self.assertIsInstance(endpoint, _WrapperServerEndpoint)
self.assertIsInstance(endpoint._wrappedEndpoint, expectedClass)
self.assertIs(endpoint._wrapperFactory, HAProxyWrappingFactory)
return endpoint
示例5: test_cancelAfterConnectionMade
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def test_cancelAfterConnectionMade(self):
"""
When a user cancels L{twisted.mail.smtp.sendmail} after the connection
is made, the connection is closed by
L{twisted.internet.interfaces.ITransport.abortConnection}.
"""
reactor = MemoryReactor()
transport = AbortableStringTransport()
d = smtp.sendmail("localhost", "source@address", "recipient@address",
"message", reactor=reactor)
factory = reactor.tcpClients[0][2]
p = factory.buildProtocol(None)
p.makeConnection(transport)
d.cancel()
self.assertEqual(transport.aborting, True)
self.assertEqual(transport.disconnecting, True)
failure = self.failureResultOf(d)
failure.trap(defer.CancelledError)
示例6: test_singleTCPQueryErrbackOnConnectionFailure
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def test_singleTCPQueryErrbackOnConnectionFailure(self):
"""
The deferred returned by L{client.Resolver.queryTCP} will
errback when the TCP connection attempt fails. The reason for
the connection failure is passed as the argument to errback.
"""
reactor = proto_helpers.MemoryReactor()
resolver = client.Resolver(
servers=[('192.0.2.100', 53)],
reactor=reactor)
d = resolver.queryTCP(dns.Query('example.com'))
host, port, factory, timeout, bindAddress = reactor.tcpClients[0]
class SentinelException(Exception):
pass
factory.clientConnectionFailed(
reactor.connectors[0], failure.Failure(SentinelException()))
self.failureResultOf(d, SentinelException)
示例7: test_multipleTCPQueryErrbackOnConnectionFailure
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def test_multipleTCPQueryErrbackOnConnectionFailure(self):
"""
All pending L{resolver.queryTCP} C{deferred}s will C{errback}
with the same C{Failure} if the connection attempt fails.
"""
reactor = proto_helpers.MemoryReactor()
resolver = client.Resolver(
servers=[('192.0.2.100', 53)],
reactor=reactor)
d1 = resolver.queryTCP(dns.Query('example.com'))
d2 = resolver.queryTCP(dns.Query('example.net'))
host, port, factory, timeout, bindAddress = reactor.tcpClients[0]
class SentinelException(Exception):
pass
factory.clientConnectionFailed(
reactor.connectors[0], failure.Failure(SentinelException()))
f1 = self.failureResultOf(d1, SentinelException)
f2 = self.failureResultOf(d2, SentinelException)
self.assertIs(f1, f2)
示例8: test_reactorParametrizationInClientMultipleStart
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def test_reactorParametrizationInClientMultipleStart(self):
"""
Like L{test_reactorParametrizationInClient}, but stop and restart the
service and check that the given reactor is still used.
"""
reactor = MemoryReactor()
factory = protocol.ClientFactory()
t = internet.TCPClient('127.0.0.1', 1234, factory, reactor=reactor)
t.startService()
self.assertEqual(
reactor.tcpClients.pop()[:3], ('127.0.0.1', 1234, factory))
t.stopService()
t.startService()
self.assertEqual(
reactor.tcpClients.pop()[:3], ('127.0.0.1', 1234, factory))
示例9: build_control_amp_service
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def build_control_amp_service(test_case, reactor=None):
"""
Create a new ``ControlAMPService``.
:param TestCase test_case: The test this service is for.
:return ControlAMPService: Not started.
"""
if reactor is None:
reactor = Clock()
cluster_state = ClusterStateService(reactor)
cluster_state.startService()
test_case.addCleanup(cluster_state.stopService)
persistence_service = ConfigurationPersistenceService(
reactor, test_case.make_temporary_directory())
persistence_service.startService()
test_case.addCleanup(persistence_service.stopService)
return ControlAMPService(
reactor, cluster_state, persistence_service,
TCP4ServerEndpoint(MemoryReactor(), 1234),
# Easiest TLS context factory to create:
ClientContextFactory(),
)
示例10: test_cancelAfterConnectionMade
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def test_cancelAfterConnectionMade(self):
"""
When a user cancels L{twisted.mail.smtp.sendmail} after the connection
is made, the connection is closed by
L{twisted.internet.interfaces.ITransport.abortConnection}.
"""
reactor = MemoryReactor()
transport = AbortableStringTransport()
d = smtp.sendmail("localhost", "source@address", "recipient@address",
b"message", reactor=reactor)
factory = reactor.tcpClients[0][2]
p = factory.buildProtocol(None)
p.makeConnection(transport)
d.cancel()
self.assertEqual(transport.aborting, True)
self.assertEqual(transport.disconnecting, True)
failure = self.failureResultOf(d)
failure.trap(defer.CancelledError)
示例11: test_getChild
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def test_getChild(self):
"""
The L{ReverseProxyResource.getChild} method should return a resource
instance with the same class as the originating resource, forward
port, host, and reactor values, and update the path value with the
value passed.
"""
reactor = MemoryReactor()
resource = ReverseProxyResource("127.0.0.1", 1234, "/path", reactor)
child = resource.getChild('foo', None)
# The child should keep the same class
self.assertIsInstance(child, ReverseProxyResource)
self.assertEquals(child.path, "/path/foo")
self.assertEquals(child.port, 1234)
self.assertEquals(child.host, "127.0.0.1")
self.assertIdentical(child.reactor, resource.reactor)
示例12: test_processWithPort
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def test_processWithPort(self):
"""
Check that L{ProxyRequest.process} correctly parse port in the incoming
URL, and create a outgoing connection with this port.
"""
transport = StringTransportWithDisconnection()
channel = DummyChannel(transport)
reactor = MemoryReactor()
request = ProxyRequest(channel, False, reactor)
request.gotLength(0)
request.requestReceived('GET', 'http://example.com:1234/foo/bar',
'HTTP/1.0')
# That should create one connection, with the port parsed from the URL
self.assertEquals(len(reactor.tcpClients), 1)
self.assertEquals(reactor.tcpClients[0][0], "example.com")
self.assertEquals(reactor.tcpClients[0][1], 1234)
示例13: test_process
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def test_process(self):
"""
L{ReverseProxyRequest.process} should create a connection to its
factory host/port, using a L{ProxyClientFactory} instantiated with the
correct parameters, and particulary set the B{host} header to the
factory host.
"""
transport = StringTransportWithDisconnection()
channel = DummyChannel(transport)
reactor = MemoryReactor()
request = ReverseProxyRequest(channel, False, reactor)
request.factory = DummyFactory("example.com", 1234)
request.gotLength(0)
request.requestReceived('GET', '/foo/bar', 'HTTP/1.0')
# Check that one connection has been created, to the good host/port
self.assertEquals(len(reactor.tcpClients), 1)
self.assertEquals(reactor.tcpClients[0][0], "example.com")
self.assertEquals(reactor.tcpClients[0][1], 1234)
# Check the factory passed to the connect, and its headers
factory = reactor.tcpClients[0][2]
self.assertIsInstance(factory, ProxyClientFactory)
self.assertEquals(factory.headers, {'host': 'example.com'})
示例14: test_endpointListenSuccess
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def test_endpointListenSuccess(self):
"""
An endpoint can listen and returns a deferred that gets called back
with a port instance.
"""
mreactor = MemoryReactor()
factory = object()
ep, expectedArgs, expectedHost = self.createServerEndpoint(
mreactor, factory)
d = ep.listen(factory)
receivedHosts = []
def checkPortAndServer(port):
receivedHosts.append(port.getHost())
d.addCallback(checkPortAndServer)
self.assertEquals(receivedHosts, [expectedHost])
self.assertEquals(self.expectedServers(mreactor), [expectedArgs])
示例15: test_endpointConnectNonDefaultArgs
# 需要导入模块: from twisted.test import proto_helpers [as 别名]
# 或者: from twisted.test.proto_helpers import MemoryReactor [as 别名]
def test_endpointConnectNonDefaultArgs(self):
"""
The endpoint should pass it's connectArgs parameter to the reactor's
listen methods.
"""
factory = object()
mreactor = MemoryReactor()
ep, expectedArgs, ignoredHost = self.createClientEndpoint(
mreactor, factory,
**self.connectArgs())
ep.connect(factory)
expectedClients = self.expectedClients(mreactor)
self.assertEquals(len(expectedClients), 1)
self.assertConnectArgs(expectedClients[0], expectedArgs)