
    Vh                     L   d Z ddlmZ ddlmZmZmZ ddlmZ ddl	mZm
Z
  G d de      Z G d d	e      Z G d
 d      Z G d deej                        Z G d deej"                        Z G d d      Z G d deej                        Z G d deej"                        Z G d d      Z G d deej                        Z G d deej"                        Z G d dej                        Z G d dej"                        Z G d  d!ej                        Z ed"d#       G d$ d%ej                               Z G d& d'ej"                        Z G d( d)ej"                        Z G d* d+ej"                        Z G d, d-ej"                        Z d. Z! G d/ d0ej                        Z"y1)2aJ  
Definitions of test cases with various interesting error-related behaviors, to
be used by test modules to exercise different features of trial's test runner.

See the L{twisted.trial.test.test_tests} module docstring for details about how
this code is arranged.

Some of these tests are also used by L{twisted.trial._dist.test}.
    )skipIf)deferprotocolreactor)
deferLater)unittestutilc                       e Zd Zy)FoolishErrorN__name__
__module____qualname__     L/home/dcms/DCMS/lib/python3.12/site-packages/twisted/trial/test/erroneous.pyr   r          r   r   c                   &    e Zd ZdZdeddfdZd Zy)
LargeErrorzj
    An exception which has a string representation of at least a specified
    number of characters.
    minSizereturnNc                 <    t         j                  |        || _        y N)	Exception__init__r   )selfr   s     r   r   zLargeError.__init__!   s    4 r   c                 ,    d| j                   z  }d| dS )NxzLargeError<I fail: >)r   )r   larges     r   __str__zLargeError.__str__%   s    dll"$UG1--r   )r   r   r   __doc__intr   r!   r   r   r   r   r      s    
  .r   r   c                       e Zd Zd Zd Zy)FailureInSetUpMixinc                     t        d      )NzI am a broken setUp methodr   r   s    r   setUpzFailureInSetUpMixin.setUp+   s    788r   c                      y r   r   r(   s    r   	test_noopzFailureInSetUpMixin.test_noop.       r   N)r   r   r   r)   r+   r   r   r   r%   r%   *   s    9r   r%   c                       e Zd Zy)SynchronousTestFailureInSetUpNr   r   r   r   r.   r.   2   r   r   r.   c                       e Zd Zy)AsynchronousTestFailureInSetUpNr   r   r   r   r0   r0   6   r   r   r0   c                       e Zd Zd Zd Zy)FailureInTearDownMixinc                     t        d      )NzI am a broken tearDown methodr'   r(   s    r   tearDownzFailureInTearDownMixin.tearDown;   s    :;;r   c                      y r   r   r(   s    r   r+   z FailureInTearDownMixin.test_noop>   r,   r   N)r   r   r   r4   r+   r   r   r   r2   r2   :   s    <r   r2   c                       e Zd Zy) SynchronousTestFailureInTearDownNr   r   r   r   r7   r7   B        	r   r7   c                       e Zd Zy)!AsynchronousTestFailureInTearDownNr   r   r   r   r:   r:   H   r   r   r:   c                        e Zd ZdZdZd Zd Zy)FailureButTearDownRunsMixinz7
    A test fails, but its L{tearDown} still runs.
    Fc                     d| _         y NT)tornDownr(   s    r   r4   z$FailureButTearDownRunsMixin.tearDownS   s	    r   c                     t        d      )z$
        A test that fails.
        zI am a broken testr'   r(   s    r   
