o
    >h                     @   s  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 deZG dd	 d	eZG d
d dZG dd deejZG dd deejZG dd dZG dd deejZG dd deejZG dd dZG dd deejZG dd deejZG dd dejZG dd dejZG d d! d!ejZed"d#G d$d% d%ejZG d&d' d'ejZG d(d) d)ejZG d*d+ d+ejZG d,d- d-ejZ d.d/ Z!G d0d1 d1ejZ"d2S )3aJ  
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__ r   r   |/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/trial/test/erroneous.pyr
          r
   c                   @   s*   e Zd ZdZdeddfddZdd ZdS )	
LargeErrorzj
    An exception which has a string representation of at least a specified
    number of characters.
    minSizereturnNc                 C   s   t |  || _d S N)	Exception__init__r   )selfr   r   r   r   r   !   s   

zLargeError.__init__c                 C   s   d| j  }d| dS )NxzLargeError<I fail: >)r   )r   larger   r   r   __str__%   s   
zLargeError.__str__)r   r   r   __doc__intr   r   r   r   r   r   r      s    r   c                   @      e Zd Zdd Zdd ZdS )FailureInSetUpMixinc                 C      t d)NzI am a broken setUp methodr
   r   r   r   r   setUp+      zFailureInSetUpMixin.setUpc                 C      d S r   r   r#   r   r   r   	test_noop.      zFailureInSetUpMixin.test_noopN)r   r   r   r$   r'   r   r   r   r   r    *       r    c                   @   r	   )SynchronousTestFailureInSetUpNr   r   r   r   r   r*   2   r   r*   c                   @   r	   )AsynchronousTestFailureInSetUpNr   r   r   r   r   r+   6   r   r+   c                   @   r   )FailureInTearDownMixinc                 C   r!   )NzI am a broken tearDown methodr"   r#   r   r   r   tearDown;   r%   zFailureInTearDownMixin.tearDownc                 C   r&   r   r   r#   r   r   r   r'   >   r(   z FailureInTearDownMixin.test_noopN)r   r   r   r-   r'   r   r   r   r   r,   :   r)   r,   c                   @   r	   ) SynchronousTestFailureInTearDownNr   r   r   r   r   r.   B       r.   c                   @   r	   )!AsynchronousTestFailureInTearDownNr   r   r   r   r   r0   H   r   r0   c                   @   s$   e Zd ZdZdZdd Zdd ZdS )FailureButTearDownRunsMixinz7
    A test fails, but its L{tearDown} still runs.
    Fc                 C   s
   d| _ d S NT)tornDownr#   r   r   r   r-   S      
z$FailureButTearDownRunsMixin.tearDownc                 C   r!   )z$
        A test that fails.
        zI am a broken testr"   r#   r   r   r   
test_failsV   s   z&FailureButTearDownRunsMixin.test_failsN)r   r   r   r   r3   r-   r5   r   r   r   r   r1   L   s
    r1   c                   @   r	   )%SynchronousTestFailureButTearDownRunsNr   r   r   r   r   r6   ]   r/   r6   c                   @   r	   )&AsynchronousTestFailureButTearDownRunsNr   r   r   r   r   r7   c   r/   r7   c                   @   $   e Zd Zdd Zdd Zdd ZdS )TestRegularFailc                 C      |  d d S )NI failfailr#   r   r   r   	test_failj      zTestRegularFail.test_failc                 C   s   |    d S r   )
subroutiner#   r   r   r   test_subfailm      zTestRegularFail.test_subfailc                 C   r:   )NzI fail insider<   r#   r   r   r   r@   p   r?   zTestRegularFail.subroutineN)r   r   r   r>   rA   r@   r   r   r   r   r9   i   s    r9   c                   @   sZ   e Zd ZdZdZdejd fddZdejd fddZdd	d
Z	dddZ
dddZdS )TestAsynchronousFailz?
    Test failures for L{unittest.TestCase} based classes.
    r;   r   Nc                 C   s   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   r=   r#   r   r   r   r>   {   s   zTestAsynchronousFail.test_failc                 C   s   t td| jddd  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      rD   r#   r   r   r   test_failGreaterThan64k   s   z,TestAsynchronousFail.test_failGreaterThan64kc                 C   
   t | j)zA
        A test which raises an exception synchronously.
        )r   textr#   r   r   r   test_exception   s   
