
    hp              	         % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJr  SSKJrJrJrJrJrJr  SSKJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKJ r   SSK!J"r"J#r#  \(       a  SSK$J%r%   SSK&J'r'  \\\)   \)\4   r*S\+S'   \\*\S   4   r,\\,\4   r-S8S jr. " S S\/5      r0 " S S5      r1\" \"Rd                  5       " S S\Rf                  5      5       r3\" \"Rd                  5       " S S\" \"Rd                  S5      5      5       r4\" \"Rd                  5       " S S\45      5       r5\" \"Rd                  5       " S  S!\45      5       r6 " S" S#\45      r7\" \"Rd                  5       " S$ S%\35      5       r8 " S& S'\85      r9 " S( S)\85      r: " S* S+\85      r; " S, S-\;5      r< " S. S/5      r= " S0 S15      r> " S2 S35      r?\" \"Rd                  5       " S4 S55      5       r@ " S6 S7\85      rAg! \( a    Sr' GNf = f)9z3
Defines classes that handle the results of tests.
    )annotationsN)OrderedDict)TracebackType)TYPE_CHECKINGListOptionalTupleTypeUnion)implementer)	TypeAlias)logreflect)proxyForInterface)Failure)untilConcludes)itrialutil   )Todo)TestProtocolClientr   ExcInfo)NNNc                    SSK Jn  U" U 5      $ )aH  
Return a L{Todo} object built from C{value}.

This is a synonym for L{twisted.trial.unittest.makeTodo}, but imported
locally to avoid circular imports.

@param value: A string or a tuple of C{(errors, reason)}, where C{errors}
is either a single exception class or an iterable of exception classes.

@return: A L{Todo} object.
r   )makeTodo)twisted.trial.unittestr   )valuer   s     ]/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/trial/reporter.py	_makeTodor   ,   s     0E?    c                      \ rS rSrSrSrg)BrokenTestCaseWarning=   zL
Emitted as a warning when an exception occurs in one of setUp or tearDown.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r#   r   r   r!   r!   =   s    r   r!   c                  *    \ rS rSrSrS rS rS rSrg)
SafeStreamC   zx
Wraps a stream object so that all C{write} calls are wrapped in
L{untilConcludes<twisted.python.util.untilConcludes>}.
c                    Xl         g Noriginal)selfr1   s     r   __init__SafeStream.__init__I   s     r   c                .    [        U R                  U5      $ r/   )getattrr1   )r2   names     r   __getattr__SafeStream.__getattr__L   s    t}}d++r   c                H    [        U R                  R                  /UQ70 UD6$ r/   )r   r1   write)r2   akws      r   r;   SafeStream.writeO   s!    dmm11<A<<<r   r0   N)	r%   r&   r'   r(   r)   r3   r8   r;   r*   r#   r   r   r,   r,   C   s    
!,=r   r,   c                     ^  \ rS rSr% SrSrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   SrU 4S jrSS jr	S r
S rU 4S jrU 4S jrS rS rS rSS jrSS jrS rS rS rSrU =r$ ) 
TestResultS   a  
Accumulates the results of several L{twisted.trial.unittest.TestCase}s.

@ivar successes: count the number of successes achieved by the test run.
@type successes: C{int}

@ivar _startTime: The time when the current test was started. It defaults to
L{None}, which means that the test was skipped.
@ivar _lastTime: The duration of the current test run. It defaults to
L{None}, which means that the test was skipped.
zTest expected to failz"List[Tuple[itrial.ITestCase, str]]skipsz*List[Tuple[itrial.ITestCase, str, 'Todo']]expectedFailuresunexpectedSuccessesint	successeszOptional[int]_testStarted	_lastTimeFc                   > [         TU ]  5         / U l        / U l        / U l        SU l        / U l        S U l        S U l        g )Nr   )	superr3   rB   rC   rD   rF   _timingsrG   rH   )r2   	__class__s    r   r3   TestResult.__init__o   sB    
 "#%  r   c           
     (   S[         R                  " U R                  5      U R                  [	        U R
                  5      [	        U R                  5      [	        U R                  5      [	        U R                  5      [	        U R                  5      4-  $ )Nz<<%s run=%d errors=%d failures=%d todos=%d dones=%d skips=%d>)
r   qualrL   testsRunlenerrorsfailuresrC   rB   rD   r2   s    r   __repr__TestResult.__repr__y   sk    MLL(MM%%&

O(()Q
 
 	
r   c                ,    [         R                   " 5       $ r/   )timerT   s    r   _getTimeTestResult._getTime   s    yy{r   c                    [        U[        5      =(       a    [        U5      S:H  nU(       a  [        US   US   US   5      $ [        U[        5      (       a  U$ [	        SU S35      e)zH
Convert a C{sys.exc_info()}-style tuple to a L{Failure}, if necessary.
   r   r      zCannot convert z to a Failure)
isinstancetuplerQ   r   	TypeError)r2   erroris_exc_info_tuples      r   _getFailureTestResult._getFailure   sb     'ue4HUq58U1XuQx88w''L/%>??r   c                N   > [         TU ]  U5        U R                  5       U l        g)zY
This must be called before the given test is commenced.

@type test: L{pyunit.TestCase}
N)rJ   	startTestrY   rG   r2   testrL   s     r   rf   TestResult.startTest   s      	$ MMOr   c                   > [         TU ]  U5        U R                  b#  U R                  5       U R                  -
  U l        gg)zX
This must be called after the given test is completed.

@type test: L{pyunit.TestCase}
N)rJ   stopTestrG   rY   rH   rg   s     r   rk   TestResult.stopTest   s;     	(!]]_t/@/@@DN )r   c                Z    U R                   R                  XR                  U5      45        g)zr
Report a failed assertion for the given test.

@type test: L{pyunit.TestCase}
@type fail: L{Failure} or L{tuple}
N)rS   appendrc   )r2   rh   fails      r   
addFailureTestResult.addFailure   s$     	d$4$4T$:;<r   c                Z    U R                   R                  XR                  U5      45        g)z
Report an error that occurred while running the given test.