test_failsz&FailureButTearDownRunsMixin.test_failsV   s     /00r   N)r   r   r   r"   r?   r4   rA   r   r   r   r<   r<   L   s     H1r   r<   c                       e Zd Zy)%SynchronousTestFailureButTearDownRunsNr   r   r   r   rC   rC   ]   r8   r   rC   c                       e Zd Zy)&AsynchronousTestFailureButTearDownRunsNr   r   r   r   rE   rE   c   r8   r   rE   c                       e Zd Zd Zd Zd Zy)TestRegularFailc                 &    | j                  d       y )NI failfailr(   s    r   	test_failzTestRegularFail.test_failj   s    		(r   c                 $    | j                          y r   )
subroutiner(   s    r   test_subfailzTestRegularFail.test_subfailm   s    r   c                 &    | j                  d       y )NzI fail insiderJ   r(   s    r   rN   zTestRegularFail.subroutinep   s    		/"r   N)r   r   r   rL   rO   rN   r   r   r   rG   rG   i   s    #r   rG   c                   x    e Zd ZdZdZdej                  d   fdZdej                  d   fdZd
dZ	d
dZ
d
d	Zy)TestAsynchronousFailz?
    Test failures for L{unittest.TestCase} based classes.
    rI   r   Nc                 :    t        t        d| j                  d      S )zW
        A test which fails in the callback of the returned L{defer.Deferred}.
        r   zI fail laterr   r   rK   r(   s    r   rL   zTestAsynchronousFail.test_fail{   s     '1dii@@r   c                 F    t        t        d| j                  dddz  z         S )zw
        A test which fails in the callback of the returned L{defer.Deferred}
        with a very long string.
        r   zI fail later: r      rT   r(   s    r   test_failGreaterThan64kz,TestAsynchronousFail.test_failGreaterThan64k   s#    
 '1dii1AC%K1OPPr   c                 ,    t        | j                        )zA
        A test which raises an exception synchronously.
        )r   textr(   s    r   test_exceptionz#TestAsynchronousFail.test_exception   s     		""r   c                     t        d      )zk
        A test which raises an exception with a long string representation
        synchronously.
        rV   )r   r(   s    r   test_exceptionGreaterThan64kz1TestAsynchronousFail.test_exceptionGreaterThan64k   s    
 r   c                     t        ddz        )z
        A test which synchronously raises an exception with a long string
        representation including non-ascii content.
        u   ☃i   )r   r(   s    r   #test_exceptionGreaterThan64kEncodedz8TestAsynchronousFail.test_exceptionGreaterThan64kEncoded   s     -..r   )r   N)r   r   r   r"   rY   r   DeferredrL   rW   rZ   r\   r^   r   r   r   rR   rR   t   sK     DA5>>$/ AQ)= Q# 	/r   rR   c                       e Zd ZdZdZd Zy)	ErrorTestz
    A test case which has a L{test_foo} which will raise an error.

    @ivar ran: boolean indicating whether L{test_foo} has been run.
    Fc                     d| _         ddz   y)zJ
        Set C{self.ran} to True and raise a C{ZeroDivisionError}
        T   r   N)ranr(   s    r   test_foozErrorTest.test_foo   s     	Ar   N)r   r   r   r"   rd   re   r   r   r   ra   ra      s     Cr   ra   Tzskipping this testc                       e Zd Zy)TestSkipTestCaseNr   r   r   r   rg   rg      s    r   rg   c                   P    e Zd ZdZd Zd Z ej                  de      ge_        y)DelayedCallzsomething blew upc                 ,    t        | j                        r   )RuntimeErrorhiddenExceptionMsgr(   s    r   gozDelayedCall.go   s    42233r   c                     t        j                  d| j                         t        j                  d       | j	                  d       y)a  
        What happens if an error is raised in a DelayedCall and an error is
        also raised in the test?

        L{test_reporter.ErrorReportingTests.testHiddenException} checks that
        both errors get reported.

        Note that this behaviour is deprecated. A B{real} test would return a
        Deferred that got triggered by the callLater. This would guarantee the
        delayed call error gets reported.
        r   g{Gz?z/Deliberate failure to mask the hidden exceptionN)r   	callLaterrm   iteraterK   r(   s    r   testHiddenExceptionzDelayedCall.testHiddenException   s1     	!TWW%		CDr   z!reactor\.iterate cannot be used.*)messagecategoryN)	r   r   r   rl   rm   rq   r	   suppressDeprecationWarningr   r   r   ri   ri      s4    ,4E" 	8CU	
$ r   ri   c                       e Zd Zd Zy)ReactorCleanupTestsc                 6    d }t        j                  d|       y )Nc                      t        d       y )Nzfoo!)printr   r   r   _z8ReactorCleanupTests.test_leftoverPendingCalls.<locals>._   s	    &Mr   g     @)r   ro   )r   r{   s     r   test_leftoverPendingCallsz-ReactorCleanupTests.test_leftoverPendingCalls   s    	 	'1%r   N)r   r   r   r|   r   r   r   rw   rw      s    &r   rw   c                       e Zd Zd Zy)SocketOpenTestc                     t        j                         }t         j                  |_         t        j                  d|       y )Nr   )r   FactoryProtocolr   	listenTCP)r   fs     r   test_socketsLeftOpenz#SocketOpenTest.test_socketsLeftOpen   s-    &&
!Qr   N)r   r   r   r   r   r   r   r~   r~      s     r   r~   c                       e Zd Zd Zd Zd Zy)TimingOutDeferredc                      y r   r   r(   s    r   
test_alphazTimingOutDeferred.test_alpha   r,   r   c                 <    d| _         t        j                         }|S r>   )methodCalledr   r_   )r   ds     r   test_deferredThatNeverFiresz-TimingOutDeferred.test_deferredThatNeverFires   s     NNr   c                      y r   r   r(   s    r   
test_omegazTimingOutDeferred.test_omega   r,   r   N)r   r   r   r   r   r   r   r   r   r   r      s    
r   r   c                      y)zci will raise an unexpected exception...
    ... *CAUSE THAT'S THE KINDA GUY I AM*

    >>> 1/0
    Nr   r(   s    r   unexpectedExceptionr      s    r   c                   &    e Zd ZU dZdZeed<   d Zy)EventuallyFailingTestCasez>
    A test suite that fails after it is run a few times.
    r   nc                 p    | xj                   dz  c_         | j                   dk\  r| j                  d       yy)zK
        Run successfully a few times and then fail forever after.
        rc      zeventually failingN)r   rK   r(   s    r   test_itz!EventuallyFailingTestCase.test_it   s.     	!66Q;II*+ r   N)r   r   r   r"   r   r#   __annotations__r   r   r   r   r   r      s     AsJ,r   r   N)#r"   r   r   twisted.internetr   r   r   twisted.internet.taskr   twisted.trialr	   r   r   r   r%   SynchronousTestCaser.   TestCaser0   r2   r7   r:   r<   rC   rE   rG   rR   ra   rg   ri   rw   r~   r   r   r   r   r   r   <module>r      s  
  5 5 , (	9 	. . 	$79U9U 		%8(:K:K 	 	H88		(>@Q@Q 	1 1"	!=!=		!2!2	#h22 #*/8,, */Z,, " "#	x33 	 $	(## :&(++ & X&&  
)) 
, < < ,r   