Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/internet/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyc


6Mc@sdZddlmZyddlZWnek
r?dZnXddlmZddlm	Z	ddl
mZddlm
Z
ddlmZd	efd
YZdefdYZejejdS(
s6
Tests for implementations of L{IReactorWin32Events}.
i(t	get_identN(tverifyObject(tisInIOThread(tIReactorWin32Events(tDeferred(tReactorBuildertListenercBsXeZdZeZdZZZdZ	dZ
dZdZdZ
dZRS(s
    L{Listener} is an object that can be added to a L{IReactorWin32Events}
    reactor to receive callback notification when a Windows event is set.  It
    records what thread its callback is invoked in and fires a Deferred.

    @ivar success: A flag which is set to C{True} when the event callback is
        called.

    @ivar logThreadID: The id of the thread in which the C{logPrefix} method is
        called.

    @ivar eventThreadID: The id of the thread in which the event callback is
        called.

    @ivar connLostThreadID: The id of the thread in which the C{connectionLost}
        method is called.

    @ivar _finished: The L{Deferred} which will be fired when the event callback
        is called.
    cCs
||_dS(N(t	_finished(tselftfinished((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyt__init__/scCst|_dS(NR(RtlogThreadID(R((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyt	logPrefix3scCs)t|_t|_|jjddS(N(tTruetsuccessRt
eventThreadIDRtcallbacktNone(R((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pytoccurred8s	cCstddS(NsSome problem(tRuntimeError(R((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pytbrokenOccurred>scCs
tdS(NsEntirely different problem(tEnvironmentError(R((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pytreturnValueOccurredBscCs t|_|jj|dS(N(RtconnLostThreadIDRterrback(Rtreason((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pytconnectionLostFsN(t__name__t
__module__t__doc__tFalseRRRRRR
RRRRR(((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyRs					tWin32EventsTestsBuildercBsMeZdZegZdZdZdZdZdZ	dZ
RS(sD
    Builder defining tests relating to L{IReactorWin32Events}.
    cCs|j}tt|dS(sn
        An instance of the reactor has all of the methods defined on
        L{IReactorWin32Events}.
        N(tbuildReactorRR(Rtreactor((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyttest_interfaceRscst}|jtjdttd}t}|jfdt|}j	||dj
tj||j|j
|j|j||j|j||jdS(s
        When an event which has been added to the reactor is set, the action
        associated with the event is invoked in the reactor thread.
        cs
jS(N(tstop(tignored(R!(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyt<lambda>dsRN(RR t
win32eventtCreateEventRRRtaddCallbackRtaddEventtcallWhenRunningtSetEventt
runReactort
assertTrueRtassertEqualRR(RtreactorThreadIDteventR	tlistener((R!sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyt
test_addEvent[s		
csgfd}|jtjdttd}t}t|}|j|j||dj	tj
||j|j|j
|jtgdS(s{
        Using L{IReactorWin32Events.addEvent} does not change which thread is
        reported as the I/O thread.
        csjtjdS(N(tappendRR#(R$(R!tresults(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pytchecktsRN(R R&R'RRRRR(R)R*R+R,R-RR.R
(RR5R0R	R1((R!R4sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyttest_ioThreadDoesNotChangens	

cst}|jtjdttd}|jtt}|j	fdt
|}j||djtj
||j|j||j|jdt|jtdS(s
        If the event handler raises an exception, the event is removed from the
        reactor and the handler's C{connectionLost} method is called in the I/O
        thread and the exception is logged.
        cs
jS(N(R#(R$(R!(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyR%sRiN(RR R&R'RRt
assertFailureRRR(RR)R*R+R,R.RtlentflushLoggedErrors(RR/R0R	R1((R!sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyttest_disconnectedOnErrors	
cst}|jtjdttd}|jtt}|j	fdt
|}j||djtj
||j|j||jdS(s
        If the event handler returns a value, the event is removed from the
        reactor and the handler's C{connectionLost} method is called in the I/O
        thread.
        cs
jS(N(R#(R$(R!(sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyR%sRN(RR R&R'RRR7RRR(RR)R*R+R,R.R(RR/R0R	R1((R!sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyttest_disconnectOnReturnValues	
cCs|j}tjdttd}t}t|}|j||d|j|j	|j
||jd|jdS(s
        Event handlers added with L{IReactorWin32Events.addEvent} do not have
        C{connectionLost} called on them if they are still active when the
        reactor shuts down.
        RN(
R R&R'RRRRR)R*R#R,tassertIdenticalR(RR!R0R	R1((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyttest_notDisconnectedOnShutdowns	
(RRRRtrequiredInterfacesR"R2R6R:R;R=(((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyRLs							(RtthreadRR&tImportErrorRtzope.interface.verifyRttwisted.python.threadableRttwisted.internet.interfacesRttwisted.internet.deferRt#twisted.internet.test.reactormixinsRtobjectRRtglobalstupdatetmakeTestCaseClasses(((sJ/usr/lib/python2.7/dist-packages/twisted/internet/test/test_win32events.pyt<module>s

5k