@type test: L{pyunit.TestCase}
@type error: L{Failure} or L{tuple}
N)rR   rn   rc   r2   rh   ra   s      r   addErrorTestResult.addError   s$     	D"2"25"9:;r   c                <    U R                   R                  X45        g)z
Report that the given test was skipped.

In Trial, tests can be 'skipped'. Tests are skipped mostly because
there is some platform or configuration issue that prevents them from
being run correctly.

@type test: L{pyunit.TestCase}
@type reason: L{str}
N)rB   rn   )r2   rh   reasons      r   addSkipTestResult.addSkip   s     	

4.)r   c                l    Uc  [        U R                  5      nU R                  R                  X45        g)a|  
Report that the given test succeeded against expectations.

In Trial, tests can be marked 'todo'. That is, they are expected to
fail.  When a test that is expected to fail instead succeeds, it should
call this method to report the unexpected success.

@type test: L{pyunit.TestCase}
@type todo: L{unittest.Todo}, or L{None}, in which case a default todo
    message is provided.
N)r   _DEFAULT_TODOrD   rn   r2   rh   todos      r   addUnexpectedSuccessTestResult.addUnexpectedSuccess   s/     <T//0D  ''5r   c                n    Uc  [        U R                  5      nU R                  R                  XU45        g)a"  
Report that the given test failed, and was expected to do so.

In Trial, tests can be marked 'todo'. That is, they are expected to
fail.

@type test: L{pyunit.TestCase}
@type error: L{Failure}
@type todo: L{unittest.Todo}, or L{None}, in which case a default todo
    message is provided.
N)r   r{   rC   rn   )r2   rh   ra   r}   s       r   addExpectedFailureTestResult.addExpectedFailure   s2     <T//0D$$d4%89r   c                .    U =R                   S-  sl         g)zG
Report that the given test succeeded.

@type test: L{pyunit.TestCase}
r   N)rF   r2   rh   s     r   
addSuccessTestResult.addSuccess   s     	!r   c                x    [        U R                  5      [        U R                  5      s=:H  =(       a    S:H  $ s  $ )a  
Report whether or not this test suite was successful or not.

The behaviour of this method changed in L{pyunit} in Python 3.4 to
fail if there are any errors, failures, or unexpected successes.
Previous to 3.4, it was only if there were errors or failures. This
method implements the old behaviour for backwards compatibility reasons,
checking just for errors and failures.

@rtype: L{bool}
r   )rQ   rS   rR   rT   s    r   wasSuccessfulTestResult.wasSuccessful   s/     4==!S%5::::::r   c                    g)z&
The test suite has finished running.
Nr#   rT   s    r   doneTestResult.done       r   )rH   rG   rK   rC   rB   rF   rD   )returnstrr/   )r%   r&   r'   r(   r)   r{   __annotations____test__r3   rU   rY   rc   rf   rk   rp   rt   rx   r~   r   r   r   r   r*   __classcell__rL   s   @r   r@   r@   S   s    
 ,M--@@;;N H	
	@,A=<*6 : ; r   r@   c                      \ rS rSrSrSrg)TestResultDecorator   z
Base class for TestResult decorators.

@ivar _originalReporter: The wrapped instance of reporter.
@type _originalReporter: A provider of L{itrial.IReporter}
r#   Nr$   r#   r   r   r   r      s    r   r   _originalReporterc                      \ rS rSrSrS rSrg)UncleanWarningsReporterWrapperi  zY
A wrapper for a reporter that converts L{util.DirtyReactorAggregateError}s
to warnings.
c                    [        U[        5      (       aI  UR                  [        R                  5      (       a%  [
        R                  " UR                  5       5        gU R                  R                  X5        g)zs
If the error is a L{util.DirtyReactorAggregateError}, instead of
reporting it as a normal error, throw a warning.
N)
r^   r   checkr   DirtyReactorAggregateErrorwarningswarngetErrorMessager   rt   rs   s      r   rt   'UncleanWarningsReporterWrapper.addError  sN     eW%%%++d6U6U*V*VMM%//12""++D8r   r#   N)r%   r&   r'   r(   r)   rt   r*   r#   r   r   r   r     s    
	9r   r   c                  $    \ rS rSrSrS rS rSrg)_ExitWrapperi  zU
A wrapper for a reporter that causes the reporter to stop after
unsuccessful tests.
c                H    SU l         U R                  R                  " U0 UD6$ NT)
shouldStopr   rt   r2   argskwargss      r   rt   _ExitWrapper.addError&  s%    %%..???r   c                H    SU l         U R                  R                  " U0 UD6$ r   )r   r   rp   r   s      r   rp   _ExitWrapper.addFailure*  s%    %%00$A&AAr   )r   N)r%   r&   r'   r(   r)   rt   rp   r*   r#   r   r   r   r     s    
@Br   r   c                  P    \ rS rSrSrS rS rSS jrS rS r	SS	 jr
S
 rS rSrg)_AdaptedReporteri/  z{
TestResult decorator that makes sure that addError only gets tests that
have been adapted with a particular test adapter.
c                :    [         R                  X5        X l        g)z
Construct an L{_AdaptedReporter}.

@param original: An {itrial.IReporter}.
@param testAdapter: A callable that returns an L{itrial.ITestCase}.
N)r   r3   testAdapter)r2   r1   r   s      r   r3   _AdaptedReporter.__init__5  s     	$$T4&r   c                Z    U R                  U5      nU R                  R                  X5      $ z
See L{itrial.IReporter}.
)r   r   rt   rs   s      r   rt   _AdaptedReporter.addError?  s+     %%%..t;;r   Nc                X    U R                   R                  U R                  U5      X#5      $ )a4  
See L{itrial.IReporter}.

@type test: A L{pyunit.TestCase}.
@type failure: A L{failure.Failure} or L{AssertionError}
@type todo: A L{unittest.Todo} or None

When C{todo} is L{None} a generic C{unittest.Todo} is built.

L{pyunit.TestCase}'s C{run()} calls this with 3 positional arguments
(without C{todo}).
)r   r   r   )r2   rh   failurer}   s       r   r   #_AdaptedReporter.addExpectedFailureF  s-     %%88T"G
 	
