code
stringlengths 26
870k
| docstring
stringlengths 1
65.6k
| func_name
stringlengths 1
194
| language
stringclasses 1
value | repo
stringlengths 8
68
| path
stringlengths 5
182
| url
stringlengths 46
251
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
def stopConnecting(self):
"""
Behave as though an ongoing connection attempt has now
failed, and notify the factory of this.
"""
f.clientConnectionFailed(self, None) | Behave as though an ongoing connection attempt has now
failed, and notify the factory of this. | test_stopTryingDoesNotReconnect.stopConnecting | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | MIT |
def connect(self):
"""
Record an attempt to reconnect, since this is what we
are trying to avoid.
"""
self.attemptedRetry = True | Record an attempt to reconnect, since this is what we
are trying to avoid. | test_stopTryingDoesNotReconnect.connect | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | MIT |
def test_stopTryingDoesNotReconnect(self):
"""
Calling stopTrying on a L{ReconnectingClientFactory} doesn't attempt a
retry on any active connector.
"""
class FactoryAwareFakeConnector(FakeConnector):
attemptedRetry = False
def stopConnecting(self):
"""
Behave as though an ongoing connection attempt has now
failed, and notify the factory of this.
"""
f.clientConnectionFailed(self, None)
def connect(self):
"""
Record an attempt to reconnect, since this is what we
are trying to avoid.
"""
self.attemptedRetry = True
f = ReconnectingClientFactory()
f.clock = Clock()
# simulate an active connection - stopConnecting on this connector should
# be triggered when we call stopTrying
f.connector = FactoryAwareFakeConnector()
f.stopTrying()
# make sure we never attempted to retry
self.assertFalse(f.connector.attemptedRetry)
self.assertFalse(f.clock.getDelayedCalls()) | Calling stopTrying on a L{ReconnectingClientFactory} doesn't attempt a
retry on any active connector. | test_stopTryingDoesNotReconnect | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | MIT |
def test_serializeUnused(self):
"""
A L{ReconnectingClientFactory} which hasn't been used for anything
can be pickled and unpickled and end up with the same state.
"""
original = ReconnectingClientFactory()
reconstituted = pickle.loads(pickle.dumps(original))
self.assertEqual(original.__dict__, reconstituted.__dict__) | A L{ReconnectingClientFactory} which hasn't been used for anything
can be pickled and unpickled and end up with the same state. | test_serializeUnused | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | MIT |
def test_serializeWithClock(self):
"""
The clock attribute of L{ReconnectingClientFactory} is not serialized,
and the restored value sets it to the default value, the reactor.
"""
clock = Clock()
original = ReconnectingClientFactory()
original.clock = clock
reconstituted = pickle.loads(pickle.dumps(original))
self.assertIsNone(reconstituted.clock) | The clock attribute of L{ReconnectingClientFactory} is not serialized,
and the restored value sets it to the default value, the reactor. | test_serializeWithClock | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | MIT |
def test_deserializationResetsParameters(self):
"""
A L{ReconnectingClientFactory} which is unpickled does not have an
L{IConnector} and has its reconnecting timing parameters reset to their
initial values.
"""
factory = ReconnectingClientFactory()
factory.clientConnectionFailed(FakeConnector(), None)
self.addCleanup(factory.stopTrying)
serialized = pickle.dumps(factory)
unserialized = pickle.loads(serialized)
self.assertIsNone(unserialized.connector)
self.assertIsNone(unserialized._callID)
self.assertEqual(unserialized.retries, 0)
self.assertEqual(unserialized.delay, factory.initialDelay)
self.assertTrue(unserialized.continueTrying) | A L{ReconnectingClientFactory} which is unpickled does not have an
L{IConnector} and has its reconnecting timing parameters reset to their
initial values. | test_deserializationResetsParameters | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | MIT |
def test_parametrizedClock(self):
"""
The clock used by L{ReconnectingClientFactory} can be parametrized, so
that one can cleanly test reconnections.
"""
clock = Clock()
factory = ReconnectingClientFactory()
factory.clock = clock
factory.clientConnectionLost(FakeConnector(), None)
self.assertEqual(len(clock.calls), 1) | The clock used by L{ReconnectingClientFactory} can be parametrized, so
that one can cleanly test reconnections. | test_parametrizedClock | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_factories.py | MIT |
def __init__(self, protocol, isServer, hostAddress=None, peerAddress=None):
"""
@param protocol: This transport will deliver bytes to this protocol.
@type protocol: L{IProtocol} provider
@param isServer: C{True} if this is the accepting side of the
connection, C{False} if it is the connecting side.
@type isServer: L{bool}
@param hostAddress: The value to return from C{getHost}. L{None}
results in a new L{FakeAddress} being created to use as the value.
@type hostAddress: L{IAddress} provider or L{None}
@param peerAddress: The value to return from C{getPeer}. L{None}
results in a new L{FakeAddress} being created to use as the value.
@type peerAddress: L{IAddress} provider or L{None}
"""
self.protocol = protocol
self.isServer = isServer
self.stream = []
self.serial = self._nextserial()
if hostAddress is None:
hostAddress = FakeAddress()
self.hostAddress = hostAddress
if peerAddress is None:
peerAddress = FakeAddress()
self.peerAddress = peerAddress | @param protocol: This transport will deliver bytes to this protocol.
@type protocol: L{IProtocol} provider
@param isServer: C{True} if this is the accepting side of the
connection, C{False} if it is the connecting side.
@type isServer: L{bool}
@param hostAddress: The value to return from C{getHost}. L{None}
results in a new L{FakeAddress} being created to use as the value.
@type hostAddress: L{IAddress} provider or L{None}
@param peerAddress: The value to return from C{getPeer}. L{None}
results in a new L{FakeAddress} being created to use as the value.
@type peerAddress: L{IAddress} provider or L{None} | __init__ | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def abortConnection(self):
"""
For the time being, this is the same as loseConnection; no buffered
data will be lost.
"""
self.disconnecting = True | For the time being, this is the same as loseConnection; no buffered
data will be lost. | abortConnection | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def logPrefix(self):
"""
Identify this transport/event source to the logging system.
"""
return "iosim" | Identify this transport/event source to the logging system. | logPrefix | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def getOutBuffer(self):
"""
Get the pending writes from this transport, clearing them from the
pending buffer.
@return: the bytes written with C{transport.write}
@rtype: L{bytes}
"""
S = self.stream
if S:
self.stream = []
return b''.join(S)
elif self.tls is not None:
if self.tls.readyToSend:
# Only _send_ the TLS negotiation "packet" if I'm ready to.
self.tls.sent = True
return self.tls
else:
return None
else:
return None | Get the pending writes from this transport, clearing them from the
pending buffer.
@return: the bytes written with C{transport.write}
@rtype: L{bytes} | getOutBuffer | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def makeFakeClient(clientProtocol):
"""
Create and return a new in-memory transport hooked up to the given protocol.
@param clientProtocol: The client protocol to use.
@type clientProtocol: L{IProtocol} provider
@return: The transport.
@rtype: L{FakeTransport}
"""
return FakeTransport(clientProtocol, isServer=False) | Create and return a new in-memory transport hooked up to the given protocol.
@param clientProtocol: The client protocol to use.
@type clientProtocol: L{IProtocol} provider
@return: The transport.
@rtype: L{FakeTransport} | makeFakeClient | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def makeFakeServer(serverProtocol):
"""
Create and return a new in-memory transport hooked up to the given protocol.
@param serverProtocol: The server protocol to use.
@type serverProtocol: L{IProtocol} provider
@return: The transport.
@rtype: L{FakeTransport}
"""
return FakeTransport(serverProtocol, isServer=True) | Create and return a new in-memory transport hooked up to the given protocol.
@param serverProtocol: The server protocol to use.
@type serverProtocol: L{IProtocol} provider
@return: The transport.
@rtype: L{FakeTransport} | makeFakeServer | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def flush(self, debug=False):
"""
Pump until there is no more input or output.
Returns whether any data was moved.
"""
result = False
for x in range(1000):
if self.pump(debug):
result = True
else:
break
else:
assert 0, "Too long"
return result | Pump until there is no more input or output.
Returns whether any data was moved. | flush | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def connect(serverProtocol, serverTransport, clientProtocol, clientTransport,
debug=False, greet=True):
"""
Create a new L{IOPump} connecting two protocols.
@param serverProtocol: The protocol to use on the accepting side of the
connection.
@type serverProtocol: L{IProtocol} provider
@param serverTransport: The transport to associate with C{serverProtocol}.
@type serverTransport: L{FakeTransport}
@param clientProtocol: The protocol to use on the initiating side of the
connection.
@type clientProtocol: L{IProtocol} provider
@param clientTransport: The transport to associate with C{clientProtocol}.
@type clientTransport: L{FakeTransport}
@param debug: A flag indicating whether to log information about what the
L{IOPump} is doing.
@type debug: L{bool}
@param greet: Should the L{IOPump} be L{flushed <IOPump.flush>} once before
returning to put the protocols into their post-handshake or
post-server-greeting state?
@type greet: L{bool}
@return: An L{IOPump} which connects C{serverProtocol} and
C{clientProtocol} and delivers bytes between them when it is pumped.
@rtype: L{IOPump}
"""
serverProtocol.makeConnection(serverTransport)
clientProtocol.makeConnection(clientTransport)
pump = IOPump(
clientProtocol, serverProtocol, clientTransport, serverTransport, debug
)
if greet:
# Kick off server greeting, etc
pump.flush()
return pump | Create a new L{IOPump} connecting two protocols.
@param serverProtocol: The protocol to use on the accepting side of the
connection.
@type serverProtocol: L{IProtocol} provider
@param serverTransport: The transport to associate with C{serverProtocol}.
@type serverTransport: L{FakeTransport}
@param clientProtocol: The protocol to use on the initiating side of the
connection.
@type clientProtocol: L{IProtocol} provider
@param clientTransport: The transport to associate with C{clientProtocol}.
@type clientTransport: L{FakeTransport}
@param debug: A flag indicating whether to log information about what the
L{IOPump} is doing.
@type debug: L{bool}
@param greet: Should the L{IOPump} be L{flushed <IOPump.flush>} once before
returning to put the protocols into their post-handshake or
post-server-greeting state?
@type greet: L{bool}
@return: An L{IOPump} which connects C{serverProtocol} and
C{clientProtocol} and delivers bytes between them when it is pumped.
@rtype: L{IOPump} | connect | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def connectedServerAndClient(ServerClass, ClientClass,
clientTransportFactory=makeFakeClient,
serverTransportFactory=makeFakeServer,
debug=False, greet=True):
"""
Connect a given server and client class to each other.
@param ServerClass: a callable that produces the server-side protocol.
@type ServerClass: 0-argument callable returning L{IProtocol} provider.
@param ClientClass: like C{ServerClass} but for the other side of the
connection.
@type ClientClass: 0-argument callable returning L{IProtocol} provider.
@param clientTransportFactory: a callable that produces the transport which
will be attached to the protocol returned from C{ClientClass}.
@type clientTransportFactory: callable taking (L{IProtocol}) and returning
L{FakeTransport}
@param serverTransportFactory: a callable that produces the transport which
will be attached to the protocol returned from C{ServerClass}.
@type serverTransportFactory: callable taking (L{IProtocol}) and returning
L{FakeTransport}
@param debug: Should this dump an escaped version of all traffic on this
connection to stdout for inspection?
@type debug: L{bool}
@param greet: Should the L{IOPump} be L{flushed <IOPump.flush>} once before
returning to put the protocols into their post-handshake or
post-server-greeting state?
@type greet: L{bool}
@return: the client protocol, the server protocol, and an L{IOPump} which,
when its C{pump} and C{flush} methods are called, will move data
between the created client and server protocol instances.
@rtype: 3-L{tuple} of L{IProtocol}, L{IProtocol}, L{IOPump}
"""
c = ClientClass()
s = ServerClass()
cio = clientTransportFactory(c)
sio = serverTransportFactory(s)
return c, s, connect(s, sio, c, cio, debug, greet) | Connect a given server and client class to each other.
@param ServerClass: a callable that produces the server-side protocol.
@type ServerClass: 0-argument callable returning L{IProtocol} provider.
@param ClientClass: like C{ServerClass} but for the other side of the
connection.
@type ClientClass: 0-argument callable returning L{IProtocol} provider.
@param clientTransportFactory: a callable that produces the transport which
will be attached to the protocol returned from C{ClientClass}.
@type clientTransportFactory: callable taking (L{IProtocol}) and returning
L{FakeTransport}
@param serverTransportFactory: a callable that produces the transport which
will be attached to the protocol returned from C{ServerClass}.
@type serverTransportFactory: callable taking (L{IProtocol}) and returning
L{FakeTransport}
@param debug: Should this dump an escaped version of all traffic on this
connection to stdout for inspection?
@type debug: L{bool}
@param greet: Should the L{IOPump} be L{flushed <IOPump.flush>} once before
returning to put the protocols into their post-handshake or
post-server-greeting state?
@type greet: L{bool}
@return: the client protocol, the server protocol, and an L{IOPump} which,
when its C{pump} and C{flush} methods are called, will move data
between the created client and server protocol instances.
@rtype: 3-L{tuple} of L{IProtocol}, L{IProtocol}, L{IOPump} | connectedServerAndClient | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def _factoriesShouldConnect(clientInfo, serverInfo):
"""
Should the client and server described by the arguments be connected to
each other, i.e. do their port numbers match?
@param clientInfo: the args for connectTCP
@type clientInfo: L{tuple}
@param serverInfo: the args for listenTCP
@type serverInfo: L{tuple}
@return: If they do match, return factories for the client and server that
should connect; otherwise return L{None}, indicating they shouldn't be
connected.
@rtype: L{None} or 2-L{tuple} of (L{ClientFactory},
L{IProtocolFactory})
"""
(clientHost, clientPort, clientFactory, clientTimeout,
clientBindAddress) = clientInfo
(serverPort, serverFactory, serverBacklog,
serverInterface) = serverInfo
if serverPort == clientPort:
return clientFactory, serverFactory
else:
return None | Should the client and server described by the arguments be connected to
each other, i.e. do their port numbers match?
@param clientInfo: the args for connectTCP
@type clientInfo: L{tuple}
@param serverInfo: the args for listenTCP
@type serverInfo: L{tuple}
@return: If they do match, return factories for the client and server that
should connect; otherwise return L{None}, indicating they shouldn't be
connected.
@rtype: L{None} or 2-L{tuple} of (L{ClientFactory},
L{IProtocolFactory}) | _factoriesShouldConnect | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def __init__(self, memoryReactor):
"""
Create a L{ConnectionCompleter} from a L{MemoryReactor}.
@param memoryReactor: The reactor to attach to.
@type memoryReactor: L{MemoryReactor}
"""
self._reactor = memoryReactor | Create a L{ConnectionCompleter} from a L{MemoryReactor}.
@param memoryReactor: The reactor to attach to.
@type memoryReactor: L{MemoryReactor} | __init__ | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def succeedOnce(self, debug=False):
"""
Complete a single TCP connection established on this
L{ConnectionCompleter}'s L{MemoryReactor}.
@param debug: A flag; whether to dump output from the established
connection to stdout.
@type debug: L{bool}
@return: a pump for the connection, or L{None} if no connection could
be established.
@rtype: L{IOPump} or L{None}
"""
memoryReactor = self._reactor
for clientIdx, clientInfo in enumerate(memoryReactor.tcpClients):
for serverInfo in memoryReactor.tcpServers:
factories = _factoriesShouldConnect(clientInfo, serverInfo)
if factories:
memoryReactor.tcpClients.remove(clientInfo)
memoryReactor.connectors.pop(clientIdx)
clientFactory, serverFactory = factories
clientProtocol = clientFactory.buildProtocol(None)
serverProtocol = serverFactory.buildProtocol(None)
serverTransport = makeFakeServer(serverProtocol)
clientTransport = makeFakeClient(clientProtocol)
return connect(serverProtocol, serverTransport,
clientProtocol, clientTransport,
debug) | Complete a single TCP connection established on this
L{ConnectionCompleter}'s L{MemoryReactor}.
@param debug: A flag; whether to dump output from the established
connection to stdout.
@type debug: L{bool}
@return: a pump for the connection, or L{None} if no connection could
be established.
@rtype: L{IOPump} or L{None} | succeedOnce | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def failOnce(self, reason=Failure(ConnectionRefusedError())):
"""
Fail a single TCP connection established on this
L{ConnectionCompleter}'s L{MemoryReactor}.
@param reason: the reason to provide that the connection failed.
@type reason: L{Failure}
"""
self._reactor.tcpClients.pop(0)[2].clientConnectionFailed(
self._reactor.connectors.pop(0), reason
) | Fail a single TCP connection established on this
L{ConnectionCompleter}'s L{MemoryReactor}.
@param reason: the reason to provide that the connection failed.
@type reason: L{Failure} | failOnce | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def connectableEndpoint(debug=False):
"""
Create an endpoint that can be fired on demand.
@param debug: A flag; whether to dump output from the established
connection to stdout.
@type debug: L{bool}
@return: A client endpoint, and an object that will cause one of the
L{Deferred}s returned by that client endpoint.
@rtype: 2-L{tuple} of (L{IStreamClientEndpoint}, L{ConnectionCompleter})
"""
reactor = MemoryReactorClock()
clientEndpoint = TCP4ClientEndpoint(reactor, "0.0.0.0", 4321)
serverEndpoint = TCP4ServerEndpoint(reactor, 4321)
serverEndpoint.listen(Factory.forProtocol(Protocol))
return clientEndpoint, ConnectionCompleter(reactor) | Create an endpoint that can be fired on demand.
@param debug: A flag; whether to dump output from the established
connection to stdout.
@type debug: L{bool}
@return: A client endpoint, and an object that will cause one of the
L{Deferred}s returned by that client endpoint.
@rtype: 2-L{tuple} of (L{IStreamClientEndpoint}, L{ConnectionCompleter}) | connectableEndpoint | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/iosim.py | MIT |
def test_create(self):
"""
Create a simple shortcut.
"""
testFilename = __file__
baseFileName = os.path.basename(testFilename)
s1 = shortcut.Shortcut(testFilename)
tempname = self.mktemp() + '.lnk'
s1.save(tempname)
self.assertTrue(os.path.exists(tempname))
sc = shortcut.open(tempname)
scPath = sc.GetPath(shell.SLGP_RAWPATH)[0]
self.assertEqual(scPath[-len(baseFileName):].lower(),
baseFileName.lower()) | Create a simple shortcut. | test_create | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_shortcut.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_shortcut.py | MIT |
def test_createPythonShortcut(self):
"""
Create a shortcut to the Python executable,
and set some values.
"""
testFilename = sys.executable
baseFileName = os.path.basename(testFilename)
tempDir = tempfile.gettempdir()
s1 = shortcut.Shortcut(
path=testFilename,
arguments="-V",
description="The Python executable",
workingdir=tempDir,
iconpath=tempDir,
iconidx=1,
)
tempname = self.mktemp() + '.lnk'
s1.save(tempname)
self.assertTrue(os.path.exists(tempname))
sc = shortcut.open(tempname)
scPath = sc.GetPath(shell.SLGP_RAWPATH)[0]
self.assertEqual(scPath[-len(baseFileName):].lower(),
baseFileName.lower())
self.assertEqual(sc.GetDescription(), "The Python executable")
self.assertEqual(sc.GetWorkingDirectory(), tempDir)
self.assertEqual(sc.GetIconLocation(), (tempDir, 1)) | Create a shortcut to the Python executable,
and set some values. | test_createPythonShortcut | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_shortcut.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_shortcut.py | MIT |
def test_decimalDotted(self):
"""
L{isIPAddress} should return C{True} for any decimal dotted
representation of an IPv4 address.
"""
self.assertTrue(isIPAddress('0.1.2.3'))
self.assertTrue(isIPAddress('252.253.254.255')) | L{isIPAddress} should return C{True} for any decimal dotted
representation of an IPv4 address. | test_decimalDotted | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | MIT |
def test_shortDecimalDotted(self):
"""
L{isIPAddress} should return C{False} for a dotted decimal
representation with fewer or more than four octets.
"""
self.assertFalse(isIPAddress('0'))
self.assertFalse(isIPAddress('0.1'))
self.assertFalse(isIPAddress('0.1.2'))
self.assertFalse(isIPAddress('0.1.2.3.4')) | L{isIPAddress} should return C{False} for a dotted decimal
representation with fewer or more than four octets. | test_shortDecimalDotted | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | MIT |
def test_invalidLetters(self):
"""
L{isIPAddress} should return C{False} for any non-decimal dotted
representation including letters.
"""
self.assertFalse(isIPAddress('a.2.3.4'))
self.assertFalse(isIPAddress('1.b.3.4')) | L{isIPAddress} should return C{False} for any non-decimal dotted
representation including letters. | test_invalidLetters | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | MIT |
def test_invalidPunctuation(self):
"""
L{isIPAddress} should return C{False} for a string containing
strange punctuation.
"""
self.assertFalse(isIPAddress(','))
self.assertFalse(isIPAddress('1,2'))
self.assertFalse(isIPAddress('1,2,3'))
self.assertFalse(isIPAddress('1.,.3,4')) | L{isIPAddress} should return C{False} for a string containing
strange punctuation. | test_invalidPunctuation | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | MIT |
def test_emptyString(self):
"""
L{isIPAddress} should return C{False} for the empty string.
"""
self.assertFalse(isIPAddress('')) | L{isIPAddress} should return C{False} for the empty string. | test_emptyString | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | MIT |
def test_invalidNegative(self):
"""
L{isIPAddress} should return C{False} for negative decimal values.
"""
self.assertFalse(isIPAddress('-1'))
self.assertFalse(isIPAddress('1.-2'))
self.assertFalse(isIPAddress('1.2.-3'))
self.assertFalse(isIPAddress('1.2.-3.4')) | L{isIPAddress} should return C{False} for negative decimal values. | test_invalidNegative | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | MIT |
def test_invalidPositive(self):
"""
L{isIPAddress} should return C{False} for a string containing
positive decimal values greater than 255.
"""
self.assertFalse(isIPAddress('256.0.0.0'))
self.assertFalse(isIPAddress('0.256.0.0'))
self.assertFalse(isIPAddress('0.0.256.0'))
self.assertFalse(isIPAddress('0.0.0.256'))
self.assertFalse(isIPAddress('256.256.256.256')) | L{isIPAddress} should return C{False} for a string containing
positive decimal values greater than 255. | test_invalidPositive | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | MIT |
def test_unicodeAndBytes(self):
"""
L{isIPAddress} evaluates ASCII-encoded bytes as well as text.
"""
self.assertFalse(isIPAddress(b'256.0.0.0'))
self.assertFalse(isIPAddress(u'256.0.0.0'))
self.assertTrue(isIPAddress(b'252.253.254.255'))
self.assertTrue(isIPAddress(u'252.253.254.255')) | L{isIPAddress} evaluates ASCII-encoded bytes as well as text. | test_unicodeAndBytes | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | MIT |
def test_nonIPAddressFamily(self):
"""
All address families other than C{AF_INET} and C{AF_INET6} result in a
L{ValueError} being raised.
"""
self.assertRaises(ValueError, isIPAddress, b'anything', AF_IPX) | All address families other than C{AF_INET} and C{AF_INET6} result in a
L{ValueError} being raised. | test_nonIPAddressFamily | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | MIT |
def test_nonASCII(self):
"""
All IP addresses must be encodable as ASCII; non-ASCII should result in
a L{False} result.
"""
self.assertFalse(isIPAddress(b'\xff.notascii'))
self.assertFalse(isIPAddress(u'\u4321.notascii')) | All IP addresses must be encodable as ASCII; non-ASCII should result in
a L{False} result. | test_nonASCII | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_abstract.py | MIT |
def test_suggestThreadPoolSize(self):
"""
Try to change maximum number of threads.
"""
reactor.suggestThreadPoolSize(34)
self.assertEqual(reactor.threadpool.max, 34)
reactor.suggestThreadPoolSize(4)
self.assertEqual(reactor.threadpool.max, 4) | Try to change maximum number of threads. | test_suggestThreadPoolSize | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def _waitForThread(self):
"""
The reactor's threadpool is only available when the reactor is running,
so to have a sane behavior during the tests we make a dummy
L{threads.deferToThread} call.
"""
return threads.deferToThread(time.sleep, 0) | The reactor's threadpool is only available when the reactor is running,
so to have a sane behavior during the tests we make a dummy
L{threads.deferToThread} call. | _waitForThread | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_callInThread(self):
"""
Test callInThread functionality: set a C{threading.Event}, and check
that it's not in the main thread.
"""
def cb(ign):
waiter = threading.Event()
result = []
def threadedFunc():
result.append(threadable.isInIOThread())
waiter.set()
reactor.callInThread(threadedFunc)
waiter.wait(120)
if not waiter.isSet():
self.fail("Timed out waiting for event.")
else:
self.assertEqual(result, [False])
return self._waitForThread().addCallback(cb) | Test callInThread functionality: set a C{threading.Event}, and check
that it's not in the main thread. | test_callInThread | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_callFromThread(self):
"""
Test callFromThread functionality: from the main thread, and from
another thread.
"""
def cb(ign):
firedByReactorThread = defer.Deferred()
firedByOtherThread = defer.Deferred()
def threadedFunc():
reactor.callFromThread(firedByOtherThread.callback, None)
reactor.callInThread(threadedFunc)
reactor.callFromThread(firedByReactorThread.callback, None)
return defer.DeferredList(
[firedByReactorThread, firedByOtherThread],
fireOnOneErrback=True)
return self._waitForThread().addCallback(cb) | Test callFromThread functionality: from the main thread, and from
another thread. | test_callFromThread | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_wakerOverflow(self):
"""
Try to make an overflow on the reactor waker using callFromThread.
"""
def cb(ign):
self.failure = None
waiter = threading.Event()
def threadedFunction():
# Hopefully a hundred thousand queued calls is enough to
# trigger the error condition
for i in range(100000):
try:
reactor.callFromThread(lambda: None)
except:
self.failure = failure.Failure()
break
waiter.set()
reactor.callInThread(threadedFunction)
waiter.wait(120)
if not waiter.isSet():
self.fail("Timed out waiting for event")
if self.failure is not None:
return defer.fail(self.failure)
return self._waitForThread().addCallback(cb) | Try to make an overflow on the reactor waker using callFromThread. | test_wakerOverflow | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def _testBlockingCallFromThread(self, reactorFunc):
"""
Utility method to test L{threads.blockingCallFromThread}.
"""
waiter = threading.Event()
results = []
errors = []
def cb1(ign):
def threadedFunc():
try:
r = threads.blockingCallFromThread(reactor, reactorFunc)
except Exception as e:
errors.append(e)
else:
results.append(r)
waiter.set()
reactor.callInThread(threadedFunc)
return threads.deferToThread(waiter.wait, self.getTimeout())
def cb2(ign):
if not waiter.isSet():
self.fail("Timed out waiting for event")
return results, errors
return self._waitForThread().addCallback(cb1).addBoth(cb2) | Utility method to test L{threads.blockingCallFromThread}. | _testBlockingCallFromThread | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_blockingCallFromThread(self):
"""
Test blockingCallFromThread facility: create a thread, call a function
in the reactor using L{threads.blockingCallFromThread}, and verify the
result returned.
"""
def reactorFunc():
return defer.succeed("foo")
def cb(res):
self.assertEqual(res[0][0], "foo")
return self._testBlockingCallFromThread(reactorFunc).addCallback(cb) | Test blockingCallFromThread facility: create a thread, call a function
in the reactor using L{threads.blockingCallFromThread}, and verify the
result returned. | test_blockingCallFromThread | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_asyncBlockingCallFromThread(self):
"""
Test blockingCallFromThread as above, but be sure the resulting
Deferred is not already fired.
"""
def reactorFunc():
d = defer.Deferred()
reactor.callLater(0.1, d.callback, "egg")
return d
def cb(res):
self.assertEqual(res[0][0], "egg")
return self._testBlockingCallFromThread(reactorFunc).addCallback(cb) | Test blockingCallFromThread as above, but be sure the resulting
Deferred is not already fired. | test_asyncBlockingCallFromThread | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_errorBlockingCallFromThread(self):
"""
Test error report for blockingCallFromThread.
"""
def reactorFunc():
return defer.fail(RuntimeError("bar"))
def cb(res):
self.assertIsInstance(res[1][0], RuntimeError)
self.assertEqual(res[1][0].args[0], "bar")
return self._testBlockingCallFromThread(reactorFunc).addCallback(cb) | Test error report for blockingCallFromThread. | test_errorBlockingCallFromThread | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_asyncErrorBlockingCallFromThread(self):
"""
Test error report for blockingCallFromThread as above, but be sure the
resulting Deferred is not already fired.
"""
def reactorFunc():
d = defer.Deferred()
reactor.callLater(0.1, d.errback, RuntimeError("spam"))
return d
def cb(res):
self.assertIsInstance(res[1][0], RuntimeError)
self.assertEqual(res[1][0].args[0], "spam")
return self._testBlockingCallFromThread(reactorFunc).addCallback(cb) | Test error report for blockingCallFromThread as above, but be sure the
resulting Deferred is not already fired. | test_asyncErrorBlockingCallFromThread | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def add(self):
"""A non thread-safe method."""
next = self.index + 1
# another thread could jump in here and increment self.index on us
if next != self.index + 1:
self.problem = 1
raise ValueError
# or here, same issue but we wouldn't catch it. We'd overwrite
# their results, and the index will have lost a count. If
# several threads get in here, we will actually make the count
# go backwards when we overwrite it.
self.index = next | A non thread-safe method. | add | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_callMultiple(self):
"""
L{threads.callMultipleInThread} calls multiple functions in a thread.
"""
L = []
N = 10
d = defer.Deferred()
def finished():
self.assertEqual(L, list(range(N)))
d.callback(None)
threads.callMultipleInThread([
(L.append, (i,), {}) for i in range(N)
] + [(reactor.callFromThread, (finished,), {})])
return d | L{threads.callMultipleInThread} calls multiple functions in a thread. | test_callMultiple | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_deferredResult(self):
"""
L{threads.deferToThread} executes the function passed, and correctly
handles the positional and keyword arguments given.
"""
d = threads.deferToThread(lambda x, y=5: x + y, 3, y=4)
d.addCallback(self.assertEqual, 7)
return d | L{threads.deferToThread} executes the function passed, and correctly
handles the positional and keyword arguments given. | test_deferredResult | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_deferredFailure(self):
"""
Check that L{threads.deferToThread} return a failure object
with an appropriate exception instance when the called
function raises an exception.
"""
class NewError(Exception):
pass
def raiseError():
raise NewError()
d = threads.deferToThread(raiseError)
return self.assertFailure(d, NewError) | Check that L{threads.deferToThread} return a failure object
with an appropriate exception instance when the called
function raises an exception. | test_deferredFailure | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_deferredFailureAfterSuccess(self):
"""
Check that a successful L{threads.deferToThread} followed by a one
that raises an exception correctly result as a failure.
"""
# set up a condition that causes cReactor to hang. These conditions
# can also be set by other tests when the full test suite is run in
# alphabetical order (test_flow.FlowTest.testThreaded followed by
# test_internet.ReactorCoreTestCase.testStop, to be precise). By
# setting them up explicitly here, we can reproduce the hang in a
# single precise test case instead of depending upon side effects of
# other tests.
#
# alas, this test appears to flunk the default reactor too
d = threads.deferToThread(lambda: None)
d.addCallback(lambda ign: threads.deferToThread(lambda: 1//0))
return self.assertFailure(d, ZeroDivisionError) | Check that a successful L{threads.deferToThread} followed by a one
that raises an exception correctly result as a failure. | test_deferredFailureAfterSuccess | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_deferredResult(self):
"""
L{threads.deferToThreadPool} executes the function passed, and
correctly handles the positional and keyword arguments given.
"""
d = threads.deferToThreadPool(reactor, self.tp,
lambda x, y=5: x + y, 3, y=4)
d.addCallback(self.assertEqual, 7)
return d | L{threads.deferToThreadPool} executes the function passed, and
correctly handles the positional and keyword arguments given. | test_deferredResult | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def test_deferredFailure(self):
"""
Check that L{threads.deferToThreadPool} return a failure object with an
appropriate exception instance when the called function raises an
exception.
"""
class NewError(Exception):
pass
def raiseError():
raise NewError()
d = threads.deferToThreadPool(reactor, self.tp, raiseError)
return self.assertFailure(d, NewError) | Check that L{threads.deferToThreadPool} return a failure object with an
appropriate exception instance when the called function raises an
exception. | test_deferredFailure | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_threads.py | MIT |
def getDivisionFailure(*args, **kwargs):
"""
Make a L{failure.Failure} of a divide-by-zero error.
@param args: Any C{*args} are passed to Failure's constructor.
@param kwargs: Any C{**kwargs} are passed to Failure's constructor.
"""
try:
1/0
except:
f = failure.Failure(*args, **kwargs)
return f | Make a L{failure.Failure} of a divide-by-zero error.
@param args: Any C{*args} are passed to Failure's constructor.
@param kwargs: Any C{**kwargs} are passed to Failure's constructor. | getDivisionFailure | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def fakeCallbackCanceller(deferred):
"""
A fake L{defer.Deferred} canceller which callbacks the L{defer.Deferred}
with C{str} "Callback Result" when cancelling it.
@param deferred: The cancelled L{defer.Deferred}.
"""
deferred.callback("Callback Result") | A fake L{defer.Deferred} canceller which callbacks the L{defer.Deferred}
with C{str} "Callback Result" when cancelling it.
@param deferred: The cancelled L{defer.Deferred}. | fakeCallbackCanceller | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def assertImmediateFailure(self, deferred, exception):
"""
Assert that the given Deferred current result is a Failure with the
given exception.
@return: The exception instance in the Deferred.
"""
failures = []
deferred.addErrback(failures.append)
self.assertEqual(len(failures), 1)
self.assertTrue(failures[0].check(exception))
return failures[0].value | Assert that the given Deferred current result is a Failure with the
given exception.
@return: The exception instance in the Deferred. | assertImmediateFailure | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_logErrorReturnsError(self):
"""
L{defer.logError} returns the given error.
"""
error = failure.Failure(RuntimeError())
result = defer.logError(error)
self.flushLoggedErrors(RuntimeError)
self.assertIs(error, result) | L{defer.logError} returns the given error. | test_logErrorReturnsError | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_logErrorLogsError(self):
"""
L{defer.logError} logs the given error.
"""
error = failure.Failure(RuntimeError())
defer.logError(error)
errors = self.flushLoggedErrors(RuntimeError)
self.assertEqual(errors, [error]) | L{defer.logError} logs the given error. | test_logErrorLogsError | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_logErrorLogsErrorNoRepr(self):
"""
The text logged by L{defer.logError} has no repr of the failure.
"""
output = []
def emit(eventDict):
output.append(log.textFromEventDict(eventDict))
log.addObserver(emit)
error = failure.Failure(RuntimeError())
defer.logError(error)
self.flushLoggedErrors(RuntimeError)
self.assertTrue(output[0].startswith("Unhandled Error\nTraceback ")) | The text logged by L{defer.logError} has no repr of the failure. | test_logErrorLogsErrorNoRepr | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_cancelDeferredList(self):
"""
When cancelling an unfired L{defer.DeferredList}, cancel every
L{defer.Deferred} in the list.
"""
deferredOne = defer.Deferred()
deferredTwo = defer.Deferred()
deferredList = defer.DeferredList([deferredOne, deferredTwo])
deferredList.cancel()
self.failureResultOf(deferredOne, defer.CancelledError)
self.failureResultOf(deferredTwo, defer.CancelledError) | When cancelling an unfired L{defer.DeferredList}, cancel every
L{defer.Deferred} in the list. | test_cancelDeferredList | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_cancelDeferredListCallback(self):
"""
When cancelling an unfired L{defer.DeferredList} without the
C{fireOnOneCallback} and C{fireOnOneErrback} flags set, the
L{defer.DeferredList} will be callback with a C{list} of
(success, result) C{tuple}s.
"""
deferredOne = defer.Deferred(fakeCallbackCanceller)
deferredTwo = defer.Deferred()
deferredList = defer.DeferredList([deferredOne, deferredTwo])
deferredList.cancel()
self.failureResultOf(deferredTwo, defer.CancelledError)
result = self.successResultOf(deferredList)
self.assertTrue(result[0][0])
self.assertEqual(result[0][1], "Callback Result")
self.assertFalse(result[1][0])
self.assertTrue(result[1][1].check(defer.CancelledError)) | When cancelling an unfired L{defer.DeferredList} without the
C{fireOnOneCallback} and C{fireOnOneErrback} flags set, the
L{defer.DeferredList} will be callback with a C{list} of
(success, result) C{tuple}s. | test_cancelDeferredListCallback | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_cancelDeferredListWithFireOnOneCallback(self):
"""
When cancelling an unfired L{defer.DeferredList} with the flag
C{fireOnOneCallback} set, cancel every L{defer.Deferred} in the list.
"""
deferredOne = defer.Deferred()
deferredTwo = defer.Deferred()
deferredList = defer.DeferredList([deferredOne, deferredTwo],
fireOnOneCallback=True)
deferredList.cancel()
self.failureResultOf(deferredOne, defer.CancelledError)
self.failureResultOf(deferredTwo, defer.CancelledError) | When cancelling an unfired L{defer.DeferredList} with the flag
C{fireOnOneCallback} set, cancel every L{defer.Deferred} in the list. | test_cancelDeferredListWithFireOnOneCallback | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_cancelDeferredListWithFireOnOneCallbackAndDeferredCallback(self):
"""
When cancelling an unfired L{defer.DeferredList} with the flag
C{fireOnOneCallback} set, if one of the L{defer.Deferred} callbacks
in its canceller, the L{defer.DeferredList} will callback with the
result and the index of the L{defer.Deferred} in a C{tuple}.
"""
deferredOne = defer.Deferred(fakeCallbackCanceller)
deferredTwo = defer.Deferred()
deferredList = defer.DeferredList([deferredOne, deferredTwo],
fireOnOneCallback=True)
deferredList.cancel()
self.failureResultOf(deferredTwo, defer.CancelledError)
result = self.successResultOf(deferredList)
self.assertEqual(result, ("Callback Result", 0)) | When cancelling an unfired L{defer.DeferredList} with the flag
C{fireOnOneCallback} set, if one of the L{defer.Deferred} callbacks
in its canceller, the L{defer.DeferredList} will callback with the
result and the index of the L{defer.Deferred} in a C{tuple}. | test_cancelDeferredListWithFireOnOneCallbackAndDeferredCallback | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_cancelDeferredListWithFireOnOneErrback(self):
"""
When cancelling an unfired L{defer.DeferredList} with the flag
C{fireOnOneErrback} set, cancel every L{defer.Deferred} in the list.
"""
deferredOne = defer.Deferred()
deferredTwo = defer.Deferred()
deferredList = defer.DeferredList([deferredOne, deferredTwo],
fireOnOneErrback=True)
deferredList.cancel()
self.failureResultOf(deferredOne, defer.CancelledError)
self.failureResultOf(deferredTwo, defer.CancelledError)
deferredListFailure = self.failureResultOf(deferredList,
defer.FirstError)
firstError = deferredListFailure.value
self.assertTrue(firstError.subFailure.check(defer.CancelledError)) | When cancelling an unfired L{defer.DeferredList} with the flag
C{fireOnOneErrback} set, cancel every L{defer.Deferred} in the list. | test_cancelDeferredListWithFireOnOneErrback | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_cancelDeferredListWithFireOnOneErrbackAllDeferredsCallback(self):
"""
When cancelling an unfired L{defer.DeferredList} with the flag
C{fireOnOneErrback} set, if all the L{defer.Deferred} callbacks
in its canceller, the L{defer.DeferredList} will callback with a
C{list} of (success, result) C{tuple}s.
"""
deferredOne = defer.Deferred(fakeCallbackCanceller)
deferredTwo = defer.Deferred(fakeCallbackCanceller)
deferredList = defer.DeferredList([deferredOne, deferredTwo],
fireOnOneErrback=True)
deferredList.cancel()
result = self.successResultOf(deferredList)
self.assertTrue(result[0][0])
self.assertEqual(result[0][1], "Callback Result")
self.assertTrue(result[1][0])
self.assertEqual(result[1][1], "Callback Result") | When cancelling an unfired L{defer.DeferredList} with the flag
C{fireOnOneErrback} set, if all the L{defer.Deferred} callbacks
in its canceller, the L{defer.DeferredList} will callback with a
C{list} of (success, result) C{tuple}s. | test_cancelDeferredListWithFireOnOneErrbackAllDeferredsCallback | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_cancelDeferredListWithOriginalDeferreds(self):
"""
Cancelling a L{defer.DeferredList} will cancel the original
L{defer.Deferred}s passed in.
"""
deferredOne = defer.Deferred()
deferredTwo = defer.Deferred()
argumentList = [deferredOne, deferredTwo]
deferredList = defer.DeferredList(argumentList)
deferredThree = defer.Deferred()
argumentList.append(deferredThree)
deferredList.cancel()
self.failureResultOf(deferredOne, defer.CancelledError)
self.failureResultOf(deferredTwo, defer.CancelledError)
self.assertNoResult(deferredThree) | Cancelling a L{defer.DeferredList} will cancel the original
L{defer.Deferred}s passed in. | test_cancelDeferredListWithOriginalDeferreds | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def cancellerRaisesException(deferred):
"""
A L{defer.Deferred} canceller that raises an exception.
@param deferred: The cancelled L{defer.Deferred}.
"""
raise RuntimeError("test") | A L{defer.Deferred} canceller that raises an exception.
@param deferred: The cancelled L{defer.Deferred}. | test_cancelDeferredListWithException.cancellerRaisesException | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_cancelDeferredListWithException(self):
"""
Cancelling a L{defer.DeferredList} will cancel every L{defer.Deferred}
in the list even exceptions raised from the C{cancel} method of the
L{defer.Deferred}s.
"""
def cancellerRaisesException(deferred):
"""
A L{defer.Deferred} canceller that raises an exception.
@param deferred: The cancelled L{defer.Deferred}.
"""
raise RuntimeError("test")
deferredOne = defer.Deferred(cancellerRaisesException)
deferredTwo = defer.Deferred()
deferredList = defer.DeferredList([deferredOne, deferredTwo])
deferredList.cancel()
self.failureResultOf(deferredTwo, defer.CancelledError)
errors = self.flushLoggedErrors(RuntimeError)
self.assertEqual(len(errors), 1) | Cancelling a L{defer.DeferredList} will cancel every L{defer.Deferred}
in the list even exceptions raised from the C{cancel} method of the
L{defer.Deferred}s. | test_cancelDeferredListWithException | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_cancelFiredOnOneCallbackDeferredList(self):
"""
When a L{defer.DeferredList} has fired because one L{defer.Deferred} in
the list fired with a non-failure result, the cancellation will do
nothing instead of cancelling the rest of the L{defer.Deferred}s.
"""
deferredOne = defer.Deferred()
deferredTwo = defer.Deferred()
deferredList = defer.DeferredList([deferredOne, deferredTwo],
fireOnOneCallback=True)
deferredOne.callback(None)
deferredList.cancel()
self.assertNoResult(deferredTwo) | When a L{defer.DeferredList} has fired because one L{defer.Deferred} in
the list fired with a non-failure result, the cancellation will do
nothing instead of cancelling the rest of the L{defer.Deferred}s. | test_cancelFiredOnOneCallbackDeferredList | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_cancelFiredOnOneErrbackDeferredList(self):
"""
When a L{defer.DeferredList} has fired because one L{defer.Deferred} in
the list fired with a failure result, the cancellation will do
nothing instead of cancelling the rest of the L{defer.Deferred}s.
"""
deferredOne = defer.Deferred()
deferredTwo = defer.Deferred()
deferredList = defer.DeferredList([deferredOne, deferredTwo],
fireOnOneErrback=True)
deferredOne.errback(GenericError("test"))
deferredList.cancel()
self.assertNoResult(deferredTwo)
self.failureResultOf(deferredOne, GenericError)
self.failureResultOf(deferredList, defer.FirstError) | When a L{defer.DeferredList} has fired because one L{defer.Deferred} in
the list fired with a failure result, the cancellation will do
nothing instead of cancelling the rest of the L{defer.Deferred}s. | test_cancelFiredOnOneErrbackDeferredList | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_chainedPausedDeferredWithResult(self):
"""
When a paused Deferred with a result is returned from a callback on
another Deferred, the other Deferred is chained to the first and waits
for it to be unpaused.
"""
expected = object()
paused = defer.Deferred()
paused.callback(expected)
paused.pause()
chained = defer.Deferred()
chained.addCallback(lambda ignored: paused)
chained.callback(None)
result = []
chained.addCallback(result.append)
self.assertEqual(result, [])
paused.unpause()
self.assertEqual(result, [expected]) | When a paused Deferred with a result is returned from a callback on
another Deferred, the other Deferred is chained to the first and waits
for it to be unpaused. | test_chainedPausedDeferredWithResult | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_pausedDeferredChained(self):
"""
A paused Deferred encountered while pushing a result forward through a
chain does not prevent earlier Deferreds from continuing to execute
their callbacks.
"""
first = defer.Deferred()
second = defer.Deferred()
first.addCallback(lambda ignored: second)
first.callback(None)
first.pause()
second.callback(None)
result = []
second.addCallback(result.append)
self.assertEqual(result, [None]) | A paused Deferred encountered while pushing a result forward through a
chain does not prevent earlier Deferreds from continuing to execute
their callbacks. | test_pausedDeferredChained | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_gatherResultsWithConsumeErrors(self):
"""
If a L{Deferred} in the list passed to L{gatherResults} fires with a
failure and C{consumerErrors} is C{True}, the failure is converted to a
L{None} result on that L{Deferred}.
"""
# test successful list of deferreds
dgood = defer.succeed(1)
dbad = defer.fail(RuntimeError("oh noes"))
d = defer.gatherResults([dgood, dbad], consumeErrors=True)
unconsumedErrors = []
dbad.addErrback(unconsumedErrors.append)
gatheredErrors = []
d.addErrback(gatheredErrors.append)
self.assertEqual((len(unconsumedErrors), len(gatheredErrors)),
(0, 1))
self.assertIsInstance(gatheredErrors[0].value, defer.FirstError)
firstError = gatheredErrors[0].value.subFailure
self.assertIsInstance(firstError.value, RuntimeError) | If a L{Deferred} in the list passed to L{gatherResults} fires with a
failure and C{consumerErrors} is C{True}, the failure is converted to a
L{None} result on that L{Deferred}. | test_gatherResultsWithConsumeErrors | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_cancelGatherResults(self):
"""
When cancelling the L{defer.gatherResults} call, all the
L{defer.Deferred}s in the list will be cancelled.
"""
deferredOne = defer.Deferred()
deferredTwo = defer.Deferred()
result = defer.gatherResults([deferredOne, deferredTwo])
result.cancel()
self.failureResultOf(deferredOne, defer.CancelledError)
self.failureResultOf(deferredTwo, defer.CancelledError)
gatherResultsFailure = self.failureResultOf(result, defer.FirstError)
firstError = gatherResultsFailure.value
self.assertTrue(firstError.subFailure.check(defer.CancelledError)) | When cancelling the L{defer.gatherResults} call, all the
L{defer.Deferred}s in the list will be cancelled. | test_cancelGatherResults | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_cancelGatherResultsWithAllDeferredsCallback(self):
"""
When cancelling the L{defer.gatherResults} call, if all the
L{defer.Deferred}s callback in their canceller, the L{defer.Deferred}
returned by L{defer.gatherResults} will be callbacked with the C{list}
of the results.
"""
deferredOne = defer.Deferred(fakeCallbackCanceller)
deferredTwo = defer.Deferred(fakeCallbackCanceller)
result = defer.gatherResults([deferredOne, deferredTwo])
result.cancel()
callbackResult = self.successResultOf(result)
self.assertEqual(callbackResult[0], "Callback Result")
self.assertEqual(callbackResult[1], "Callback Result") | When cancelling the L{defer.gatherResults} call, if all the
L{defer.Deferred}s callback in their canceller, the L{defer.Deferred}
returned by L{defer.gatherResults} will be callbacked with the C{list}
of the results. | test_cancelGatherResultsWithAllDeferredsCallback | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_maybeDeferredSync(self):
"""
L{defer.maybeDeferred} should retrieve the result of a synchronous
function and pass it to its resulting L{defer.Deferred}.
"""
S, E = [], []
d = defer.maybeDeferred((lambda x: x + 5), 10)
d.addCallbacks(S.append, E.append)
self.assertEqual(E, [])
self.assertEqual(S, [15]) | L{defer.maybeDeferred} should retrieve the result of a synchronous
function and pass it to its resulting L{defer.Deferred}. | test_maybeDeferredSync | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_maybeDeferredSyncError(self):
"""
L{defer.maybeDeferred} should catch exception raised by a synchronous
function and errback its resulting L{defer.Deferred} with it.
"""
S, E = [], []
try:
'10' + 5
except TypeError as e:
expected = str(e)
d = defer.maybeDeferred((lambda x: x + 5), '10')
d.addCallbacks(S.append, E.append)
self.assertEqual(S, [])
self.assertEqual(len(E), 1)
self.assertEqual(str(E[0].value), expected) | L{defer.maybeDeferred} should catch exception raised by a synchronous
function and errback its resulting L{defer.Deferred} with it. | test_maybeDeferredSyncError | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_maybeDeferredAsync(self):
"""
L{defer.maybeDeferred} should let L{defer.Deferred} instance pass by
so that original result is the same.
"""
d = defer.Deferred()
d2 = defer.maybeDeferred(lambda: d)
d.callback('Success')
result = []
d2.addCallback(result.append)
self.assertEqual(result, ['Success']) | L{defer.maybeDeferred} should let L{defer.Deferred} instance pass by
so that original result is the same. | test_maybeDeferredAsync | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_maybeDeferredAsyncError(self):
"""
L{defer.maybeDeferred} should let L{defer.Deferred} instance pass by
so that L{failure.Failure} returned by the original instance is the
same.
"""
d = defer.Deferred()
d2 = defer.maybeDeferred(lambda: d)
d.errback(failure.Failure(RuntimeError()))
self.assertImmediateFailure(d2, RuntimeError) | L{defer.maybeDeferred} should let L{defer.Deferred} instance pass by
so that L{failure.Failure} returned by the original instance is the
same. | test_maybeDeferredAsyncError | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_innerCallbacksPreserved(self):
"""
When a L{Deferred} encounters a result which is another L{Deferred}
which is waiting on a third L{Deferred}, the middle L{Deferred}'s
callbacks are executed after the third L{Deferred} fires and before the
first receives a result.
"""
results = []
failures = []
inner = defer.Deferred()
def cb(result):
results.append(('start-of-cb', result))
d = defer.succeed('inner')
def firstCallback(result):
results.append(('firstCallback', 'inner'))
return inner
def secondCallback(result):
results.append(('secondCallback', result))
return result * 2
d.addCallback(firstCallback).addCallback(secondCallback)
d.addErrback(failures.append)
return d
outer = defer.succeed('outer')
outer.addCallback(cb)
inner.callback('orange')
outer.addCallback(results.append)
inner.addErrback(failures.append)
outer.addErrback(failures.append)
self.assertEqual([], failures)
self.assertEqual(
results,
[('start-of-cb', 'outer'),
('firstCallback', 'inner'),
('secondCallback', 'orange'),
'orangeorange']) | When a L{Deferred} encounters a result which is another L{Deferred}
which is waiting on a third L{Deferred}, the middle L{Deferred}'s
callbacks are executed after the third L{Deferred} fires and before the
first receives a result. | test_innerCallbacksPreserved | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_continueCallbackNotFirst(self):
"""
The continue callback of a L{Deferred} waiting for another L{Deferred}
is not necessarily the first one. This is somewhat a whitebox test
checking that we search for that callback among the whole list of
callbacks.
"""
results = []
failures = []
a = defer.Deferred()
def cb(result):
results.append(('cb', result))
d = defer.Deferred()
def firstCallback(ignored):
results.append(('firstCallback', ignored))
return defer.gatherResults([a])
def secondCallback(result):
results.append(('secondCallback', result))
d.addCallback(firstCallback)
d.addCallback(secondCallback)
d.addErrback(failures.append)
d.callback(None)
return d
outer = defer.succeed('outer')
outer.addCallback(cb)
outer.addErrback(failures.append)
self.assertEqual([('cb', 'outer'), ('firstCallback', None)], results)
a.callback('withers')
self.assertEqual([], failures)
self.assertEqual(
results,
[('cb', 'outer'),
('firstCallback', None),
('secondCallback', ['withers'])]) | The continue callback of a L{Deferred} waiting for another L{Deferred}
is not necessarily the first one. This is somewhat a whitebox test
checking that we search for that callback among the whole list of
callbacks. | test_continueCallbackNotFirst | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_callbackOrderPreserved(self):
"""
A callback added to a L{Deferred} after a previous callback attached
another L{Deferred} as a result is run after the callbacks of the other
L{Deferred} are run.
"""
results = []
failures = []
a = defer.Deferred()
def cb(result):
results.append(('cb', result))
d = defer.Deferred()
def firstCallback(ignored):
results.append(('firstCallback', ignored))
return defer.gatherResults([a])
def secondCallback(result):
results.append(('secondCallback', result))
d.addCallback(firstCallback)
d.addCallback(secondCallback)
d.addErrback(failures.append)
d.callback(None)
return d
outer = defer.Deferred()
outer.addCallback(cb)
outer.addCallback(lambda x: results.append('final'))
outer.addErrback(failures.append)
outer.callback('outer')
self.assertEqual([('cb', 'outer'), ('firstCallback', None)], results)
a.callback('withers')
self.assertEqual([], failures)
self.assertEqual(
results,
[('cb', 'outer'),
('firstCallback', None),
('secondCallback', ['withers']), 'final']) | A callback added to a L{Deferred} after a previous callback attached
another L{Deferred} as a result is run after the callbacks of the other
L{Deferred} are run. | test_callbackOrderPreserved | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_reentrantRunCallbacks(self):
"""
A callback added to a L{Deferred} by a callback on that L{Deferred}
should be added to the end of the callback chain.
"""
deferred = defer.Deferred()
called = []
def callback3(result):
called.append(3)
def callback2(result):
called.append(2)
def callback1(result):
called.append(1)
deferred.addCallback(callback3)
deferred.addCallback(callback1)
deferred.addCallback(callback2)
deferred.callback(None)
self.assertEqual(called, [1, 2, 3]) | A callback added to a L{Deferred} by a callback on that L{Deferred}
should be added to the end of the callback chain. | test_reentrantRunCallbacks | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_nonReentrantCallbacks(self):
"""
A callback added to a L{Deferred} by a callback on that L{Deferred}
should not be executed until the running callback returns.
"""
deferred = defer.Deferred()
called = []
def callback2(result):
called.append(2)
def callback1(result):
called.append(1)
deferred.addCallback(callback2)
self.assertEqual(called, [1])
deferred.addCallback(callback1)
deferred.callback(None)
self.assertEqual(called, [1, 2]) | A callback added to a L{Deferred} by a callback on that L{Deferred}
should not be executed until the running callback returns. | test_nonReentrantCallbacks | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_reentrantRunCallbacksWithFailure(self):
"""
After an exception is raised by a callback which was added to a
L{Deferred} by a callback on that L{Deferred}, the L{Deferred} should
call the first errback with a L{Failure} wrapping that exception.
"""
exceptionMessage = "callback raised exception"
deferred = defer.Deferred()
def callback2(result):
raise Exception(exceptionMessage)
def callback1(result):
deferred.addCallback(callback2)
deferred.addCallback(callback1)
deferred.callback(None)
exception = self.assertImmediateFailure(deferred, Exception)
self.assertEqual(exception.args, (exceptionMessage,)) | After an exception is raised by a callback which was added to a
L{Deferred} by a callback on that L{Deferred}, the L{Deferred} should
call the first errback with a L{Failure} wrapping that exception. | test_reentrantRunCallbacksWithFailure | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_synchronousImplicitChain(self):
"""
If a first L{Deferred} with a result is returned from a callback on a
second L{Deferred}, the result of the second L{Deferred} becomes the
result of the first L{Deferred} and the result of the first L{Deferred}
becomes L{None}.
"""
result = object()
first = defer.succeed(result)
second = defer.Deferred()
second.addCallback(lambda ign: first)
second.callback(None)
results = []
first.addCallback(results.append)
self.assertIsNone(results[0])
second.addCallback(results.append)
self.assertIs(results[1], result) | If a first L{Deferred} with a result is returned from a callback on a
second L{Deferred}, the result of the second L{Deferred} becomes the
result of the first L{Deferred} and the result of the first L{Deferred}
becomes L{None}. | test_synchronousImplicitChain | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_asynchronousImplicitChain(self):
"""
If a first L{Deferred} without a result is returned from a callback on
a second L{Deferred}, the result of the second L{Deferred} becomes the
result of the first L{Deferred} as soon as the first L{Deferred} has
one and the result of the first L{Deferred} becomes L{None}.
"""
first = defer.Deferred()
second = defer.Deferred()
second.addCallback(lambda ign: first)
second.callback(None)
firstResult = []
first.addCallback(firstResult.append)
secondResult = []
second.addCallback(secondResult.append)
self.assertEqual(firstResult, [])
self.assertEqual(secondResult, [])
result = object()
first.callback(result)
self.assertEqual(firstResult, [None])
self.assertEqual(secondResult, [result]) | If a first L{Deferred} without a result is returned from a callback on
a second L{Deferred}, the result of the second L{Deferred} becomes the
result of the first L{Deferred} as soon as the first L{Deferred} has
one and the result of the first L{Deferred} becomes L{None}. | test_asynchronousImplicitChain | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_synchronousImplicitErrorChain(self):
"""
If a first L{Deferred} with a L{Failure} result is returned from a
callback on a second L{Deferred}, the first L{Deferred}'s result is
converted to L{None} and no unhandled error is logged when it is
garbage collected.
"""
first = defer.fail(RuntimeError("First Deferred's Failure"))
second = defer.Deferred()
second.addCallback(lambda ign, first=first: first)
second.callback(None)
firstResult = []
first.addCallback(firstResult.append)
self.assertIsNone(firstResult[0])
self.assertImmediateFailure(second, RuntimeError) | If a first L{Deferred} with a L{Failure} result is returned from a
callback on a second L{Deferred}, the first L{Deferred}'s result is
converted to L{None} and no unhandled error is logged when it is
garbage collected. | test_synchronousImplicitErrorChain | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_asynchronousImplicitErrorChain(self):
"""
Let C{a} and C{b} be two L{Deferred}s.
If C{a} has no result and is returned from a callback on C{b} then when
C{a} fails, C{b}'s result becomes the L{Failure} that was C{a}'s result,
the result of C{a} becomes L{None} so that no unhandled error is logged
when it is garbage collected.
"""
first = defer.Deferred()
second = defer.Deferred()
second.addCallback(lambda ign: first)
second.callback(None)
secondError = []
second.addErrback(secondError.append)
firstResult = []
first.addCallback(firstResult.append)
secondResult = []
second.addCallback(secondResult.append)
self.assertEqual(firstResult, [])
self.assertEqual(secondResult, [])
first.errback(RuntimeError("First Deferred's Failure"))
self.assertTrue(secondError[0].check(RuntimeError))
self.assertEqual(firstResult, [None])
self.assertEqual(len(secondResult), 1) | Let C{a} and C{b} be two L{Deferred}s.
If C{a} has no result and is returned from a callback on C{b} then when
C{a} fails, C{b}'s result becomes the L{Failure} that was C{a}'s result,
the result of C{a} becomes L{None} so that no unhandled error is logged
when it is garbage collected. | test_asynchronousImplicitErrorChain | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_doubleAsynchronousImplicitChaining(self):
"""
L{Deferred} chaining is transitive.
In other words, let A, B, and C be Deferreds. If C is returned from a
callback on B and B is returned from a callback on A then when C fires,
A fires.
"""
first = defer.Deferred()
second = defer.Deferred()
second.addCallback(lambda ign: first)
third = defer.Deferred()
third.addCallback(lambda ign: second)
thirdResult = []
third.addCallback(thirdResult.append)
result = object()
# After this, second is waiting for first to tell it to continue.
second.callback(None)
# And after this, third is waiting for second to tell it to continue.
third.callback(None)
# Still waiting
self.assertEqual(thirdResult, [])
# This will tell second to continue which will tell third to continue.
first.callback(result)
self.assertEqual(thirdResult, [result]) | L{Deferred} chaining is transitive.
In other words, let A, B, and C be Deferreds. If C is returned from a
callback on B and B is returned from a callback on A then when C fires,
A fires. | test_doubleAsynchronousImplicitChaining | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_nestedAsynchronousChainedDeferreds(self):
"""
L{Deferred}s can have callbacks that themselves return L{Deferred}s.
When these "inner" L{Deferred}s fire (even asynchronously), the
callback chain continues.
"""
results = []
failures = []
# A Deferred returned in the inner callback.
inner = defer.Deferred()
def cb(result):
results.append(('start-of-cb', result))
d = defer.succeed('inner')
def firstCallback(result):
results.append(('firstCallback', 'inner'))
# Return a Deferred that definitely has not fired yet, so we
# can fire the Deferreds out of order.
return inner
def secondCallback(result):
results.append(('secondCallback', result))
return result * 2
d.addCallback(firstCallback).addCallback(secondCallback)
d.addErrback(failures.append)
return d
# Create a synchronous Deferred that has a callback 'cb' that returns
# a Deferred 'd' that has fired but is now waiting on an unfired
# Deferred 'inner'.
outer = defer.succeed('outer')
outer.addCallback(cb)
outer.addCallback(results.append)
# At this point, the callback 'cb' has been entered, and the first
# callback of 'd' has been called.
self.assertEqual(
results, [('start-of-cb', 'outer'), ('firstCallback', 'inner')])
# Once the inner Deferred is fired, processing of the outer Deferred's
# callback chain continues.
inner.callback('orange')
# Make sure there are no errors.
inner.addErrback(failures.append)
outer.addErrback(failures.append)
self.assertEqual(
[], failures, "Got errbacks but wasn't expecting any.")
self.assertEqual(
results,
[('start-of-cb', 'outer'),
('firstCallback', 'inner'),
('secondCallback', 'orange'),
'orangeorange']) | L{Deferred}s can have callbacks that themselves return L{Deferred}s.
When these "inner" L{Deferred}s fire (even asynchronously), the
callback chain continues. | test_nestedAsynchronousChainedDeferreds | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_nestedAsynchronousChainedDeferredsWithExtraCallbacks(self):
"""
L{Deferred}s can have callbacks that themselves return L{Deferred}s.
These L{Deferred}s can have other callbacks added before they are
returned, which subtly changes the callback chain. When these "inner"
L{Deferred}s fire (even asynchronously), the outer callback chain
continues.
"""
results = []
failures = []
# A Deferred returned in the inner callback after a callback is
# added explicitly and directly to it.
inner = defer.Deferred()
def cb(result):
results.append(('start-of-cb', result))
d = defer.succeed('inner')
def firstCallback(ignored):
results.append(('firstCallback', ignored))
# Return a Deferred that definitely has not fired yet with a
# result-transforming callback so we can fire the Deferreds
# out of order and see how the callback affects the ultimate
# results.
return inner.addCallback(lambda x: [x])
def secondCallback(result):
results.append(('secondCallback', result))
return result * 2
d.addCallback(firstCallback)
d.addCallback(secondCallback)
d.addErrback(failures.append)
return d
# Create a synchronous Deferred that has a callback 'cb' that returns
# a Deferred 'd' that has fired but is now waiting on an unfired
# Deferred 'inner'.
outer = defer.succeed('outer')
outer.addCallback(cb)
outer.addCallback(results.append)
# At this point, the callback 'cb' has been entered, and the first
# callback of 'd' has been called.
self.assertEqual(
results, [('start-of-cb', 'outer'), ('firstCallback', 'inner')])
# Once the inner Deferred is fired, processing of the outer Deferred's
# callback chain continues.
inner.callback('withers')
# Make sure there are no errors.
outer.addErrback(failures.append)
inner.addErrback(failures.append)
self.assertEqual(
[], failures, "Got errbacks but wasn't expecting any.")
self.assertEqual(
results,
[('start-of-cb', 'outer'),
('firstCallback', 'inner'),
('secondCallback', ['withers']),
['withers', 'withers']]) | L{Deferred}s can have callbacks that themselves return L{Deferred}s.
These L{Deferred}s can have other callbacks added before they are
returned, which subtly changes the callback chain. When these "inner"
L{Deferred}s fire (even asynchronously), the outer callback chain
continues. | test_nestedAsynchronousChainedDeferredsWithExtraCallbacks | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_chainDeferredRecordsExplicitChain(self):
"""
When we chain a L{Deferred}, that chaining is recorded explicitly.
"""
a = defer.Deferred()
b = defer.Deferred()
b.chainDeferred(a)
self.assertIs(a._chainedTo, b) | When we chain a L{Deferred}, that chaining is recorded explicitly. | test_chainDeferredRecordsExplicitChain | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_explicitChainClearedWhenResolved(self):
"""
Any recorded chaining is cleared once the chaining is resolved, since
it no longer exists.
In other words, if one L{Deferred} is recorded as depending on the
result of another, and I{that} L{Deferred} has fired, then the
dependency is resolved and we no longer benefit from recording it.
"""
a = defer.Deferred()
b = defer.Deferred()
b.chainDeferred(a)
b.callback(None)
self.assertIsNone(a._chainedTo) | Any recorded chaining is cleared once the chaining is resolved, since
it no longer exists.
In other words, if one L{Deferred} is recorded as depending on the
result of another, and I{that} L{Deferred} has fired, then the
dependency is resolved and we no longer benefit from recording it. | test_explicitChainClearedWhenResolved | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_chainDeferredRecordsImplicitChain(self):
"""
We can chain L{Deferred}s implicitly by adding callbacks that return
L{Deferred}s. When this chaining happens, we record it explicitly as
soon as we can find out about it.
"""
a = defer.Deferred()
b = defer.Deferred()
a.addCallback(lambda ignored: b)
a.callback(None)
self.assertIs(a._chainedTo, b) | We can chain L{Deferred}s implicitly by adding callbacks that return
L{Deferred}s. When this chaining happens, we record it explicitly as
soon as we can find out about it. | test_chainDeferredRecordsImplicitChain | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_circularChainWarning(self):
"""
When a Deferred is returned from a callback directly attached to that
same Deferred, a warning is emitted.
"""
d = defer.Deferred()
def circularCallback(result):
return d
d.addCallback(circularCallback)
d.callback("foo")
circular_warnings = self.flushWarnings([circularCallback])
self.assertEqual(len(circular_warnings), 1)
warning = circular_warnings[0]
self.assertEqual(warning['category'], DeprecationWarning)
pattern = "Callback returned the Deferred it was attached to"
self.assertTrue(
re.search(pattern, warning['message']),
"\nExpected match: %r\nGot: %r" % (pattern, warning['message'])) | When a Deferred is returned from a callback directly attached to that
same Deferred, a warning is emitted. | test_circularChainWarning | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_circularChainException(self):
"""
If the deprecation warning for circular deferred callbacks is
configured to be an error, the exception will become the failure
result of the Deferred.
"""
self.addCleanup(setattr, warnings, "filters", warnings.filters)
warnings.filterwarnings("error", category=DeprecationWarning)
d = defer.Deferred()
def circularCallback(result):
return d
d.addCallback(circularCallback)
d.callback("foo")
failure = self.failureResultOf(d)
failure.trap(DeprecationWarning) | If the deprecation warning for circular deferred callbacks is
configured to be an error, the exception will become the failure
result of the Deferred. | test_circularChainException | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_repr(self):
"""
The C{repr()} of a L{Deferred} contains the class name and a
representation of the internal Python ID.
"""
d = defer.Deferred()
address = id(d)
self.assertEqual(
repr(d), '<Deferred at 0x%x>' % (address,)) | The C{repr()} of a L{Deferred} contains the class name and a
representation of the internal Python ID. | test_repr | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_reprWithResult(self):
"""
If a L{Deferred} has been fired, then its C{repr()} contains its
result.
"""
d = defer.Deferred()
d.callback('orange')
self.assertEqual(
repr(d), "<Deferred at 0x%x current result: 'orange'>" % (
id(d),)) | If a L{Deferred} has been fired, then its C{repr()} contains its
result. | test_reprWithResult | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_reprWithChaining(self):
"""
If a L{Deferred} C{a} has been fired, but is waiting on another
L{Deferred} C{b} that appears in its callback chain, then C{repr(a)}
says that it is waiting on C{b}.
"""
a = defer.Deferred()
b = defer.Deferred()
b.chainDeferred(a)
self.assertEqual(
repr(a), "<Deferred at 0x%x waiting on Deferred at 0x%x>" % (
id(a), id(b))) | If a L{Deferred} C{a} has been fired, but is waiting on another
L{Deferred} C{b} that appears in its callback chain, then C{repr(a)}
says that it is waiting on C{b}. | test_reprWithChaining | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_boundedStackDepth(self):
"""
The depth of the call stack does not grow as more L{Deferred} instances
are chained together.
"""
def chainDeferreds(howMany):
stack = []
def recordStackDepth(ignored):
stack.append(len(traceback.extract_stack()))
top = defer.Deferred()
innerDeferreds = [defer.Deferred() for ignored in range(howMany)]
originalInners = innerDeferreds[:]
last = defer.Deferred()
inner = innerDeferreds.pop()
top.addCallback(lambda ign, inner=inner: inner)
top.addCallback(recordStackDepth)
while innerDeferreds:
newInner = innerDeferreds.pop()
inner.addCallback(lambda ign, inner=newInner: inner)
inner = newInner
inner.addCallback(lambda ign: last)
top.callback(None)
for inner in originalInners:
inner.callback(None)
# Sanity check - the record callback is not intended to have
# fired yet.
self.assertEqual(stack, [])
# Now fire the last thing and return the stack depth at which the
# callback was invoked.
last.callback(None)
return stack[0]
# Callbacks should be invoked at the same stack depth regardless of
# how many Deferreds are chained.
self.assertEqual(chainDeferreds(1), chainDeferreds(2)) | The depth of the call stack does not grow as more L{Deferred} instances
are chained together. | test_boundedStackDepth | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_resultOfDeferredResultOfDeferredOfFiredDeferredCalled(self):
"""
Given three Deferreds, one chained to the next chained to the next,
callbacks on the middle Deferred which are added after the chain is
created are called once the last Deferred fires.
This is more of a regression-style test. It doesn't exercise any
particular code path through the current implementation of Deferred, but
it does exercise a broken codepath through one of the variations of the
implementation proposed as a resolution to ticket #411.
"""
first = defer.Deferred()
second = defer.Deferred()
third = defer.Deferred()
first.addCallback(lambda ignored: second)
second.addCallback(lambda ignored: third)
second.callback(None)
first.callback(None)
third.callback(None)
L = []
second.addCallback(L.append)
self.assertEqual(L, [None]) | Given three Deferreds, one chained to the next chained to the next,
callbacks on the middle Deferred which are added after the chain is
created are called once the last Deferred fires.
This is more of a regression-style test. It doesn't exercise any
particular code path through the current implementation of Deferred, but
it does exercise a broken codepath through one of the variations of the
implementation proposed as a resolution to ticket #411. | test_resultOfDeferredResultOfDeferredOfFiredDeferredCalled | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
def test_errbackWithNoArgsNoDebug(self):
"""
C{Deferred.errback()} creates a failure from the current Python
exception. When Deferred.debug is not set no globals or locals are
captured in that failure.
"""
defer.setDebugging(False)
d = defer.Deferred()
l = []
exc = GenericError("Bang")
try:
raise exc
except:
d.errback()
d.addErrback(l.append)
fail = l[0]
self.assertEqual(fail.value, exc)
localz, globalz = fail.frames[0][-2:]
self.assertEqual([], localz)
self.assertEqual([], globalz) | C{Deferred.errback()} creates a failure from the current Python
exception. When Deferred.debug is not set no globals or locals are
captured in that failure. | test_errbackWithNoArgsNoDebug | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_defer.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.