ϪfJ- tdZddlmZddlmZmZmZmZmZm Z ddl m Z ddl mZmZddlmZddlmZmZddlmZmZdd lmZdd lmZdd lmZdd lmZd dlm Z ddl!m"Z"m!Z!e dZ#dede$de$de$dee$ddf dZ%dede$de$de$dee$ddf dZ&dede$de$de$ddf dZ'eGdd Z(Gd!d"eZ)y)#zZ Test reporter forwarding test results over trial distributed AMP commands. @since: 12.3 ) TracebackType)CallableListOptionalSequenceTypeTypeVar)TestCase)Factorydefine)Literal)Deferred maybeDeferred)AMPMAX_VALUE_LENGTH)Failure)qual)managercommands) TestResult) TrialFailure)chunkstreamTamptestName errorClasserrorframesreturnNcKt|t|jdtd{}t|d|Dd{}|j t j ||||d{y7L737 w)a/ Send an error to the worker manager over an AMP connection. First the pieces which can be large are streamed over the connection. Then, L{managercommands.AddError} is called with the rest of the information and the stream IDs. :param amp: The connection to use. :param testName: The name (or ID) of the test the error relates to. :param errorClass: The fully qualified name of the error type. :param error: The string representation of the error. :param frames: The lines of the traceback associated with the error. utf-8Nc3>K|]}|jdywr#Nencode.0frames D/usr/lib/python3/dist-packages/twisted/trial/_dist/workerreporter.py zaddError..1'R% W(='R)rr errorStreamIdframesStreamId)rrr'r callRemoterAddError)rrrrr r/r0s r+addErrorr3s}"!eELL,ACS&TUUM!#'R6'RSSN ..  #%  VS3-BA<B A> +B6B7B>BBfail failClasscKt|t|jdtd{}t|d|Dd{}|j t j ||||d{y7L737 w)a[ Like L{addError} but for failures. :param amp: See L{addError} :param testName: See L{addError} :param failClass: The fully qualified name of the exception associated with the failure. :param fail: The string representation of the failure. :param frames: The lines of the traceback associated with the error. r#Nc3>K|]}|jdywr%r&r(s r+r,zaddFailure..Jr-r.)rr6 failStreamIdr0)rrr'rr1r AddFailure)rrr5r6r r9r0s r+ addFailurer;<s} U4;;w+?AQ%RSSL!#'R6'RSSN ..""!%  TSr4todocKt|t|jdtd{}|j t j |||d{y707w)z Like L{addError} but for expected failures. :param amp: See L{addError} :param testName: See L{addError} :param error: The string representation of the expected failure. :param todo: The string description of the expectation. r#N)rr/r<)rrr'rr1rAddExpectedFailure)rrrr<r/s r+addExpectedFailurer?Usa!eELL,ACS&TUUM ..**#   Vs!-A$A *A$A"A$"A$c eZdZUdZded<eeZee e ed<de e e fdZ de eded eded fd Zd e e dd fdZy )ReportingResultsa A mutable container for the result of sending test results back to the parent process. Since it is possible for these sends to fail asynchronously but the L{TestResult} protocol is not well suited for asynchronous result reporting, results are collected on an instance of this class and when the runner believes the test is otherwise complete, it can collect the results and do something with any errors. :ivar _reporter: The L{WorkerReporter} this object is associated with. This is the object doing the result reporting. :ivar _results: A list of L{Deferred} instances representing the results of reporting operations. This is expected to grow over the course of the test run and then be inspected by the runner once the test is over. The public interface to this list is via the context manager interface. WorkerReporter _reporter_resultsr!c|jS)a Begin a new reportable context in which results can be collected. :return: A sequence which will contain the L{Deferred} instances representing the results of all test result reporting that happens while the context manager is active. The sequence is extended as the test runs so its value should not be consumed until the test is over. )rDselfs r+ __enter__zReportingResults.__enter__s}}excTypeexcValue excTracebackFc&d|j_y)z- End the reportable context. NF)rC _reporting)rGrJrKrLs r+__exit__zReportingResults.__exit__s%)!rIresultNc:|jj|y)zi Record a L{Deferred} instance representing one test result reporting operation. N)rDappend)rGrPs r+recordzReportingResults.records V$rI)__name__ __module__ __qualname____doc____annotations__r listrDrrobjectrrHr BaseExceptionrr rOrSrIr+rArAhs( '.t}Hd8F#$4 8HV$45  m$   $   %Xf-%$%rIrAceZdZUdZdZeed<dZee ed<fdZ de fdZ d e de fd Zd e deefd Zd egefddfdZdeddffd Zdede ddfdZded e ddffd Zdede ddffd ZfdZdZdfd Zdfd ZdZxZS)rBa Reporter for trial's distributed workers. We send things not through a stream, but through an C{AMP} protocol's C{callRemote} method. @ivar _DEFAULT_TODO: Default message for expected failures and unexpected successes, used only if a C{Todo} is not provided. @ivar _reporting: When a "result reporting" context is active, the corresponding context manager. Otherwise, L{None}. zTest expected to fail ampProtocolNrNc0t|||_y)z @param ampProtocol: The communication channel with the trial distributed manager which collects all test results. N)super__init__r^)rGr^ __class__s r+razWorkerReporter.__init__s &rIr!c:t||_|jS)a Get a "result reporting" context manager. In a "result reporting" context, asynchronous test result reporting methods may be used safely. Their results (in particular, failures) are available from the context manager. )rArNrFs r+gatherReportingResultsz%WorkerReporter.gatherReportingResultss+40rIrcRt|trt|d|d|dS|S)zX Convert a C{sys.exc_info()}-style tuple to a L{Failure}, if necessary. rrr) isinstancetupler)rGrs r+ _getFailurezWorkerReporter._getFailures. eU #58U1XuQx8 8 rIfailurec xg}|jD](}|j|d|dt|dg*|S)z< Extract frames from a C{Failure} instance. rrr)r extendstr)rGrir r*s r+ _getFrameszWorkerReporter._getFramessH^^ ?E MM58U1Xs58}= > ? rIfcz|j%|jjt|ytd)a Call L{f} if and only if a "result reporting" context is active. @param f: A function to call. Its result is accumulated into the result reporting context. It may return a L{Deferred} or a coroutine or synchronously raise an exception or return a result value. @raise ValueError: If no result reporting context is active. Nz9Cannot call command outside of reporting context manager.)rNrSr ValueError)rGrns r+_callzWorkerReporter._calls5 ?? & OO " "=#3 4K rItestcrt||jjfdy)z Send a success to the parent process. This must be called in context managed by L{gatherReportingResults}. cZjjtjS)N)r)r^r1r AddSuccess)rGrsr+z+WorkerReporter.addSuccess..s(D$$//**X0rIN)r` addSuccessidrq)rGrrrrbs` @r+rwzWorkerReporter.addSuccesss. 4 779   rIrerrorObjcK|j|}|j}t|j}|j |}t |j ||||d{y7w)a" Attempt to report an error to the parent process. Unlike L{addError} this can fail asynchronously. This version is for infrastructure code that can apply its own failure handling. @return: A L{Deferred} that fires with the result of the attempt. N)rhgetErrorMessagertypermr3r^)rGrryrierrorStrrr s r+addErrorFalliblezWorkerReporter.addErrorFalliblesi""8,**,',,' )           sA$A.&A,'A.cxt||jjfdy)z6 Send an error to the parent process. c(jSN)r~)rrGrsr+rvz)WorkerReporter.addError..s4005ArIN)r`r3rxrq)rGrrrrrbs` `@r+r3zWorkerReporter.addError s, u%779 ABrIr5ct|||jj|}|j t |j j|jfdy)z& Send a Failure over. c6tjSr)r;r^)r6failureMessager rGrsr+rvz+WorkerReporter.addFailure.. s!J   rIN) r`r;rxrhr{rr|rmrq) rGrrr5rir6rr rrbs ` @@@@r+r;zWorkerReporter.addFailuresj 4&779""4( 002& )   rIct|t|jj fdy)z# Send a skip over. c\jjtjS)N)rreason)r^r1rAddSkip)rrGrsr+rvz(WorkerReporter.addSkip..1s*D$$//''(60rIN)r`addSkiprlrxrq)rGrrrrrbs` `@r+rzWorkerReporter.addSkip)s8 f%V779   rIc6| |jS|jS)zj Get the reason for a C{Todo}. If C{todo} is L{None}, return a sensible default. ) _DEFAULT_TODOr)rGr<s r+_getTodoReasonzWorkerReporter._getTodoReason6s <%% %;; rIct|||j|jj fdy)z0 Send an expected failure over. cTtjjS)N)rrr<)r?r^r) errorMessagerGrr<sr+rvz3WorkerReporter.addExpectedFailure..Is*&  !"((. rIN)r`r?r{rxrq)rGrrrr<rrrbs` `@@r+r?z!WorkerReporter.addExpectedFailureAs@ "45,,. 779   rIcxt||jjfdy)z2 Send an unexpected success over. czjjtjj S)N)rr<)r^r1rAddUnexpectedSuccessr)rGrr<sr+rvz5WorkerReporter.addUnexpectedSuccess..Xs7D$$//44!((.0rIN)r`addUnexpectedSuccessrxrq)rGrrr<rrbs` `@r+rz#WorkerReporter.addUnexpectedSuccessQs0 $T40779   rIcy)z* I{Don't} print a summary Nr\rFs r+ printSummaryzWorkerReporter.printSummary_srIr) rTrUrVrWrrrXrNrrArardrrrhrrlrmrrrqPyUnitTestCaserwr~r3r;rrr?rr __classcell__)rbs@r+rBrBs ,M-1J)*1' (8 ' ' d3i xA4$  ~  $   s l t *C^CLCTC ~ \ d (      rIrB)*rWtypesrtypingrrrrrr unittestr rattrsr r r twisted.internet.deferrrtwisted.protocols.amprrtwisted.python.failurertwisted.python.reflectrtwisted.trial._distrtwisted.trial.reporterrreporterrrrrrlr3r;r?rArBr\rIr+rs   DD/!:7*'/-#! CL ),58BFs) : #&36@DS  2#SPT&5%5%5%pA ZA rI