r   c                Z    U R                  U5      nU R                  R                  X5      $ r   )r   r   rp   )r2   rh   r   s      r   rp   _AdaptedReporter.addFailureW  s+     %%%00??r   c                Z    U R                  U5      nU R                  R                  X5      $ r   )r   r   rx   )r2   rh   skips      r   rx   _AdaptedReporter.addSkip^  s+     %%%--d99r   c                Z    U R                  U5      nU R                  R                  X5      $ )z
See L{itrial.IReporter}.

@type test: A L{pyunit.TestCase}.
@type todo: A L{unittest.Todo} or None

When C{todo} is L{None} a generic C{unittest.Todo} is built.

L{pyunit.TestCase}'s C{run()} calls this with 2 positional arguments
(without C{todo}).
)r   r   r~   r|   s      r   r~   %_AdaptedReporter.addUnexpectedSuccesse  s+     %%%::4FFr   c                V    U R                   R                  U R                  U5      5      $ r   )r   rf   r   r   s     r   rf   _AdaptedReporter.startTestt  s&     %%//0@0@0FGGr   c                V    U R                   R                  U R                  U5      5      $ r   )r   rk   r   r   s     r   rk   _AdaptedReporter.stopTestz  s&     %%..t/?/?/EFFr   )r   r/   )r%   r&   r'   r(   r)   r3   rt   r   rp   rx   r~   rf   rk   r*   r#   r   r   r   r   /  s3    
'<
"@:GHGr   r   c                     ^  \ rS rSrSrSrSr\R                  SSS4U 4S jjr	S	 r
U 4S
 jrU 4S jrU 4S jrS rS rSU 4S jjrU 4S jrS rS rS rS rS rS rS rS rS rS rSrU =r$ )Reporteri  a  
A basic L{TestResult} with support for writing to a stream.

@ivar _startTime: The time when the first test was started. It defaults to
    L{None}, which means that no test was actually launched.
@type _startTime: C{float} or L{None}

@ivar _warningCache: A C{set} of tuples of warning message (file, line,
    text, category) which have already been written to the output stream
    during the currently executing test.  This is used to avoid writing
    duplicates of the same warning to the output stream.
@type _warningCache: C{set}

@ivar _publisher: The log publisher which will be observed for warning
    events.
@type _publisher: L{twisted.python.log.LogPublisher}
zO-------------------------------------------------------------------------------zO===============================================================================defaultFNc                   > [         TU ]  5         [        U5      U l        X l        X0l        S U l        [        5       U l        X@l	        Ub  UR                  U R                  5        g g r/   )rJ   r3   r,   _streamtbformatrealtime
_startTimeset_warningCache
_publisheraddObserver_observeWarnings)r2   streamr   r   	publisherrL   s        r   r3   Reporter.__init__  s]     	!&)   U $ !!$"7"78 !r   c                    SU;   aw  US   US   US   R                  S5      S   [        US   5      4nX R                  ;  a:  U R                  R                  U5        U R                  R                  SU-  5        ggg)	aD  
Observe warning events and write them to C{self._stream}.

This method is a log observer which will be registered with
C{self._publisher.addObserver}.

@param event: A C{dict} from the logging system.  If it has a
    C{'warning'} key, a logged warning will be extracted from it and
    possibly written to C{self.stream}.
warningfilenamelinenocategory.z%s:%s: %s: %s
N)splitr   r   addr   r;   )r2   eventkeys      r   r   Reporter._observeWarnings  s     j!hj!'',R0E)$%	C ,,,""&&s+""#4s#:; - r   c                   > [         TU ]  U5        U R                  c  U R                  5       U l        [	        5       U l        g)z
Called when a test begins to run. Records the time when it was first
called and resets the warning cache.

@param test: L{ITestCase}
N)rJ   rf   r   rY   r   r   rg   s     r   rf   Reporter.startTest  s3     	$??""mmoDO Ur   c                   > [         TU ]  X5        U R                  (       a3  U R                  S   S   nU R	                  U R                  U5      5        gg)z
Called when a test fails. If C{realtime} is set, then it prints the
error to the stream.

@param test: L{ITestCase} that failed.
@param fail: L{failure.Failure} containing the error.
r   r   N)rJ   rp   r   rS   _write_formatFailureTraceback)r2   rh   ro   rL   s      r   rp   Reporter.addFailure  sH     	4&====$Q'DKK44T:; r   c                   > U R                  U5      n[        TU ]	  X5        U R                  (       a3  U R                  S   S   nU R                  U R                  U5      5        gg)z
Called when a test raises an error. If C{realtime} is set, then it
prints the error to the stream.

@param test: L{ITestCase} that raised the error.
@param error: L{failure.Failure} containing the error.
r   r   N)rc   rJ   rt   r   rR   r   r   )r2   rh   ra   rL   s      r   rt   Reporter.addError  sW       '%==KKOA&EKK44U;< r   c                   [        U5      n[        U[         5      (       d   eU(       a  U R                  R                  X2-  5        OU R                  R                  U5        [	        U R                  R
                  5        g)z
Safely write to the reporter's stream.

@param format: A format string to write.
@param args: The arguments for the format string.
N)r   r^   r   r;   r   flush)r2   formatr   ss       r   r   Reporter._write  s[     K!S!!!!LLqx(LLq!t||))*r   c                L    U R                   " U/UQ76   U R                  S5        g)z
Safely write a line to the reporter's stream. Newline is appended to
the format string.

@param format: A format string to write.
@param args: The arguments for the format string.

