Ϫf1dZ ddlZddlmZddlmZddlmZddl m Z ddl m Z ddl mZmZGd d ZGd d e Zej'ej)y#e$rdZYiwxYw) z6 Tests for implementations of L{IReactorWin32Events}. N) verifyObject)Deferred)IReactorWin32Events)ReactorBuilder)Failure) getThreadID isInIOThreadcDeZdZdZdZdxZxZZdZdZ dZ dZ dZ d Z y) Listenera 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. FNc||_yN) _finished)selffinisheds H/usr/lib/python3/dist-packages/twisted/internet/test/test_win32events.py__init__zListener.__init__/s !c"t|_y)Nr )r logThreadIDrs r logPrefixzListener.logPrefix2s&=rcfd|_t|_|jj dy)NT)successr eventThreadIDrcallbackrs roccurredzListener.occurred6s% (] %rctd)Nz Some problem) RuntimeErrorrs rbrokenOccurredzListener.brokenOccurred;s >**rctdS)NzEntirely different problem)EnvironmentErrorrs rreturnValueOccurredzListener.returnValueOccurred>s <==rcXt|_|jj|yr )rconnLostThreadIDrerrback)rreasons rconnectionLostzListener.connectionLostAs +  v&r)__name__ __module__ __qualname____doc__rrrr$rrrrr"r'rrr r s<*G599K9-"2"& +>'rr c:eZdZdZegZdZdZdZdZ dZ dZ y) Win32EventsTestsBuilderzD Builder defining tests relating to L{IReactorWin32Events}. cD|j}tt|y)zn An instance of the reactor has all of the methods defined on L{IReactorWin32Events}. N) buildReactorrr)rreactors rtest_interfacez&Win32EventsTestsBuilder.test_interfaceMs ##%('2rct}|jtjdddd}t }|j fdt |}j||djtj||j|j|j|j||j|j||jy)z When an event which has been added to the reactor is set, the action associated with the event is invoked in the reactor thread. NFc$jSr stopignoredr1s rz7Win32EventsTestsBuilder.test_addEvent..^s W\\^rr)rr0 win32event CreateEventr addCallbackr addEventcallWhenRunningSetEvent runReactor assertTruer assertEqualrr)rreactorThreadIDeventrlistenerr1s @r test_addEventz%Win32EventsTestsBuilder.test_addEventUs &-##%&&tUE4@:;<H%*5 3 3U;   (() (*>*>? (*@*@Arcgfd}|jtjdddd}t}t |}|j |j ||djtj||j|j|j|jdgy)z{ Using L{IReactorWin32Events.addEvent} does not change which thread is reported as the I/O thread. cXjtjyr )appendr r6)r8r1resultss rcheckzAWin32EventsTestsBuilder.test_ioThreadDoesNotChange..checkns NN<> * LLNrNFrT) r0r:r;rr r<r=r>r?r@rArrB)rrKrDrrEr1rJs @@rtest_ioThreadDoesNotChangez2Win32EventsTestsBuilder.test_ioThreadDoesNotChangegs  ##%&&tUE4@:H%U#*5 3 3U;   (() $)rctt}|jtjdddd}g}t }|j |j |j fdt|}j||djtj||j|j|dt|djt|j!||j"|j!dt%|j'ty)z 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. NFc$jSr r5r7s rr9zBWin32EventsTestsBuilder.test_disconnectedOnError.. rrr)rr0r:r;raddBothrIr r=r>r?r@assertIsInstancertraprrBr$lenflushLoggedErrorsrrCrDresultrrEr1s @rtest_disconnectedOnErrorz0Win32EventsTestsBuilder.test_disconnectedOnError}s &-##%&&tUE4@:'78H%*:; 3 3U;   fQi1q |$ (*C*CD C 6 6| DEFrct}|jtjdddd}g}t }|j |j |j fdt|}j||djtj||j|j|dt|djt|j!||j"y)z 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. NFc$jSr r5r7s rr9zFWin32EventsTestsBuilder.test_disconnectOnReturnValue..rOrr"r)rr0r:r;rrQrIr r=r>r?r@rRrrSr!rBr$rVs @rtest_disconnectOnReturnValuez4Win32EventsTestsBuilder.test_disconnectOnReturnValues &-##%&&tUE4@:'78H%*?@ 3 3U;   fQi1q '( (*C*CDrc2|j}tjdddd}t}t |}|j ||d|j |j|j||j|jy)z 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. NFr) r0r:r;rr r=r>r6r@ assertIsNoner$)rr1rDrrEs rtest_notDisconnectedOnShutdownz6Win32EventsTestsBuilder.test_notDisconnectedOnShutdowns} ##%&&tUE4@:H%*5 -   (334rN) r(r)r*r+rrequiredInterfacesr2rFrLrXr[r^r,rrr.r.Fs3..3B$*,G4E2 5rr.)r+r: ImportErrorzope.interface.verifyrtwisted.internet.deferrtwisted.internet.interfacesr#twisted.internet.test.reactormixinsrtwisted.python.failurertwisted.python.threadablerr r r.globalsupdatemakeTestCaseClassesr,rrrjss/+;>*?-'-'`w5nw5t (<<>?mJsA((A21A2