
    Yf                     <   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"d1S )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dS )FoolishErrorN__name__
__module____qualname__     N/var/www/html/env/lib/python3.11/site-packages/twisted/trial/test/erroneous.pyr   r              Dr   r   c                   (    e Zd ZdZdeddfdZd ZdS )
LargeErrorzj
    An exception which has a string representation of at least a specified
    number of characters.
    minSizereturnNc                 H    t                               |            || _        d S 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    dl"-U----r   )r   r   r   __doc__intr   r!   r   r   r   r   r      sO         
     . . . . .r   r   c                       e Zd Zd Zd ZdS )FailureInSetUpMixinc                      t          d          )NzI am a broken setUp methodr   r   s    r   setUpzFailureInSetUpMixin.setUp+   s    7888r   c                     d S r   r   r(   s    r   	test_noopzFailureInSetUpMixin.test_noop.       r   N)r   r   r   r)   r+   r   r   r   r%   r%   *   s2        9 9 9    r   r%   c                       e Zd ZdS )SynchronousTestFailureInSetUpNr   r   r   r   r.   r.   2   r   r   r.   c                       e Zd ZdS )AsynchronousTestFailureInSetUpNr   r   r   r   r0   r0   6   r   r   r0   c                       e Zd Zd Zd ZdS )FailureInTearDownMixinc                      t          d          )NzI am a broken tearDown methodr'   r(   s    r   tearDownzFailureInTearDownMixin.tearDown;   s    :;;;r   c                     d S r   r   r(   s    r   r+   z FailureInTearDownMixin.test_noop>   r,   r   N)r   r   r   r4   r+   r   r   r   r2   r2   :   s2        < < <    r   r2   c                       e Zd ZdS ) SynchronousTestFailureInTearDownNr   r   r   r   r7   r7   B            	Dr   r7   c                       e Zd ZdS )!AsynchronousTestFailureInTearDownNr   r   r   r   r:   r:   H   r   r   r:   c                   "    e Zd ZdZdZd Zd ZdS )FailureButTearDownRunsMixinz7
    A test fails, but its L{tearDown} still runs.
    Fc                     d| _         d S 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00r   N)r   r   r   r"   r?   r4   rA   r   r   r   r<   r<   L   sC          H  1 1 1 1 1r   r<   c                       e Zd ZdS )%SynchronousTestFailureButTearDownRunsNr   r   r   r   rC   rC   ]   r8   r   rC   c                       e Zd ZdS )&AsynchronousTestFailureButTearDownRunsNr   r   r   r   rE   rE   c   r8   r   rE   c                        e Zd Zd Zd Zd ZdS )TestRegularFailc                 0    |                      d           d S )NI failfailr(   s    r   	test_failzTestRegularFail.test_failj   s    		(r   c                 .    |                                   d S r   )
subroutiner(   s    r   test_subfailzTestRegularFail.test_subfailm   s    r   c                 0    |                      d           d S )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   sA            # # # # #r   rG   c                   r    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dS )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     '1di@@@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$    
 '1di1AC%K1OP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   s          DA5>$/ A A A AQ)= Q Q Q Q# # # #       	/ 	/ 	/ 	/ 	/ 	/r   rR   c                       e Zd ZdZdZd ZdS )	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   dS )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      s4          C    r   ra   Tzskipping this testc                       e Zd ZdS )TestSkipTestCaseNr   r   r   r   rg   rg      s        Dr   rg   c                   N    e Zd ZdZd Zd Z ej        de          ge_        dS )DelayedCallzsomething blew upc                 *    t          | j                  r   )RuntimeErrorhiddenExceptionMsgr(   s    r   gozDelayedCall.go   s    42333r   c                     t          j        d| j                   t          j        d           |                     d           dS )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   sB     	!TW%%%		CDDDDDr   z!reactor\.iterate cannot be used.*)messagecategoryN)	r   r   r   rl   rm   rq   r	   suppressDeprecationWarningr   r   r   ri   ri      s`        ,4 4 4E E E" 	8CU	
 	
 	
$   r   ri   c                       e Zd Zd ZdS )ReactorCleanupTestsc                 6    d }t          j        d|           d S )Nc                  $    t          d           d S )Nzfoo!)printr   r   r   _z8ReactorCleanupTests.test_leftoverPendingCalls.<locals>._   s    &MMMMMr   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dS )SocketOpenTestc                 x    t          j                    }t           j        |_         t          j        d|           d S )Nr   )r   FactoryProtocolr   	listenTCP)r   fs     r   test_socketsLeftOpenz#SocketOpenTest.test_socketsLeftOpen   s3    &
!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dS )TimingOutDeferredc                     d S 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     Nr   c                     d S r   r   r(   s    r   
test_omegazTimingOutDeferred.test_omega   r,   r   N)r   r   r   r   r   r   r   r   r   r   r      sA            
    r   r   c                     dS )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dS )EventuallyFailingTestCasez>
    A test suite that fails after it is run a few times.
    r   nc                 j    | xj         dz  c_         | j         dk    r|                     d           dS dS )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>     	!6Q;;II*+++++ ;r   N)r   r   r   r"   r   r#   __annotations__r   r   r   r   r   r      s>           AsJJJ, , , , ,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 5 5 5 5 5 5 5 5 , , , , , , ( ( ( ( ( ( ( (	 	 	 	 	9 	 	 	. . . . . . . .       	 	 	 	 	$79U 	 	 		 	 	 	 	%8(:K 	 	 	       	 	 	 	 	H8	 	 		 	 	 	 	(>@Q 	 	 	1 1 1 1 1 1 1 1"	 	 	 	 	!=	 	 		 	 	 	 	!2	 	 	# # # # #h2 # # #*/ */ */ */ */8, */ */ */Z    ,   " "##	 	 	 	 	x3 	 	 $#	    (#   :& & & & &(+ & & &         X&      
 
 
 
 
) 
 
 
  , , , , , < , , , , ,r   