N)r   )r2   r   r   s      r   _writelnReporter._writeln  s!     	F"T"Dr   c                   > [         TU ]  XX45        U(       aT  U R                  U5      n[        R                  " U5        SR                  UU5      n[        R                  " U[        SS9  g g )Nz3caught exception in {}, your TestCase is broken

{}r]   )
stacklevel)	rJ   upDownErrorr   r   msgr   r   r   r!   )r2   methodra   r   printStatustbStrr   rL   s          r   r   Reporter.upDownError  s^    F4=007EGGENIPPC MM#4C r   c                   > [         TU ]  U5        [        R                  " S< SU R	                  U5      < 3[
        5        g )Nz&REACTOR UNCLEAN! traceback(s) follow: r   )rJ   cleanupErrorsr   r   r   r!   r2   errsrL   s     r   r   Reporter.cleanupErrors	  s9    d# 9,,T2
 "	
r   c           
     L   [        U5      n[        U5      S:  a  U$ USS  Vs/ s HJ  nUS   [        R                  R	                  [        R                  R                  US   5      5      S   4PML     nnSS/n/ SQn/ SQnU Hx  n[        R                  R	                  [        R                  R                  US   5      5      S   nUS	:X  d  MM  US   S
:X  d  MX  UR                  UR                  U5      5        Mz     USS U:X  a  USS nOUSS U:X  a  USS nOUSS U:X  a  USS nU(       d  U$ US   nUS   R                  S5      (       aK  [        R                  R	                  [        R                  R                  US   5      5      S   S:X  a  USS nU$ s  snf )a  
Trim frames to remove internal paths.

When a C{SynchronousTestCase} method fails synchronously, the stack
looks like this:
 - [0]: C{TestCase._run}
 - [1]: C{util.runWithWarningsSuppressed}
 - [2:-2]: code in the test method which failed
 - [-1]: C{_synctest.fail}

When a C{TestCase} method fails synchronously, the stack looks like
this:
 - [0]: C{TestCase._deferSetUpAndRun}
 - [1]: C{defer.__iter__}
 - [2]: C{defer.raiseException}
 - [3]: C{defer.maybeDeferred}
 - [4]: C{utils.runWithWarningsSuppressed}
 - [5]: C{utils.runWithWarningsSuppressed}
 - [6:-2]: code in the test method which failed
 - [-1]: C{_synctest.fail}

When a method fails inside a C{Deferred} (i.e., when the test method
returns a C{Deferred}, and that C{Deferred}'s errback fires), the stack
captured inside the resulting C{Failure} looks like this:

 - [0]: C{defer._deferSetUpAndRun}
 - [1]: C{defer.__iter__}
 - [2]: C{defer.Deferred._runCallbacks}
 - [3:-2]: code in the testmethod which failed
 - [-1]: C{_synctest.fail}

As a result, we want to trim either
[deferTestMethod, __iter__, raiseException, maybeDeferred, runWWS, runWWS] or
[defer.deferTestMethod, __iter__, Deferred._runCallbacks] or
[SynchronousTestCase._run, runWWS] from the front, and trim the [unittest.fail]
from the end.

There is also another case, when the test method is badly defined and
contains extra arguments.

If it doesn't recognize one of these cases, it just returns the
original frames.

@param frames: The C{list} of frames from the test failure.

@return: The C{list} of frames to display.
r\   Nr   r   )_run	_synctest)runWithWarningsSuppressedr   )_deferSetUpAndRun
_asynctest__iter__defer)raiseExceptionr   )r   r  )_runCallbacksr  compatreraiser]      r   ro   r   )	listrQ   ospathsplitextbasenamepopindex
startswith)	r2   frames	newFramesframesyncCase	asyncCase	deferCase	frameFilelasts	            r   _trimFramesReporter._trimFrames  s   ` L	v;? #2A
& 1Xrww''(8(8q(BCAFG& 	 

 *+PQ
	

	 E(()9)9%()CDQGIH$qY)>iooe45	  "1:!!!"IBQZ9$!!"IBQZ9$!!"I }Gv&&  !1!1$q'!:;A>+M!#2IW
s   AF!c                    [        U[        5      (       a  UR                  5       S-   $ U R                  UR                  5      UR                  sUl        nUR                  U R                  SS9nX!l        U$ )Nr   T)detailelideFrameworkCode)r^   r   rstripr  r  getTracebackr   )r2   ro   r  results       r   r    Reporter._formatFailureTracebackv  sd    dC  ;;=4''"..t{{;T[[V""$--D"Qr   c                    [        5       nU H3  nUS   nUSS nU" U6 nUR                  U/ 5      R                  U5        M5     [        UR	                  5       5      $ )a  
Group tests together based on their results.

@param results: An iterable of tuples of two or more elements.  The
    first element of each tuple is a test case.  The remaining
    elements describe the outcome of that test case.

@param formatter: A callable which turns a test case result into a
    string.  The elements after the first of the tuples in
    C{results} will be passed as positional arguments to
    C{formatter}.

@return: A C{list} of two-tuples.  The first element of each tuple
    is a unique string describing one result from at least one of
    the test cases in C{results}.  The second element is a list of
    the test cases which had that result.
r   r   N)r   
setdefaultrn   r  items)r2   results	formattergroupscontentcaseoutcomer   s           r   _groupResultsReporter._groupResults~  sa    $ G1:DabkGW%Cc2&--d3	 
 FLLN##r   c                $   U R                  X#5       H{  u  pEU R                  U R                  5        U R                  U5        U R                  U5        U R                  S5        U H"  nU R                  UR	                  5       5        M$     M}     g)a  
Print a group of errors to the stream.

@param flavor: A string indicating the kind of error (e.g. 'TODO').
@param errors: A list of errors, often L{failure.Failure}s, but
    sometimes 'todo' errors.
@param formatter: A callable that knows how to format the errors.
 N)r-  r   _doubleSeparatorr   id)r2   flavorrR   r(  rw   casesr+  s          r   _printResultsReporter._printResults  sn     "//BMFMM$//0MM&!KKMM"dggi(  Cr   c                X    SR                  UR                  U R                  U5      5      $ )NzReason: {!r}
{})r   rw   r   )r2   ra   r}   s      r   _printExpectedFailureReporter._printExpectedFailure  s)    !((KK55e<
 	
r   c                    SUR                   < S3nUR                  (       a-  USR                  SR                  UR                  5      5      -  nU$ )NzReason: r   zExpected errors: {}
, )rw   rR   r   join)r2   r}   rets      r   _printUnexpectedSuccess Reporter._printUnexpectedSuccess  sC    r*;;*11$))DKK2HIIC
r   c                   U R                  S5        U R                  SU R                  S 5        U R                  SU R                  U R                  5        U R                  SU R
                  U R                  5        U R                  SU R                  U R                  5        U R                  SU R                  U R                  5        g)	z=
Print all of the non-success results to the stream in full.
r   	[SKIPPED]c                    SU -  $ )N%s
r#   )xs    r   <lambda>'Reporter._printErrors.<locals>.<lambda>  s    fqjr   [TODO][FAIL][ERROR][SUCCESS!?!]N)
r   r5  rB   rC   r8  rS   r   rR   rD   r>  rT   s    r   _printErrorsReporter._printErrors  s     	D;

4HI8T%:%:D<V<VW8T]]D4P4PQ9dkk43O3OPD44d6R6R	
r   c                2   / nS H5  n[        [        X5      5      nU(       d  M   UR                  SX#4-  5        M7     U R                  (       a  UR                  SU R                  4-  5        U=(       a    SSR	                  U5      -   S-   =(       d    SnU$ )z3
Return a formatted count of tests status results.
)rB   rC   rS   rR   rD   z%s=%dzsuccesses=%dz (r;  )r0  )rQ   r6   rn   rF   r<  )r2   	summariesstatnumsummarys        r   _getSummaryReporter._getSummary  s     	
D gd)*Cs  D;!67
 >>^t~~.??@B		)(<!<s!BIrr   c                |    U R                  5       nU R                  5       (       a  SnOSnU R                  SX!5        g)z:
Print a line summarising the test results to the stream.
PASSEDFAILEDz%s%s
N)rS  r   r   )r2   rR  statuss      r   _printSummaryReporter._printSummary  s9     ""$FFHf.r   c                   U R                   b%  U R                   R                  U R                  5        U R                  5         U R	                  U R
                  5        U R                  b=  U R	                  SU R                  [        R                  " 5       U R                  -
  5        U R                  S5        U R                  5         g)ar  
Summarize the result of the test run.

The summary includes a report of all of the errors, todos, skips and
so forth that occurred during the run. It also includes the number of
tests that were run and how long it took to run them (not including
load time).

Expects that C{_printErrors}, C{_writeln}, C{_write}, C{_printSummary}
and C{_separator} are all implemented.
NzRan %d tests in %.3fsr   )r   removeObserverr   rK  r   
_separatorr   rP   rX   r   rY  rT   s    r   r   Reporter.done  s     ??&OO**4+@+@Adoo&??&MM'		doo8U 	Dr   )r   r   r   r   r   r   )TT)r%   r&   r'   r(   r)   r]  r1  sysstdoutr3   r   rf   rp   rt   r   r   r   r   r  r   r-  r5  r8  r>  rK  rS  rY  r   r*   r   r   s   @r   r   r     s    $ J ZZ)et9<,
#<=+		D	
`D$4)"


