σ …\tPc@`sŽdZddlmZmZddlZddlmZddlmZddl m Z m Z de fd„ƒYZ d efd „ƒYZdS( s& Test code for basic Factory classes. i(tdivisiontabsolute_importN(tTestCase(tClock(tReconnectingClientFactorytProtocolt FakeConnectorcB`s eZdZd„Zd„ZRS(sP A fake connector class, to be used to mock connections failed or lost. cC`sdS(N((tself((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pytstopConnectingscC`sdS(N((R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pytconnects(t__name__t __module__t__doc__RR (((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyRs tReconnectingFactoryTestCasecB`sDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s1 Tests for L{ReconnectingClientFactory}. cC`sfdtfd„ƒY}tƒ}t|_|jdƒ|jƒ|j|ƒdƒ|j|j ƒdS(sΒ If a L{ReconnectingClientFactory} has C{stopTrying} called while it is connected, it does not subsequently attempt to reconnect if the connection is later lost. tNoConnectConnectorcB`seZd„Zd„ZRS(cS`stdƒ‚dS(Ns%Shouldn't be called, we're connected.(t RuntimeError(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR,scS`stdƒ‚dS(NsShouldn't be reconnecting.(R(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR .s(R R RR (((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR+s N( tobjectRRtprotocolt buildProtocoltNonet stopTryingtclientConnectionLostt assertFalsetcontinueTrying(RRtc((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyttest_stopTryingWhenConnected%s    c`stdtf‡fd†ƒY}tƒ‰tƒˆ_|ƒˆ_ˆjƒ|jˆjjƒ|jˆjjƒƒdS(s Calling stopTrying on a L{ReconnectingClientFactory} doesn't attempt a retry on any active connector. tFactoryAwareFakeConnectorc`s&eZeZ‡fd†Zd„ZRS(c`sˆj|dƒdS(s Behave as though an ongoing connection attempt has now failed, and notify the factory of this. N(tclientConnectionFailedR(R(tf(s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyRCscS`s t|_dS(s| Record an attempt to reconnect, since this is what we are trying to avoid. N(tTruetattemptedRetry(R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR Js(R R tFalseRRR ((R(s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR@sN( RRRtclockt connectorRRRtgetDelayedCalls(RR((Rs?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyttest_stopTryingDoesNotReconnect;s    cC`s;tƒ}tjtj|ƒƒ}|j|j|jƒdS(s™ A L{ReconnectingClientFactory} which hasn't been used for anything can be pickled and unpickled and end up with the same state. N(Rtpickletloadstdumpst assertEqualt__dict__(Rtoriginalt reconstituted((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyttest_serializeUnused^s cC`sJtƒ}tƒ}||_tjtj|ƒƒ}|j|jdƒdS(s’ The clock attribute of L{ReconnectingClientFactory} is not serialized, and the restored value sets it to the default value, the reactor. N(RRR R$R%R&tassertIdenticalR(RR R)R*((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyttest_serializeWithClockhs    cC`s°tƒ}|jtƒdƒ|j|jƒtj|ƒ}tj|ƒ}|j |j dƒ|j |j dƒ|j |j dƒ|j |j |jƒ|j |jtƒdS(sΌ A L{ReconnectingClientFactory} which is unpickled does not have an L{IConnector} and has its reconnecting timing parameters reset to their initial values. iN(RRRRt addCleanupRR$R&R%R'R!t_callIDtretriestdelayt initialDelayRR(Rtfactoryt serializedt unserialized((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyt$test_deserializationResetsParametersts cC`sKtƒ}tƒ}||_|jtƒdƒ|jt|jƒdƒdS(s‰ The clock used by L{ReconnectingClientFactory} can be parametrized, so that one can cleanly test reconnections. iN( RRR RRRR'tlentcalls(RR R3((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyttest_parametrizedClock‡s    ( R R R RR#R+R-R6R9(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyR s  # (R t __future__RRR$ttwisted.trial.unittestRttwisted.internet.taskRttwisted.internet.protocolRRRRR (((s?/usr/lib/python2.7/dist-packages/twisted/test/test_factories.pyts