z#TestAsynchronousFail.test_exceptionc                 C   r!   )zk
        A test which raises an exception with a long string representation
        synchronously.
        rE   )r   r#   r   r   r   test_exceptionGreaterThan64k   s   z1TestAsynchronousFail.test_exceptionGreaterThan64kc                 C   s   t dd )z
        A test which synchronously raises an exception with a long string
        representation including non-ascii content.
        u   ☃i   )r   r#   r   r   r   #test_exceptionGreaterThan64kEncoded   s   	z8TestAsynchronousFail.test_exceptionGreaterThan64kEncoded)r   N)r   r   r   r   rH   r   Deferredr>   rF   rI   rJ   rK   r   r   r   r   rC   t   s    

rC   c                   @   s   e Zd ZdZdZd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                 C   s   d| _ dd  dS )zJ
        Set C{self.ran} to True and raise a C{ZeroDivisionError}
        T   r   N)ranr#   r   r   r   test_foo   s   zErrorTest.test_fooN)r   r   r   r   rO   rP   r   r   r   r   rM      s    rM   Tzskipping this testc                   @   r	   )TestSkipTestCaseNr   r   r   r   r   rQ      s    rQ   c                   @   s2   e Zd ZdZdd Zdd Zejdedge_dS )	DelayedCallzsomething blew upc                 C   rG   r   )RuntimeErrorhiddenExceptionMsgr#   r   r   r   go   r4   zDelayedCall.goc                 C   s&   t d| j t 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   	callLaterrU   iterater=   r#   r   r   r   testHiddenException   s   
zDelayedCall.testHiddenExceptionz!reactor\.iterate cannot be used.*)messagecategoryN)	r   r   r   rT   rU   rX   r   suppressDeprecationWarningr   r   r   r   rR      s    
rR   c                   @      e Zd Zdd ZdS )ReactorCleanupTestsc                 C   s   dd }t d| d S )Nc                   S   s   t d d S )Nzfoo!)printr   r   r   r   _   rB   z8ReactorCleanupTests.test_leftoverPendingCalls.<locals>._g     @)r   rV   )r   r`   r   r   r   test_leftoverPendingCalls   s   z-ReactorCleanupTests.test_leftoverPendingCallsN)r   r   r   ra   r   r   r   r   r^          r^   c                   @   r]   )SocketOpenTestc                 C   s    t  }t j|_ td| d S )Nr   )r   FactoryProtocolr   	listenTCP)r   fr   r   r   test_socketsLeftOpen   s   z#SocketOpenTest.test_socketsLeftOpenN)r   r   r   rh   r   r   r   r   rc      rb   rc   c                   @   r8   )TimingOutDeferredc                 C   r&   r   r   r#   r   r   r   
test_alpha   r(   zTimingOutDeferred.test_alphac                 C   s   d| _ t }|S r2   )methodCalledr   rL   )r   dr   r   r   test_deferredThatNeverFires   s   z-TimingOutDeferred.test_deferredThatNeverFiresc                 C   r&   r   r   r#   r   r   r   
test_omega   r(   zTimingOutDeferred.test_omegaN)r   r   r   rj   rm   rn   r   r   r   r   ri      s    ri   c                 C   s   dS )zci will raise an unexpected exception...
    ... *CAUSE THAT'S THE KINDA GUY I AM*

    >>> 1/0
    Nr   r#   r   r   r   unexpectedException   s    ro   c                   @   s&   e Zd ZU dZdZeed< dd ZdS )EventuallyFailingTestCasez>
    A test suite that fails after it is run a few times.
    r   nc                 C   s*   |  j d7  _ | j dkr| d dS dS )zK
        Run successfully a few times and then fail forever after.
        rN      zeventually failingN)rq   r=   r#   r   r   r   test_it   s   
z!EventuallyFailingTestCase.test_itN)r   r   r   r   rq   r   __annotations__rs   r   r   r   r   rp      s   
 rp   N)#r   r   r   twisted.internetr   r   r   twisted.internet.taskr   twisted.trialr   r   r
   r   r    SynchronousTestCaser*   TestCaser+   r,   r.   r0   r1   r6   r7   r9   rC   rM   rQ   rR   r^   rc   ri   ro   rp   r   r   r   r   <module>   sB   


-