(	/ r   r   c                  $    \ rS rSrSrS rS rSrg)MinimalReporteri  z
A minimalist reporter that prints only a summary of the test result, in
the form of (timeTaken, #tests, #tests, #errors, #failures, #skips).
c                    g)zJ
Don't print a detailed summary of errors. We only care about the
counts.
Nr#   rT   s    r   rK  MinimalReporter._printErrors  r   r   c                T   U R                   nU R                  b  U R                  5       U R                  -
  nOSnUUU[        U R                  5      [        U R
                  5      [        U R                  5      4nU R                  SR                  [        [        U5      5      5        g)z
Print out a one-line summary of the form:
'%(runtime) %(number_of_tests) %(number_of_tests) %(num_errors)
%(num_failures) %(num_skips)'
Nr    )rP   r   rY   rQ   rR   rS   rB   r   r<  mapr   )r2   numTeststimingts       r   rY  MinimalReporter._printSummary  s     ==??&]]_t6FF

O
 	chhs3{+,r   r#   N)r%   r&   r'   r(   r)   rK  rY  r*   r#   r   r   rb  rb    s    
-r   rb  c                  h   ^  \ rS rSrSrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jr	U 4S jr
S	rU =r$ )
TextReporteri  zv
Simple reporter that prints a single character for each test as it runs,
along with the standard Trial summary text.
c                F   > [         TU ]  U5        U R                  S5        g )Nr   rJ   r   r   rg   s     r   r   TextReporter.addSuccess   s    4 Cr   c                B   > [         TU ]  " U6   U R                  S5        g )NErJ   rt   r   r2   r   rL   s     r   rt   TextReporter.addError$  s    $Cr   c                B   > [         TU ]  " U6   U R                  S5        g )NFrJ   rp   r   rt  s     r   rp   TextReporter.addFailure(  s    D!Cr   c                B   > [         TU ]  " U6   U R                  S5        g )NSrJ   rx   r   rt  s     r   rx   TextReporter.addSkip,  s    Cr   c                B   > [         TU ]  " U6   U R                  S5        g )NTrJ   r   r   rt  s     r   r   TextReporter.addExpectedFailure0  s    "D)Cr   c                B   > [         TU ]  " U6   U R                  S5        g )N!rJ   r~   r   rt  s     r   r~   !TextReporter.addUnexpectedSuccess4  s    $d+Cr   r#   )r%   r&   r'   r(   r)   r   rt   rp   rx   r   r~   r*   r   r   s   @r   rm  rm    s+    
 r   rm  c                     ^  \ rS rSrSrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jr	U 4S jr
U 4S	 jrU 4S
 jrSrU =r$ )VerboseTextReporteri9  z
A verbose reporter that prints the name of each test as it is running.

Each line is printed with the name of the test, followed by the result of
that test.
c                d   > U R                  SUR                  5       5        [        TU ]  U5        g )Nz%s ... )r   r2  rJ   rf   )r2   tmrL   s     r   rf   VerboseTextReporter.startTestC  s$    Iruuw'"r   c                F   > [         TU ]  U5        U R                  S5        g Nz[OK]ro  rg   s     r   r   VerboseTextReporter.addSuccessG  s    4 Fr   c                B   > [         TU ]  " U6   U R                  S5        g NrI  rs  rt  s     r   rt   VerboseTextReporter.addErrorK  s    $Ir   c                B   > [         TU ]  " U6   U R                  S5        g )Nz	[FAILURE]rx  rt  s     r   rp   VerboseTextReporter.addFailureO  s    D!K r   c                B   > [         TU ]  " U6   U R                  S5        g NrA  r|  rt  s     r   rx   VerboseTextReporter.addSkipS  s    K r   c                B   > [         TU ]  " U6   U R                  S5        g NrG  r  rt  s     r   r   &VerboseTextReporter.addExpectedFailureW  s    "D)Hr   c                B   > [         TU ]  " U6   U R                  S5        g NrJ  r  rt  s     r   r~   (VerboseTextReporter.addUnexpectedSuccess[  s    $d+N#r   c                F   > [         TU ]  U5        U R                  S5        g )Nr   )rJ   rk   r   rg   s     r   rk   VerboseTextReporter.stopTest_  s    Dr   r#   )r%   r&   r'   r(   r)   rf   r   rt   rp   rx   r   r~   rk   r*   r   r   s   @r   r  r  9  s5    !!$ r   r  c                  ,   ^  \ rS rSrSrU 4S jrSrU =r$ )TimingTextReporterid  zY
Prints out each test as it is running, followed by the time taken for each
test to run.
c                `   > [         TU ]  U5        U R                  SU R                  -  5        g)zU
Mark the test as stopped, and write the time it took to run the test
to the stream.
z(%.03f secs)
N)rJ   rk   r   rH   )r2   r   rL   s     r   rk   TimingTextReporter.stopTestj  s(    
 	 $t~~56r   r#   )r%   r&   r'   r(   r)   rk   r*   r   r   s   @r   r  r  d  s    
7 7r   r  c                  h    \ rS rSrSr\" SSSSSSS	S
S9rS r\\	R                  4S j5       rS rSrg)_AnsiColorizeris  z
A colorizer is an object that loosely wraps around a stream, allowing
callers to write text to the stream in a particular color.

Colorizer classes must implement C{supported()} and C{write(text, color)}.
          !   "   #   $   %   )blackredgreenyellowbluemagentacyanwhitec                    Xl         g r/   r   r2   r   s     r   r3   _AnsiColorizer.__init__      r   c                   UR                  5       (       d  g SSKn  UR                  S5      S:  $ ! UR                   a'    UR	                  5         UR                  S5      S:  s $ f = f! [
         a     gf = f! [         a     gf = f)z
A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
Fr   Ncolorsr]   )isattycursestigetnumra   	setuptermBaseExceptionImportError)clsr   r  s      r   	supported_AnsiColorizer.supported  s     }}	9!??84q88|| 9$$&!??84q889 !   		s8   A< 2 4A)&A, (A))A, ,
A98A9<
B	B	c                f    U R                   U   nU R                  R                  SU SU S35        g)z
Write the given text to the stream in the given color.

@param text: Text to be written to the stream.

@param color: A string label for a color. e.g. 'red', 'white'.
z[z;1mz[0mN)_colorsr   r;   r2   textcolors      r   r;   _AnsiColorizer.write  s3     U#E%D69:r   r  N)r%   r&   r'   r(   r)   dictr  r3   classmethodr_  r`  r  r;   r*   r#   r   r   r  r  s  sJ     b2BSUG !jj  ,	;r   r  c                  N    \ rS rSrSrS r\\R                  4S j5       r	S r
Srg)_Win32Colorizeri  
See _AnsiColorizer docstring.
c           	         SSK JnJnJnJnJnJn  UUUU4u  ppXl        U" U5      U l        X-  U
-  X-  X-  X-  X-  U-  X-  U-  X-  U-  X-  U
-  U-  S.U l	        g )Nr   )FOREGROUND_BLUEFOREGROUND_GREENFOREGROUND_INTENSITYFOREGROUND_REDSTD_OUTPUT_HANDLEGetStdHandle)normalr  r  r  r  r  r  r  )
win32consoler  r  r  r  r  r  r   screenBufferr  )r2   r   r  r  r  r  r  r  r  r  r  bolds               r   r3   _Win32Colorizer.__init__  s    	
 	
  	"
D ():;kD(:\KkD(zD(L4'[4'$.	
r   c                    SS K nUR                  UR                  5      nSS Kn UR                  UR                  UR                  -  UR                  -  5        g! [         a     gf = f! UR                   a     gf = f)Nr   FT)
r  r  r  r  
pywintypesSetConsoleTextAttributer  r  r  ra   )r  r   r  r  r  s        r   r  _Win32Colorizer.supported  s    	'44\5S5STL 			00++//0../   		  		s"   A 5A, 
A)(A),A?>A?c                    U R                   U   nU R                  R                  U5        U R                  R	                  U5        U R                  R                  U R                   S   5        g )Nr  )r  r  r  r   r;   r  s      r   r;   _Win32Colorizer.write  sS    U#11%8$11$,,x2HIr   )r  r  r   Nr%   r&   r'   r(   r)   r3   r  r_  r`  r  r;   r*   r#   r   r   r  r    s-    
: !jj  (Jr   r  c                  N    \ rS rSrSrS r\\R                  4S j5       r	S r
Srg)_NullColorizeri  r  c                    Xl         g r/   r  r  s     r   r3   _NullColorizer.__init__  r  r   c                    gr   r#   )r  r   s     r   r  _NullColorizer.supported  s    r   c                :    U R                   R                  U5        g r/   )r   r;   r  s      r   r;   _NullColorizer.write  s    $r   r  Nr  r#   r   r   r  r    s,     !jj   r   r  c                      \ rS rSrSrSr\R                  SSS4S jrS r	\
S 5       rS	 rS
 rS rS rS rS rS rS rSS jrSS jrSrg)SubunitReporteri  z
Reports test output via Subunit.

@ivar _subunit: The subunit protocol client that we are wrapping.

@ivar _successful: An internal variable, used to track whether we have
    received only successful results.

@since: 10.0
Nr   Fc                V    [         c  [        S5      e[        U5      U l        SU l        g)a  
Construct a L{SubunitReporter}.

@param stream: A file-like object representing the stream to print
    output to. Defaults to stdout.
@param tbformat: The format for tracebacks. Ignored, since subunit
    always uses Python's standard format.
@param realtime: Whether or not to print exceptions in the middle
    of the test results. Ignored, since subunit always does this.
@param publisher: The log publisher which will be preserved for
    reporting events. Ignored, as it's not relevant to subunit.
NzSubunit not availableT)r   	Exception_subunit_successful)r2   r   r   r   r   s        r   r3   SubunitReporter.__init__  s*     %344*62r   c                    g)z
Record that the entire test suite run is finished.

We do nothing, since a summary clause is irrelevant to the subunit
protocol.
Nr#   rT   s    r   r   SubunitReporter.done  s     	r   c                .    U R                   R                  $ )z;
Whether or not the test runner should stop running tests.
)r  r   rT   s    r   r   SubunitReporter.shouldStop  s    
 }}'''r   c                6    U R                   R                  5       $ )z8
Signal that the test runner should stop running tests.
)r  stoprT   s    r   r  SubunitReporter.stop&  s     }}!!##r   c                    U R                   $ )z
Has the test run been successful so far?

@return: C{True} if we have received no reports of errors or failures,
    C{False} otherwise.
)r  rT   s    r   r   SubunitReporter.wasSuccessful,  s     r   c                8    U R                   R                  U5      $ )z"
Record that C{test} has started.
)r  rf   r   s     r   rf   SubunitReporter.startTest8  s     }}&&t,,r   c                8    U R                   R                  U5      $ )z$
Record that C{test} has completed.
)r  rk   r   s     r   rk   SubunitReporter.stopTest>  s     }}%%d++r   c                8    U R                   R                  U5      $ )z%
Record that C{test} was successful.
)r  r   r   s     r   r   SubunitReporter.addSuccessD  s     }}''--r   c                    [        U R                  SS5      nUc  U R                  U5        gU R                  R                  X5        g)aM  
Record that C{test} was skipped for C{reason}.

Some versions of subunit don't have support for addSkip. In those
cases, the skip is reported as a success.

@param test: A unittest-compatible C{TestCase}.
@param reason: The reason for it being skipped. The C{str()} of this
    object will be included in the subunit output stream.
rx   N)r6   r  r   rx   )r2   rh   rw   rx   s       r   rx   SubunitReporter.addSkipJ  s9     $--D9?OOD!MM!!$/r   c                p    SU l         U R                  R                  U[        R                  " U5      5      $ )z
Record that C{test} failed with an unexpected error C{err}.

Also marks the run as being unsuccessful, causing
L{SubunitReporter.wasSuccessful} to return C{False}.
F)r  r  rt   r   excInfoOrFailureToExcInfor2   rh   errs      r   rt   SubunitReporter.addError[  s.     !}}%%dD,J,J3,OPPr   c                p    SU l         U R                  R                  U[        R                  " U5      5      $ )z
Record that C{test} failed an assertion with the error C{err}.

Also marks the run as being unsuccessful, causing
L{SubunitReporter.wasSuccessful} to return C{False}.
F)r  r  rp   r   r  r  s      r   rp   SubunitReporter.addFailuree  s.     !}}''d.L.LS.QRRr   c                    [         R                  " U5      n[        U R                  SS5      nUc  U R	                  U5        gU" X5        g)z
Record an expected failure from a test.

Some versions of subunit do not implement this. For those versions, we
record a success.
r   N)r   r  r6   r  r   )r2   rh   r   r}   r   s        r   r   "SubunitReporter.addExpectedFailureo  sB     009$T]]4H$O%OOD!t-r   c                &    U R                  U5        g)z
Record an unexpected success.

Since subunit has no way of expressing this concept, we record a
success on the subunit stream.
N)r   r|   s      r   r~   $SubunitReporter.addUnexpectedSuccess}  s     	r   )r  r  r/   )r%   r&   r'   r(   r)   rP   r_  r`  r3   r   propertyr   r  r   rf   rk   r   rx   rt   rp   r   r~   r*   r#   r   r   r  r    so    	 H ZZ)et ( ( ($
 -,.0"QS.r   r  c                    ^  \ rS rSrSrSrSrSrSrSr	Sr
SrSrSr\R                  4U 4S	 jjrS
 rU 4S jrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jrU 4S jrS rS rU 4S jrU 4S jrU 4S jrU 4S jrS rSr U =r!$ )TreeReporteri  z
Print out the tests in the form a tree.

Tests are indented according to which class and module they belong.
Results are printed in ANSI color.
r0  z  O   r  r  r  c                   > [         TU ]  " U/UQ70 UD6  / U l        [        [        [
        4 H(  nUR                  U5      (       d  M  U" U5      U l          g    g r/   )rJ   r3   	_lastTestr  r  r  r  
_colorizer)r2   r   r   r   	colorizerrL   s        r   r3   TreeReporter.__init__  sS    1$1&1)>>JI""6**"+F"3 Kr   c                F    UR                  5       R                  S5      S   $ )z
Return the name of the method which 'test' represents.  This is
what gets displayed in the leaves of the tree.

e.g. getDescription(TestCase('test_foo')) ==> test_foo
r   r   )r2  r   r   s     r   getDescriptionTreeReporter.getDescription  s     wwys#B''r   c                \   > [         TU ]  U5        U R                  SU R                  5        g r  )rJ   r   endLineSUCCESSrg   s     r   r   TreeReporter.addSuccess  s"    4 VT\\*r   c                X   > [         TU ]  " U6   U R                  SU R                  5        g r  )rJ   rt   r  ERRORrt  s     r   rt   TreeReporter.addError  s"    $Y

+r   c                X   > [         TU ]  " U6   U R                  SU R                  5        g )NrH  )rJ   rp   r  FAILURErt  s     r   rp   TreeReporter.addFailure  s"    D!Xt||,r   c                X   > [         TU ]  " U6   U R                  SU R                  5        g r  )rJ   rx   r  SKIPrt  s     r   rx   TreeReporter.addSkip  s!    [$)),r   c                X   > [         TU ]  " U6   U R                  SU R                  5        g r  )rJ   r   r  TODOrt  s     r   r   TreeReporter.addExpectedFailure  s"    "D)Xtyy)r   c                X   > [         TU ]  " U6   U R                  SU R                  5        g r  )rJ   r~   r  TODONErt  s     r   r~   !TreeReporter.addUnexpectedSuccess  s"    $d+^T[[1r   c                Z   > U(       a  X-  nXl         [        TU ]	  U R                   5        g r/   )currentLinerJ   r   )r2   r   r   rL   s      r   r   TreeReporter._write  s%    ]F!t''(r   c                    UR                  S5      SS n[        U5      S:X  a  U$ SR                  USS 5      US   4 Vs/ s H  n[        U5      S:  d  M  UPM     nnU$ s  snf )zm
Return a list of all non-leaf segments to display in the tree.

Normally this is the module and class name.
r   Nr   r   )r   rQ   r<  )r2   testIDsegmentssegs       r   _getPreludeSegments TreeReporter._getPreludeSegments  sv     <<$Sb)x=AOHHXcr]3Xb\B
BCc#hQRlCB 	 
 
s   A"A"c                6   U R                  U5      nSnU Hz  nU[        U R                  5      :  a6  X@R                  U   :w  a#  U R                  U R                  U-   U S35        O#U R                  U R                  U-   U S35        US-  nM|     X l        g)z
Write the name of the test to the stream, indenting it appropriately.

If the test is the first test in a new 'branch' of the tree, also
write all of the parents in that branch.
r   r   r   N)r3  rQ   r  r   indent)r2   r0  r1  indentLevelr2  s        r   _testPreludeTreeReporter._testPrelude  s     ++F3CS00..55KK4;;#<"=cU" EFt{{[89#bAB1K  "r   c                   > U R                   R                  SU R                  5        U R                  SU R                  5        [        TU ]  U5        g )Nz    cleanup errorsrI  )r  r;   r  r  rJ   r   r   s     r   r   TreeReporter.cleanupErrors  s;    2DJJ?Y

+d#r   c                   > U R                   R                  SU-  U R                  5        U(       a  U R                  SU R                  5        [        TU ]  XX45        g )Nz  %srI  )r  r;   r  r  rJ   r   )r2   r   ra   r   r   rL   s        r   r   TreeReporter.upDownError  sC    fvotzz:LLDJJ/F4=r   c                   > U R                  UR                  5       5        U R                  U R                  [	        U R
                  5      -  < U R                  U5      < S35        [        TU ]!  U5        g)zV
Called when C{test} starts. Writes the tests name to the stream using
a tree format.
z ... N)	r8  r2  r   r6  rQ   r  r  rJ   rf   rg   s     r   rf   TreeReporter.startTest  s\    
 	$'')${{c$..12D4G4G4MO	
 	$r   c                   > SU R                   [        U R                  5      -
  [        U5      -
  -  n[        TU ]  U5        U R
                  R                  X5        [        TU ]  S5        g)z
Print 'message' in the given color.

@param message: A string message, usually '[OK]' or something similar.
@param color: A string color, 'red', 'green' and so forth.
rf  r   N)columnsrQ   r-  rJ   r   r  r;   )r2   messager  spacesrL   s       r   r  TreeReporter.endLine  sV     s4+;+;'<<s7|KLvg-tr   c                    U R                  5       nU R                  5       (       a  SnU R                  nOSnU R                  nU R                  R                  X#5        U R                  SU5        g)zW
Print a line summarising the test results to the stream, and color the
status result.
rV  rW  rC  N)rS  r   r  r!  r  r;   r   )r2   rR  rX  r  s       r   rY  TreeReporter._printSummary  s]    
 ""$FLLEFLLEf,FG$r   )r  r  r-  )"r%   r&   r'   r(   r)   r-  r6  rA  r!  r  r'  r$  r*  r  r_  r`  r3   r  r   rt   rp   rx   r   r~   r   r3  r8  r   r   rf   r  rY  r*   r   r   s   @r   r  r    s     KFGGEDDFG!jj (+,--*2)"$$
>
 
% %r   r  )r   r   r   z'Todo')Br)   
__future__r   r  r_  rX   unittestpyunitr   collectionsr   typesr   typingr   r   r   r	   r
   r   zope.interfacer   typing_extensionsr   twisted.pythonr   r   twisted.python.componentsr   twisted.python.failurer   twisted.python.utilr   twisted.trialr   r   r   r   subunitr   r  r  r   r   XUnitFailureTrialFailurer   Warningr!   r,   	IReporterr@   r   r   r   r   r   rb  rm  r  r  r  r  r  r  r  r#   r   r   <module>rY     s>   # 	 
    #  D D & ' ' 7 * . &* 4.}LM MWe$4556\7*+"G = =  Vi"" i iX Vf&&(;<  V9%8 9 9$ VB& B BOG* OGd Vsz s sl-h -D8 >(( (V7, 7/; /;d;J ;J|     VQ Q QhR%8 R%I#  s   6G2 2G>=G>